In particular, I want to show you how to search for bugs, teach you a bit about Launchpad's internal data model and help you help yourself when it comes to figuring out Launchpad APIs.
The script at lp:~jml/+junk/bugstats is designed to tell you how good you are at filing bugs. It uses a very simple metric: out of the bugs that you've filed, how many actually have been fixed.
$ ./bugstats.py ubuntu jmlTo do that, we need to:
jml is 22.22% successful on bugs in Ubuntu
$ ./bugstats.py launchpad-code jml
jml is 47.63% successful on bugs in Launchpad Code
- get the "project" and person referred to on the command line
- search for all fixed bugs filed by that person
- search for all bugs in total by that same person
- count them both
- divide them
- print them!
We get the pillar and person like this:
pillar = launchpad.projects[pillar_name]Pretty easy, huh? Now, how do we search for bug tasks?
reporter = launchpad.people[reporter_name]
The first port of call is to go to the Launchpad API reference page. I'm going to look for the string 'reporter', since that's the one thing I definitely know I want to find.
Eventually, I found the
searchTasks method (named operation) that's on pillars and takes a bug_reporter parameter and a status parameter. It returns a collection of bug_tasks, which are the objects that represent the rows in the table you see at the top of a bug page.I can find the bugtasks for the bugs I've reported that have been fixed by doing:
fixed_bugtasks = pillar.searchTasks(It took me a while to figure out exactly how to spell "Fix Released". I ended up using trial and error.
bug_reporter=reporter, status=['Fix Released'])
Similarly, I can all the bugtasks for bugs I've filed by doing:
total_bugtasks = pillar.searchTasks(I cheated a bit for that one and looked at the launchpad code to get a list of all bug statusus. The default for
bug_reporter=reporter,
status=[
"New",
"Incomplete",
"Invalid",
"Won't Fix",
"Confirmed",
"Triaged",
"In Progress",
"Fix Committed",
'Fix Released'])
searchTasks is to only return open bugs.Once we've got the collections of bug tasks, we need to get their counts. In an ideal world, it would be
len(total_bugtasks), but sadly bug 274074 means that len is really, really slow here.Instead, I wrote this helper function:
def length(collection):With that, I can calculate & print my success rate at filing bugs:
# XXX: Workaround bug 274074. Thanks wgrant.
return int(collection._wadl_resource.representation['total_size'])
percentage = 100.0 * length(fixed_bugtasks) / length(total_bugtasks)Next up on the API, I'll talk about some of the gotchas and what you can do about them.
print "%s is %.2f%% successful on bugs in %s" % (
reporter.display_name, percentage, pillar.display_name)

0 comments:
Post a Comment