1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
from __future__ import with_statement
__metaclass__ = type
from datetime import datetime
import logging
import os
from genshi.template import TemplateLoader
log = logging.getLogger(__name__)
def load_report_template(template_name):
"""Retrieve a Genshi HTML template instance for the deployment report."""
loader = TemplateLoader(
os.path.join(os.path.dirname(__file__), 'templates'))
return loader.load(template_name)
def render_deployment_report(stream, context, template_name):
"""Render the deployment report to the given stream using the given
context.
"""
template = load_report_template(template_name)
template_stream = template.generate(**context)
stream.write(template_stream.render('html'))
def write_triage_html_report(new_bugtasks, new_undecided_bugtasks,
new_incomplete_with_response_bugtasks,
new_incomplete_without_response_bugtasks, other_bugtasks,
directory=None):
"""Write an HTML report to a directory."""
report_timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
context = dict(
new_bugtasks=new_bugtasks,
new_undecided_bugtasks=new_undecided_bugtasks,
new_incomplete_with_response_bugtasks=new_incomplete_with_response_bugtasks,
new_incomplete_without_response_bugtasks=new_incomplete_without_response_bugtasks,
other_bugtasks=other_bugtasks,
report_timestamp=report_timestamp,
)
report_name = "triage-report.html"
report_path = os.path.join(directory, report_name)
print report_path
with file(report_path, 'w') as reportfile:
log.info("Writing HTML report to %s", report_path)
render_deployment_report(reportfile, context, 'bugs-report.html')
def write_last_touched_html_report(last_touched_list, directory=None):
report_timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
context = dict(
last_touched_bugtasks=last_touched_list,
report_timestamp=report_timestamp,
)
report_name = "triage-last-touched-report.html"
report_path = os.path.join(directory, report_name)
with file(report_path, 'w') as reportfile:
log.info("Writing HTML report to %s", report_path)
render_deployment_report(
reportfile, context, 'bugs-last-touched-report.html')
def write_wiki_output(data_dict, output_filename):
reportfile = open(output_filename, 'w')
reportfile.write("<<TableOfContents>>\n")
for title, bugtasks in data_dict.iteritems():
reportfile.write("= %s =\n" % title)
reportfile.write("|| Bug # || Title || Package || Status || "
"Importance || Assignee || Milestone || Bug Last Touched ||\n")
for bugtask in bugtasks:
assignee = "-"
milestone = "-"
if bugtask.assignee:
assignee = "[[https://launchpad.net/~%s | %s]]" % (
bugtask.assignee.name, bugtask.assignee.display_name)
if bugtask.milestone:
milestone = ("[[https://launchpad.net/ubuntu/+milestone/%s | %s]]"
% (bugtask.milestone.name, bugtask.milestone.name))
line = "|| #Bug:%s || %s || %s || %s || %s || %s || %s|| %s ||\n" % (
bugtask.bug_id, bugtask.bug.title, bugtask.target,
bugtask.status, bugtask.importance, assignee, milestone,
bugtask.bug.last_changed.strftime("%Y-%m-%d %H:%M"))
reportfile.write(line)
reportfile.flush()
reportfile.close()
|