massfile: Add option parsing and various fixes.

This commit is contained in:
Benjamin Drung 2010-12-23 12:18:30 +01:00
commit e0457ff333
3 changed files with 70 additions and 22 deletions

View File

@ -3,15 +3,25 @@
\fBmassfile\fR \- script for massfiling bugs against Ubuntu packages
.SH SYNOPSIS
\fBmassfile\fR <path to instructions file> <path to list file>
\fBmassfile\fR [\fIoptions\fR]
.SH DESCRIPTION
\fBmassfile\fR is a script for massfiling bugs against Ubuntu packages in Launchpad. It requires an instructions file describing the contents of the bug report and a list file which lists the packages which the bug will be filed against.
Templates for both files can be found in /usr/share/doc/ubuntu-dev-tools/examples.
.SH OPTIONS
.TP
.B \-l \fIINSTANCE\fR, \fB\-\-lpinstance\fR=\fIINSTANCE\fR
Use the specified instance of Launchpad (e.g. "staging"), instead of
the default of "production".
.TP
.B \-\-no\-conf
Do not read any configuration files, or configuration from environment
variables.
.SH EXAMPLES
\fBmassfile.instructions\fR - file designating the contents of the bug report
\fBinstructions\fR - file designating the contents of the bug report
subject: [UNMETDEPS] $pack has unmet dependencies
assignee:
@ -30,13 +40,29 @@ Templates for both files can be found in /usr/share/doc/ubuntu-dev-tools/example
.
Please have a look and make sure it's installable again.
\fBmassfile.list\fR - file designating the packages affected
\fBlist\fR - file designating the packages affected
Each package should be listed on a new line as follows:
z88dk
zope-quotafolder
.SH ENVIRONMENT
All of the \fBCONFIGURATION VARIABLES\fR below are also supported as
environment variables.
Variables in the environment take precedence to those in configuration
files.
.SH CONFIGURATION VARIABLES
The following variables can be set in the environment or in
.BR ubuntu\-dev\-tools (5)
configuration files.
In each case, the script\-specific variable takes precedence over the
package\-wide variable.
.TP
.BR MASSFILE_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE
The default value for \fB--lpinstance\fR.
.SH AUTHORS
\fBmassfile\fR was written by Iain Lane <iain@orangesquash.org.uk>, Daniel Hahler <ubuntu@thequod.de>. and Markus Korn <thekorn@gmx.de>.

View File

@ -23,11 +23,15 @@
#
# ##################################################################
import optparse
import os
import sys
import email
from ubuntutools.lp.libsupport import get_launchpad, translate_api_web, translate_web_api
from ubuntutools.config import UDTConfig
from ubuntutools.lp.libsupport import (get_launchpad,
translate_api_web,
translate_web_api)
def read_config():
instructions_file = open("instructions")
@ -77,23 +81,25 @@ def check_configfiles():
return result
def file_bug(config):
launchpad = get_launchpad("ubuntu-dev-tools")
def file_bug(config, launchpad):
try:
summary = config["subject"].replace("$pack", config["sourcepackage"])
description = config["text"].replace("$pack", config["sourcepackage"])
product_url = "%subuntu/+source/%s" %(launchpad._root_uri, config["sourcepackage"])
tags = filter(None, map(lambda t: t.strip("\n").strip(), config["tags"].split(",")))
product_url = "%subuntu/+source/%s" % \
(launchpad._root_uri, config["sourcepackage"])
tags = filter(None, map(lambda t: t.strip("\n").strip(),
config["tags"].split(",")))
bug = launchpad.bugs.createBug(description=description, title=summary,
target=product_url, tags=tags)
print "Successfully filed bug %i: %s" %(bug.id, translate_api_web(bug.self_link))
print "Successfully filed bug %i: %s" % \
(bug.id, translate_api_web(bug.self_link))
subscribers = filter(None, map(lambda t: t.strip("\n").strip(), config["subscribers"].split(",")))
subscribers = filter(None, map(lambda t: t.strip("\n").strip(),
config["subscribers"].split(",")))
for sub in subscribers:
subscribe_url = "%s~%s" %(launchpad._root_uri, sub)
subscribe_url = "%s~%s" % (launchpad._root_uri, sub)
bug.subscribe(person=subscribe_url)
#newly created bugreports have one task
@ -107,22 +113,23 @@ def file_bug(config):
assignee = config["assignee"]
if assignee:
assignee_url = "%s~%s" %(launchpad._root_uri, assignee)
assignee_url = "%s~%s" % (launchpad._root_uri, assignee)
task.assignee = assignee_url
task.lp_save()
except:
"Bug for '%s' was not filed." % config["sourcepackage"]
print >> sys.stderr, "Bug for '%s' was not filed." % \
config["sourcepackage"]
def read_buglist(url):
def read_buglist(url, launchpad):
if not url:
return set()
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
# 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 = get_launchpad("ubuntu-dev-tools")
packages = set()
api_url = translate_web_api(url, launchpad)
@ -138,19 +145,35 @@ def read_buglist(url):
return packages
def main():
p = optparse.OptionParser(description=
'Files bugs against multiple packages in Ubuntu. '
'Reads the bug from "instructions" and files them against '
'packages listed in "list". '
"If these files aren't preset they are created.")
p.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to (default: production)')
p.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
options, args = p.parse_args()
udtconfig = UDTConfig(options.no_conf)
if options.lpinstance is None:
options.lpinstance = udtconfig.get_value('LPINSTANCE')
if not check_configfiles():
sys.exit(1)
launchpad = get_launchpad('ubuntu-dev-tools', server=options.lpinstance)
config = read_config()
pack_list = read_list()
buglist = read_buglist(config["buglist-url"])
buglist = read_buglist(config["buglist-url"], launchpad)
for pack in pack_list:
if pack not in buglist:
config["sourcepackage"] = pack
file_bug(config)
file_bug(config, launchpad)
if __name__ == '__main__':
main()

View File

@ -30,7 +30,6 @@ BLACKLIST = {
'get-build-deps': 'No Help, runs sudo',
'grep-merges': 'No Help',
'lp-project-upload': 'Returns non-zero after help. Leaving u-d-t in LP: #524680',
'massfile': 'No Help. Leaves files in .',
'mk-sbuild': 'Fires up apt-get before showing help',
'pbuilder-dist-simple': 'No Help',
'setup-packaging-environment': 'Throws Error',