#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (C) 2007 Canonical Ltd., Daniel Holbach # Copyright (C) 2008 Jonathan Patrick Davies # # ################################################################## # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # See file /usr/share/common-licenses/GPL-3 for more details. # # ################################################################## # # # hugdaylist - produces MoinMoin wiki formatted tables based on a Launchpad bug # list. # # hugdaylist # - produces lists like https://wiki.ubuntu.com/UbuntuBugDay/20070912?action=raw # # hugdaylist -n # - will only list URLs. import os import re import string import sys from optparse import OptionParser from ubuntutools.lp.libsupport import get_launchpad, translate_web_api, translate_api_web def check_args(): howmany = -1 url = "" # Our usage options. usage = "usage: %prog [-n ] launchpad-buglist-url" optParser = OptionParser(usage) argsParsed = 0 # Options - namely just the number of bugs to output. optParser.add_option("-n", "--number", type = "int", dest = "number", help = "Number of entries to output.") # Parse arguments. (options, args) = optParser.parse_args() # Check if we want a number other than the default. howmany = options.number # Check that we have an URL. if not args: print >> sys.stderr, "An URL pointing to a Launchpad bug list is " \ "required." optParser.print_help() sys.exit(1) else: url = args[argsParsed] return (howmany, url) def filter_unsolved(task): # TODO: don't use this filter here, only check status and assignee of # the given task # Filter out special types of bugs: # - https://wiki.ubuntu.com/Bugs/HowToTriage#Special%20types%20of%20bugs subscriptions = set(s.person.name for s in task.bug.subscriptions) #this is expensive, parse name out of self_link instead? if (task.status != "Fix Committed" and (not task.assignee or task.assignee.name in ['motu','desktop-bugs']) and 'ubuntu-main-sponsors' not in subscriptions and 'ubuntu-universe-sponsors' not in subscriptions and 'ubuntu-archive' not in subscriptions): return True return False def main(): (howmany, url) = check_args() if len(url.split("?", 1)) == 2: # search options not supported, because there is no mapping web ui options <-> API options print >> sys.stderr, "Options in url are not supported, url: %s" %url sys.exit(1) launchpad = None try: launchpad = get_launchpad("ubuntu-dev-tools") except IOError, e: print e sys.exit(1) api_url = translate_web_api(url, launchpad) try: product = launchpad.load(api_url) except Exception, e: x = getattr(e, "response", {}) if response.get("status", None) == "404": print >> sys.stderr, "The URL at '%s' does not appear to be a valid url to a product" %url sys.exit(1) else: raise bl = product.searchTasks() l = filter(filter_unsolved, bl) if not l: print "Bug list of %s is empty." % url sys.exit(0) if howmany == -1: howmany = len(l) print """ ## || This task is done || somebody || || ## || This task is assigned || somebody || || ## || This task isn't || ... || || ## || This task is blocked on something || somebody || || || Bug || Subject || Triager ||""" for i in list(l)[:howmany]: bug = i.bug print '|| [%s %s] || %s || ||' % \ (translate_api_web(bug.self_link), bug.id, bug.title) if __name__ == '__main__': try: main() except KeyboardInterrupt: print >> sys.stderr, "Aborted." sys.exit(1)