From 4ca004c836aff0ed42c25601b8f36592a48b614d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 5 Sep 2017 21:48:39 +0200 Subject: [PATCH] daca2-search.cgi: write summary if no arguments are used --- tools/daca2-search.cgi | 100 +++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/tools/daca2-search.cgi b/tools/daca2-search.cgi index b0eec9049..dde8452fb 100755 --- a/tools/daca2-search.cgi +++ b/tools/daca2-search.cgi @@ -7,50 +7,82 @@ import glob import os import cgi import cgitb +import re -def matchline(line, id): - return line.endswith('[' + id + ']') - -def doSearch(path,arguments): - id = arguments['id'].value - +def getfiles(path, arguments): files = [] if 'folder' in arguments: files.append(path + '/daca2-' + arguments['folder'].value + '.html') else: files.extend(sorted(glob.glob(path+'/daca2-?.html'))) files.extend(sorted(glob.glob(path+'/daca2-lib?.html'))) + return files - for g in files: - if os.path.isfile(g): - ftp = '' - found = False - f = open(g,'rt') - for line in f.readlines(): - while len(line)>1 and (line[-1]=='\r' or line[-1]=='\n'): - line = line[:-1] - if line.startswith('ftp://'): - ftp = line - if matchline(line, id): - found = True - sys.stdout.write(ftp + '\n') - elif line.find(': note:') < 0: - found = False - if found: - sys.stdout.write(line + '\n') - f.close() +def readlines(filename): + if not os.path.isfile(filename): + return [] + f = open(filename, 'rt') + lines = f.readlines() + f.close() + return lines + +def trimline(line): + while len(line)>1 and (line[-1]=='\r' or line[-1]=='\n'): + line = line[:-1] + return line + +def matchline(line, id): + return line.endswith('[' + id + ']') + +def doSearch(path,arguments): + id = arguments['id'].value + for g in getfiles(path, arguments): + ftp = '' + found = False + for line in readlines(g): + line = trimline(line) + if line.startswith('ftp://'): + ftp = line + if matchline(line, id): + found = True + sys.stdout.write(ftp + '\n') + elif line.find(': note:') < 0: + found = False + if found: + sys.stdout.write(line + '\n') + +def summary(path, arguments): + count = {} + for g in getfiles(path, arguments): + for line in readlines(g): + line = trimline(line) + res = re.match(r'.*: (error|warning|style|performance|portability):.*\[([a-zA-Z0-9]+)\]$', line) + if res is None: + continue + id = res.group(2) + if id in count: + count[id] = count[id] + 1 + else: + count[id] = 1 + print('') + for id in sorted(count.keys()): + print('') + print('
' + id +''+str(count[id])+'
') sys.stdout.write('Content-type: text/html\r\n\r\n') - -sys.stdout.write('
\n')
+sys.stdout.write('\n')
 
 cgitb.enable()
 arguments = cgi.FieldStorage()
-id = arguments['id'].value
-#id = 'oppositeInnerCondition'
-print(id)
-
-doSearch('../htdocs/devinfo/daca2-report', arguments)
-#doSearch(os.path.expanduser('~/temp'), id)
-
-sys.stdout.write('
\n') +if 'id' in arguments: + id = arguments['id'].value + #id = 'oppositeInnerCondition' + print(id) + sys.stdout.write('
\n')
+  doSearch('../htdocs/devinfo/daca2-report', arguments)
+  #doSearch(os.path.expanduser('~/temp'), id)
+  sys.stdout.write('
\n') +else: + summary('../htdocs/devinfo/daca2-report', arguments) + #summary(os.path.expanduser('~/temp'), arguments) +sys.stdout.write('\n')