-
Notifications
You must be signed in to change notification settings - Fork 2
/
dashboard.py
executable file
·142 lines (115 loc) · 4.06 KB
/
dashboard.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
#
# Author: Mike Hoye
# Email: mhoye@mozilla.com
# License: MPL
import json
import urllib
import urllib2
import sys
import re
import logging, logging.handlers
from datetime import date, timedelta
from os import mkdir
from bugzilla.agents import BMOAgent
from bugzilla.utils import get_credentials
from xml.sax.saxutils import escape
def main():
fmt = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(message)s',
datefmt="%Y-%m-%d %H:%M:%S %Z")
if "--quiet" not in sys.argv:
sh = logging.StreamHandler()
sh.setFormatter(fmt)
sh.setLevel(logging.DEBUG)
logging.root.addHandler(sh)
rfh = logging.handlers.RotatingFileHandler("/var/log/bz-triage.log",
backupCount=10)
rfh.setFormatter(fmt)
rfh.setLevel(logging.DEBUG)
logging.root.addHandler(rfh)
logging.root.setLevel(logging.DEBUG)
logging.info("Generating static audit page.")
cfg = json.load(open("/etc/bz-triage.cfg"))
server = cfg["server"].encode("utf8")
owner = cfg["owner"].encode("utf8")
user = cfg["user"]
password = cfg["password"]
bugdays = dict()
try:
contributors = json.load(open("/var/local/bz-triage/contributors.cfg"))
bzagent = BMOAgent(user,password)
except:
logging.info("Failed to obtain data sources.")
exit(-1)
for inc in range(1,10):
d = date.today() - timedelta(inc)
bugdays[d] = getOutstandingBugs(bzagent, d)
print '''<html>
<head>
<title>All Hail King Canute</title>
<link href="index.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="logo">
<center><img src="allthethings.jpeg" width="800px"></center>
</div>
<div id="header">
<h2>Current Status</h2>
</div>
<div id="body">
<h3>Number of contributors: %d</h3>
''' % (len(contributors))
print '''</div>
<div id="header">
Outstanding Bugs!
</div>
'''
for key in list(reversed( sorted(bugdays.keys()))):
print '''<div class="dayheader">Outstanding bugs for %s: %s</div>''' % (str(key), str(len(bugdays[key])))
print '''<div class="day"><blockquote>'''
for boog in bugdays[key]:
print '''<br/><a href="https://bugzilla.mozilla.org/%s">Bug %s</a>: %s''' % (boog['id'], boog['id'], escape(boog['summary']))
print '''</blockquote></div>'''
print "</body></html>"
def getOutstandingBugs(bzagent,someday):
date_from = str(date.isoformat(someday)).encode("utf8")
date_to = str(date.isoformat(someday)).encode("utf8")
# NOTE: The reason it's laid out like this is because bztools doesn't
# seem to work with the "product=foo,bar" syntax, despite what the docs say
option_sets = {
'firefox_untriaged': {
'changed_field':'[Bug creation]',
'changed_after':date_from,
'changed_before': date_to,
'product': 'Firefox',
'component':'Untriaged',
'status': 'UNCONFIRMED'},
'core_untriaged': {
'changed_field':'[Bug creation]',
'changed_after':date_from,
'changed_before': date_to,
'product': 'Toolkit',
'component':'Untriaged',
'status': 'UNCONFIRMED'},
'toolkit_untriaged': {
'changed_field':'[Bug creation]',
'changed_after':date_from,
'changed_before': date_to,
'product': 'Core',
'component':'Untriaged',
'status': 'UNCONFIRMED'},
}
buglist = list()
# Get the bugs from the bugzilla API
for opt in option_sets:
bug_url = ("https://bugzilla.mozilla.org/rest/bug?" + urllib.urlencode(option_sets[opt]) )
bug_url = bug_url.replace("ug+creat","ug%20creat").replace("%5B","[").replace("%5D","]")
print bug_url
resp = urllib.urlopen(bug_url)
bugdict = json.loads(resp.read())
for c in bugdict['bugs']:
buglist.append(c)
#print date_to + " - " + str(len(buglist))
return buglist
if __name__ == "__main__":
main()