Created
July 9, 2011 01:25
-
-
Save slackorama/1073190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Print out (to stdout) a tag cloud of bugs in bugzilla for 1.7 | |
""" | |
from collections import defaultdict | |
import datetime | |
import cookielib | |
import urllib | |
import urllib2 | |
import csv | |
import netrc | |
import math | |
import random | |
bzdomain = 'XXXXX' | |
class InvalidDomainError(Exception): | |
pass | |
def print_report(input_stream, seven_days_ago, report_url): | |
data = defaultdict(lambda:0) | |
for row in input_stream: | |
data[row['Assignee'].replace('XXXXX','')] = int(row['Number of issues']) | |
max_length = max([len(key) for key in data.keys()]) | |
max_length = min(max_length, 50) | |
value_characters = 80 - max_length | |
max_value = max(data.values()) | |
scale = int(math.ceil(float(max_value) / value_characters)) | |
scale = max(10, scale) | |
data = [[value,key] for key,value in data.items()] | |
# data.sort(reverse=True) | |
random.shuffle(data) | |
print header() | |
print '<h1>Bug cloud (since %s)</h1>' % seven_days_ago | |
format = "%" + str(max_length) + "s [%6d] %s" | |
print '<div>' | |
for value,key in data: | |
print '<span style="font-size: %s" title="%s closed">%s</span>' % (value * scale, value, key) | |
# print format % (key[:max_length], value, (value / scale) * "*") | |
print '</div>' | |
print '<!-- scale %s -->' % scale | |
print '<div><a href="%s">Visit bugzilla to see the actual report</a></div>' % report_url.replace('ctype=csv','format=table') | |
print footer() | |
def get_bugs(): | |
seven_days_ago = get_seven_days_ago() | |
n = netrc.netrc() | |
auth = n.authenticators(bzdomain) | |
if not auth: | |
raise InvalidDomainError('No domain found in netrc') | |
url = 'https://%s/index.cgi?Bugzilla_login=%s&Bugzilla_password=%s&\ | |
Bugzilla_restrictlogin=on&GoAheadAndLogIn=1&GoAheadAndLogIn=Log+in' % \ | |
(bzdomain, urllib.quote_plus(auth[0]), urllib.quote_plus(auth[2])) | |
report_url = 'https://%s/report.cgi?bug_file_loc=&bug_file_loc_type=allwordssubstr&bug_id=&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&bugidtype=include&chfield=bug_status&chfieldfrom=%s&chfieldto=now&chfieldvalue=&deadlinefrom=&deadlineto=&email1=&email2=&emailassigned_to1=1&emailassigned_to2=1&emailcc2=1&emailreporter2=1&emailtype1=substring&emailtype2=substring&field0-0-0=component&keywords=&keywords_type=allwords&longdesc=&longdesc_type=allwordssubstr&short_desc=&short_desc_type=allwordssubstr&target_milestone=1.7&type0-0-0=notequals&value0-0-0=Merge+Request&x_axis_field=&y_axis_field=assigned_to&z_axis_field=&width=600&height=350&action=wrap&ctype=csv&format=table' % (bzdomain, seven_days_ago) | |
# this is just to authenticate | |
cj = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
r = opener.open(url) | |
print_report(csv.DictReader(opener.open(report_url)),seven_days_ago, report_url); | |
def get_seven_days_ago(): | |
delta = datetime.timedelta(days=7) | |
today = datetime.date.today() | |
seven_days_ago = today - delta | |
return seven_days_ago.strftime('%Y-%m-%d') | |
def header(): | |
return """<html> | |
<head> | |
<title>Bugs closed</title> | |
<style type="text/css"> | |
* {line-height: .9em;} | |
</style> | |
</head><body>""" | |
def footer(): | |
return """</body></html>""" | |
if __name__ == '__main__': | |
bugs = get_bugs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment