ubuntu-dev-tools/hugdaylist

142 lines
4.4 KiB
Plaintext
Raw Permalink Normal View History

2019-09-04 14:42:20 -03:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Canonical Ltd., Daniel Holbach
# Copyright (C) 2008 Jonathan Patrick Davies <jpds@ubuntu.com>
#
# ##################################################################
#
# 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.
2010-12-03 00:06:43 +01:00
#
# 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 <url>
# - produces lists like https://wiki.ubuntu.com/UbuntuBugDay/20070912?action=raw
#
# hugdaylist -n <howmany> <url>
# - will only list <howmany> URLs.
import sys
from optparse import OptionParser
from launchpadlib.launchpad import Launchpad
from ubuntutools.lp.libsupport import translate_web_api
from ubuntutools import getLogger
Logger = getLogger(__name__)
2017-05-01 00:20:03 +02:00
def check_args():
howmany = -1
url = ""
# Our usage options.
usage = "usage: %prog [-n <number>] launchpad-buglist-url"
2010-12-27 21:54:31 +01:00
opt_parser = OptionParser(usage)
# Options - namely just the number of bugs to output.
2010-12-27 21:54:31 +01:00
opt_parser.add_option("-n", "--number", type="int",
dest="number", help="Number of entries to output.")
# Parse arguments.
2010-12-27 21:54:31 +01:00
(options, args) = opt_parser.parse_args()
2010-12-03 00:06:43 +01:00
# Check if we want a number other than the default.
howmany = options.number
# Check that we have an URL.
if not args:
Logger.error("An URL pointing to a Launchpad bug list is required.")
2010-12-27 21:54:31 +01:00
opt_parser.print_help()
sys.exit(1)
else:
2010-12-27 21:54:31 +01:00
url = args[0]
return (howmany, url)
2017-05-01 00:20:03 +02:00
def filter_unsolved(task):
2010-12-03 00:06:43 +01:00
# 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
2010-12-27 14:21:01 +01:00
# this is expensive, parse name out of self_link instead?
subscriptions = set(s.person.name for s in task.bug.subscriptions)
if (task.status != "Fix Committed" and
2017-05-01 00:20:03 +02:00
(not task.assignee or task.assignee.name in ['motu', 'desktop-bugs']) and
'ubuntu-sponsors' not in subscriptions and
'ubuntu-archive' not in subscriptions):
return True
return False
2017-05-01 00:20:03 +02:00
2010-12-03 00:06:43 +01:00
def main():
(howmany, url) = check_args()
if len(url.split("?", 1)) == 2:
2010-12-27 14:21:01 +01:00
# search options not supported, because there is no mapping web ui
# options <-> API options
Logger.error("Options in url are not supported, url: %s" % url)
sys.exit(1)
2010-12-03 00:06:43 +01:00
launchpad = None
try:
launchpad = Launchpad.login_with("ubuntu-dev-tools", 'production')
2019-09-04 14:42:20 -03:00
except IOError as error:
Logger.exception(error)
sys.exit(1)
2010-12-03 00:06:43 +01:00
api_url = translate_web_api(url, launchpad)
try:
product = launchpad.load(api_url)
2019-09-04 14:42:20 -03:00
except Exception as error:
2010-12-27 21:54:31 +01:00
response = getattr(error, "response", {})
if response.get("status", None) == "404":
Logger.error("The URL at '%s' does not appear to be a "
"valid url to a product" % url)
sys.exit(1)
else:
raise
2010-12-03 00:06:43 +01:00
2010-12-27 21:54:31 +01:00
bug_list = [b for b in product.searchTasks() if filter_unsolved(b)]
2010-12-27 21:54:31 +01:00
if not bug_list:
Logger.info("Bug list of %s is empty." % url)
sys.exit(0)
if howmany == -1:
2010-12-27 21:54:31 +01:00
howmany = len(bug_list)
Logger.info("""
## ||<rowbgcolor="#CCFFCC"> This task is done || somebody || ||
## ||<rowbgcolor="#FFFFCC"> This task is assigned || somebody || <status> ||
## ||<rowbgcolor="#FFEBBB"> This task isn't || ... || ||
## ||<rowbgcolor="#FFCCCC"> This task is blocked on something || somebody || <explanation> ||
2010-12-03 00:06:43 +01:00
2019-09-04 14:42:20 -03:00
|| Bug || Subject || Triager ||""")
2010-12-27 21:54:31 +01:00
for i in list(bug_list)[:howmany]:
bug = i.bug
Logger.info('||<rowbgcolor="#FFEBBB"> [%s %s] || %s || ||' %
(bug.web_link, bug.id, bug.title))
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
Logger.error("Aborted.")
sys.exit(1)