From 86b7ff977cac1ab748edaf29f9857a9d54c50c96 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Thu, 23 Dec 2010 12:35:41 +0200 Subject: [PATCH] Add option parsing to massfile, for lpinstance, correct manpage's view on file locations --- doc/massfile.1 | 32 +++++++++++++++++++++++++++++--- massfile | 30 +++++++++++++++++++++++------- ubuntutools/test/test_help.py | 1 - 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/doc/massfile.1 b/doc/massfile.1 index 9e104d4..5825906 100644 --- a/doc/massfile.1 +++ b/doc/massfile.1 @@ -3,15 +3,25 @@ \fBmassfile\fR \- script for massfiling bugs against Ubuntu packages .SH SYNOPSIS -\fBmassfile\fR +\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 , Daniel Hahler . and Markus Korn . diff --git a/massfile b/massfile index 224c166..aeef2e2 100755 --- a/massfile +++ b/massfile @@ -23,10 +23,12 @@ # # ################################################################## +import optparse import os import sys import email +from ubuntutools.config import UDTConfig from ubuntutools.lp.libsupport import get_launchpad, translate_api_web, translate_web_api def read_config(): @@ -77,9 +79,7 @@ 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"]) @@ -113,7 +113,7 @@ def file_bug(config): except: "Bug for '%s' was not filed." % config["sourcepackage"] -def read_buglist(url): +def read_buglist(url, launchpad): if not url: return set() @@ -122,7 +122,6 @@ def read_buglist(url): 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,17 +137,34 @@ 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") + opts, 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__': diff --git a/ubuntutools/test/test_help.py b/ubuntutools/test/test_help.py index 4b8e339..1d60076 100644 --- a/ubuntutools/test/test_help.py +++ b/ubuntutools/test/test_help.py @@ -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',