daca2-search.cgi: write summary if no arguments are used

This commit is contained in:
Daniel Marjamäki 2017-09-05 21:48:39 +02:00
parent 3127fcf429
commit 4ca004c836
1 changed files with 66 additions and 34 deletions

View File

@ -7,28 +7,40 @@ import glob
import os import os
import cgi import cgi
import cgitb import cgitb
import re
def matchline(line, id): def getfiles(path, arguments):
return line.endswith('[' + id + ']')
def doSearch(path,arguments):
id = arguments['id'].value
files = [] files = []
if 'folder' in arguments: if 'folder' in arguments:
files.append(path + '/daca2-' + arguments['folder'].value + '.html') files.append(path + '/daca2-' + arguments['folder'].value + '.html')
else: else:
files.extend(sorted(glob.glob(path+'/daca2-?.html'))) files.extend(sorted(glob.glob(path+'/daca2-?.html')))
files.extend(sorted(glob.glob(path+'/daca2-lib?.html'))) files.extend(sorted(glob.glob(path+'/daca2-lib?.html')))
return files
for g in files: def readlines(filename):
if os.path.isfile(g): if not os.path.isfile(filename):
ftp = '' return []
found = False f = open(filename, 'rt')
f = open(g,'rt') lines = f.readlines()
for line in f.readlines(): f.close()
return lines
def trimline(line):
while len(line)>1 and (line[-1]=='\r' or line[-1]=='\n'): while len(line)>1 and (line[-1]=='\r' or line[-1]=='\n'):
line = line[:-1] 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://'): if line.startswith('ftp://'):
ftp = line ftp = line
if matchline(line, id): if matchline(line, id):
@ -38,19 +50,39 @@ def doSearch(path,arguments):
found = False found = False
if found: if found:
sys.stdout.write(line + '\n') sys.stdout.write(line + '\n')
f.close()
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('<table>')
for id in sorted(count.keys()):
print('<tr><td>' + id +'</td><td><a href="/cgi-bin/daca2-search.cgi?id='+id+'">'+str(count[id])+'</a></td></tr>')
print('</table>')
sys.stdout.write('Content-type: text/html\r\n\r\n') sys.stdout.write('Content-type: text/html\r\n\r\n')
sys.stdout.write('<html><body>\n')
sys.stdout.write('<html><body><pre>\n')
cgitb.enable() cgitb.enable()
arguments = cgi.FieldStorage() arguments = cgi.FieldStorage()
id = arguments['id'].value if 'id' in arguments:
#id = 'oppositeInnerCondition' id = arguments['id'].value
print(id) #id = 'oppositeInnerCondition'
print(id)
doSearch('../htdocs/devinfo/daca2-report', arguments) sys.stdout.write('<pre>\n')
#doSearch(os.path.expanduser('~/temp'), id) doSearch('../htdocs/devinfo/daca2-report', arguments)
#doSearch(os.path.expanduser('~/temp'), id)
sys.stdout.write('</pre></body></html>\n') sys.stdout.write('</pre>\n')
else:
summary('../htdocs/devinfo/daca2-report', arguments)
#summary(os.path.expanduser('~/temp'), arguments)
sys.stdout.write('</body></html>\n')