Created
December 17, 2011 21:42
-
-
Save ziadsawalha/1491498 to your computer and use it in GitHub Desktop.
Launchpad Project Bug Lister with Milestones
This file contains 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 | |
# | |
# Lists Launchpad bugs in the console showing their targetted milestone | |
# | |
# Usage: python buglist.py [project_name] | |
# | |
# I created this when I couldn't find a way to list the bugs in Keystone and | |
# show their targetted milestones so I could shuffle them around | |
# | |
from launchpadlib.launchpad import Launchpad | |
import sys | |
def show_bugs(project_name): | |
lp = Launchpad.login_anonymously("Ziad Sawalha's bug lister", 'production', | |
'~/.launchpadlib-ziad', version="devel") | |
project = lp.projects[project_name] | |
bugs = project.searchTasks() | |
report = [] | |
for bug in bugs.entries: | |
number = bug['bug_link'].split('/')[-1] | |
ml = bug['milestone_link'] | |
if ml: | |
milestone = ml.split('/')[-1] | |
else: | |
milestone = '' | |
status = bug['status'] | |
importance = bug['importance'] | |
name = bug['title'][bug['title'].index('"') + 1:-1] | |
report.append((number, status, importance, milestone, name)) | |
print Table('Bugs for %s' % project_name, | |
('#', 'Status', 'Importance', 'Milestone', 'Name'), | |
report) | |
class Table: | |
"""Prints data in table for console output | |
Syntax print Table("This is the title", | |
["Header1","Header2","H3"], | |
[[1,2,3],["Hi","everybody","How are you??"],[None,True,[1,2]]]) | |
""" | |
def __init__(self, title=None, headers=None, rows=None): | |
self.title = title | |
self.headers = headers if headers is not None else [] | |
self.rows = rows if rows is not None else [] | |
self.nrows = len(self.rows) | |
self.fieldlen = [] | |
ncols = len(headers) | |
for h in range(ncols): | |
max = 0 | |
for row in rows: | |
if len(str(row[h])) > max: | |
max = len(str(row[h])) | |
self.fieldlen.append(max) | |
for i in range(len(headers)): | |
if len(str(headers[i])) > self.fieldlen[i]: | |
self.fieldlen[i] = len(str(headers[i])) | |
self.width = sum(self.fieldlen) + (ncols - 1) * 3 + 4 | |
def __str__(self): | |
horizontal_bar = "-" * self.width | |
if self.title: | |
title = "| " + self.title + " " * \ | |
(self.width - 3 - (len(self.title))) + "|" | |
out = [horizontal_bar, title, horizontal_bar] | |
else: | |
out = [] | |
header = "" | |
for i in range(len(self.headers)): | |
header += "| %s" % (str(self.headers[i])) + " " * \ | |
(self.fieldlen[i] - len(str(self.headers[i]))) + " " | |
header += "|" | |
out.append(header) | |
out.append(horizontal_bar) | |
for i in self.rows: | |
line = "" | |
for j in range(len(i)): | |
line += "| %s" % (str(i[j])) + " " * \ | |
(self.fieldlen[j] - len(str(i[j]))) + " " | |
out.append(line + "|") | |
out.append(horizontal_bar) | |
return "\r\n".join(out) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
show_bugs(sys.argv[1]) | |
else: | |
show_bugs('keystone') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment