import wikitcms.wiki as wk import wikitcms.event as ev import wikitcms.page as pg import wikitcms.release as rl from collections import defaultdict import re import os import sys import datetime import shutil SANITY_SUB = re.compile(r'[^A-Za-z0-9]') def get_bitmap_html(bitmap): out = '' sym_0 = "⠄" sym_1 = "⠄" sym_2 = "⠆" sym_3 = "⠇" for compose, cnt, style in bitmap: out += '' % style if cnt == 0: out+= sym_0 elif cnt < 3: out+= sym_1 elif cnt < 5: out+= sym_2 else: out+= sym_3 out+='' out += '' return out class Test(object): def __init__(self, name, testcase, resultrows): self.name = name self.testcase = testcase self.milestone = resultrows[len(resultrows)-1][1].milestone self.passes = defaultdict(list) self.warns = defaultdict(list) self.fails = defaultdict(list) self.composes = set() self.last_tested = "" bitmap = [] for rowtup in resultrows: compose = rowtup[0] row = rowtup[1] self.composes.add(compose) p = 0 f = 0 w = 0 rlists = row.results.values() for rlist in rlists: for result in rlist: if result.status == 'pass': self.last_tested = compose self.passes[compose].append(result) p += 1 if result.status == 'fail': self.last_tested = compose self.fails[compose].append(result) f += 1 if result.status == 'warn': self.last_tested = compose self.warns[compose].append(result) w += 1 bitmap.append([self.last_tested, 0, 'nottested']) if p+f+w > 0: b = bitmap[-1] if f+w == 0: # just passed b[2] = 'pass' elif p+w == 0: # just failed b[2] = 'fail' elif w > 0: b[2] = 'warn' b[1] += p+f+w self.bitmap = get_bitmap_html(bitmap) def print_results_html(test_dict, outdir, outfile): col_names = ['Testcase URL','Release Level', 'Last in', 'Coverage', 'Details']#'Tested', 'Pass', 'Fail', 'Warn', 'Details'] theader = "\n".join(map(lambda x: "%s" % x, col_names)) trs = [] fmt_tc = "%s" fmt = '%s\n'* (len(col_names)-2) fmt_link = 'Details\n' # sorted_results = sorted(results_dict.values(), key=attrgetter('release_level', 'last_tested_in')) for test in tests: s = fmt_tc % (test.testcase, test.name) s += fmt % (test.milestone, test.last_tested, test.bitmap) s += fmt_link % SANITY_SUB.sub('_', test.name) trs.append("%s" % s) tbody = "\n".join(trs) # directory with templates for pages htmldir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'html') # create the Overview page print "Creating HTML output: %s" % os.path.join(outdir, outfile) template = open(os.path.join(htmldir, 'index.html')).read() fout = open(os.path.join(outdir, outfile), 'w') fout.write(template % {'timestamp': datetime.datetime.utcnow(), 'theader': theader, 'tbody': tbody}) fout.close() # create detail pages template = open(os.path.join(htmldir, 'testcase.html')).read() for test in tests: body = "" for page in pages: body += "

%s
\n" % (page.wikiname, page.wikiname) compose = page.event.milestone + page.event.compose if compose not in test.composes: body += "No data
\n" continue body += "Passes: %s
" % len(test.passes[compose]) body += "Warns: %s
" % len(test.warns[compose]) body += "Fails: %s

\n" fname = os.path.join(outdir, '%s.html' % SANITY_SUB.sub('_', test.name)) fout = open(fname, 'w') fout.write(template % {'timestamp': datetime.datetime.utcnow(), 'testcase_name': test.testcase, 'body': body}) fout.close() wiki = wk.Wiki(('https', 'fedoraproject.org'), '/w/') event1 = ev.ComposeEvent('21', 'Alpha', 'RC1', wiki) event2 = ev.ComposeEvent('21', 'Beta', 'TC1', wiki) event3 = ev.ComposeEvent('21', 'Beta', 'TC2', wiki) pages = list() pages.append(pg.ComposePage(wiki, event1, 'Installation')) pages.append(pg.ComposePage(wiki, event2, 'Installation')) pages.append(pg.ComposePage(wiki, event3, 'Installation')) row_dict = defaultdict(list) tests = list() for page in pages: print("Processing: " + page.wikiname) resultrows = page.get_resultrows(statuses=['pass', 'warn', 'fail'], transferred=False) for row in resultrows: row_dict[(row.name, row.testcase)].append((page.event.milestone + page.event.compose, row)) for test, rows in row_dict.iteritems(): tests.append(Test(test[0], test[1], rows)) print_results_html(tests, '/tmp/tcstats_test', 'test.html') # copy javascript htmldir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'html') shutil.copytree(os.path.join(htmldir, 'js'), os.path.join('/tmp/tcstats_test', 'js')) """ def main(): global options logging.basicConfig(format='%(message)s') outdir = tempfile.mkdtemp(prefix = 'tc_report_') parse_args() # download and parse all pages for category in (INSTALLATION_NAME, BASE_NAME, DESKTOP_NAME): pages = list_pages(category) results_dict = {} for page in pages: try: parse_matrix(page, results_dict) except MatrixLookupException: print "Failed to find Results Matrix for %s" % page filename = SANITY_SUB.sub("_", category) print_results_html(pages, results_dict, outdir, filename+".html") # copy javascript htmldir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'html') shutil.copytree(os.path.join(htmldir, 'js'), os.path.join(outdir, 'js')) # Create index page fout = open(os.path.join(outdir, "index.html"), "w") fout.write("\n") fout.write("

Created at: %s (UTC)

" % datetime.datetime.utcnow()) for category in (INSTALLATION_NAME, BASE_NAME, DESKTOP_NAME): fname = SANITY_SUB.sub("_", category) + ".html" fout.write("%s
" % (fname, category)) fout.write("\n") fout.close() print "HTML Output: %s" % os.path.join(outdir, "index.html") print outdir if __name__ == '__main__': try: main() except KeyboardInterrupt: sys.exit(1) """