Show function line lengths

merge-requests/30/head
Bob Mottram 2021-06-26 20:01:48 +01:00
parent 5d81337ac4
commit 139cffa0d5
2 changed files with 51 additions and 17 deletions

View File

@ -72,6 +72,27 @@ def removeShare(baseDir: str, nickname: str, domain: str,
'" does not exist in ' + sharesFilename) '" does not exist in ' + sharesFilename)
def _addShareDurationSec(duration: str, published: str) -> int:
"""Returns the duration for the shared item in seconds
"""
if ' ' not in duration:
return 0
durationList = duration.split(' ')
if not durationList[0].isdigit():
return 0
if 'hour' in durationList[1]:
return published + (int(durationList[0]) * 60 * 60)
if 'day' in durationList[1]:
return published + (int(durationList[0]) * 60 * 60 * 24)
if 'week' in durationList[1]:
return published + (int(durationList[0]) * 60 * 60 * 24 * 7)
if 'month' in durationList[1]:
return published + (int(durationList[0]) * 60 * 60 * 24 * 30)
if 'year' in durationList[1]:
return published + (int(durationList[0]) * 60 * 60 * 24 * 365)
return 0
def addShare(baseDir: str, def addShare(baseDir: str,
httpPrefix: str, nickname: str, domain: str, port: int, httpPrefix: str, nickname: str, domain: str, port: int,
displayName: str, summary: str, imageFilename: str, displayName: str, summary: str, imageFilename: str,
@ -86,24 +107,8 @@ def addShare(baseDir: str,
sharesJson = loadJson(sharesFilename) sharesJson = loadJson(sharesFilename)
duration = duration.lower() duration = duration.lower()
durationSec = 0
published = int(time.time()) published = int(time.time())
if ' ' in duration: durationSec = _addShareDurationSec(duration, published)
durationList = duration.split(' ')
if durationList[0].isdigit():
if 'hour' in durationList[1]:
durationSec = published + (int(durationList[0]) * 60 * 60)
if 'day' in durationList[1]:
durationSec = published + (int(durationList[0]) * 60 * 60 * 24)
if 'week' in durationList[1]:
durationSec = \
published + (int(durationList[0]) * 60 * 60 * 24 * 7)
if 'month' in durationList[1]:
durationSec = \
published + (int(durationList[0]) * 60 * 60 * 24 * 30)
if 'year' in durationList[1]:
durationSec = \
published + (int(durationList[0]) * 60 * 60 * 24 * 365)
itemID = getValidSharedItemID(displayName) itemID = getValidSharedItemID(displayName)

View File

@ -2981,6 +2981,7 @@ def _testFunctions():
functionProperties = {} functionProperties = {}
modules = {} modules = {}
modGroups = {} modGroups = {}
methodLOC = []
for subdir, dirs, files in os.walk('.'): for subdir, dirs, files in os.walk('.'):
for sourceFile in files: for sourceFile in files:
@ -2997,6 +2998,9 @@ def _testFunctions():
with open(sourceFile, "r") as f: with open(sourceFile, "r") as f:
lines = f.readlines() lines = f.readlines()
modules[modName]['lines'] = lines modules[modName]['lines'] = lines
lineCount = 0
prevLine = 'start'
methodName = ''
for line in lines: for line in lines:
if '__module_group__' in line: if '__module_group__' in line:
if '=' in line: if '=' in line:
@ -3010,7 +3014,27 @@ def _testFunctions():
if modName not in modGroups[groupName]: if modName not in modGroups[groupName]:
modGroups[groupName].append(modName) modGroups[groupName].append(modName)
if not line.strip().startswith('def '): if not line.strip().startswith('def '):
if lineCount > 0:
lineCount += 1
if len(prevLine.strip()) == 0 and \
len(line.strip()) == 0 and \
lineCount > 2:
lineCount -= 2
if lineCount > 80:
locStr = str(lineCount) + ';' + methodName
if lineCount < 1000:
locStr = '0' + locStr
if lineCount < 100:
locStr = '0' + locStr
if lineCount < 10:
locStr = '0' + locStr
if locStr not in methodLOC:
methodLOC.append(locStr)
lineCount = 0
prevLine = line
continue continue
prevLine = line
lineCount = 1
methodName = line.split('def ', 1)[1].split('(')[0] methodName = line.split('def ', 1)[1].split('(')[0]
methodArgs = \ methodArgs = \
sourceStr.split('def ' + methodName + '(')[1] sourceStr.split('def ' + methodName + '(')[1]
@ -3029,6 +3053,11 @@ def _testFunctions():
} }
break break
print('LOC counts:')
methodLOC.sort()
for locStr in methodLOC:
print(locStr.split(';')[0] + ' ' + locStr.split(';')[1])
excludeFuncArgs = [ excludeFuncArgs = [
'pyjsonld' 'pyjsonld'
] ]