From dc6b404bc98f291f67f3215bdc3a6d285dc6a80d Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 22 Dec 2010 22:22:05 +0200 Subject: [PATCH] lp-set-dup: Config file support --- doc/lp-set-dup.1 | 29 ++++++++++++++++++++++++++++- lp-set-dup | 25 ++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/doc/lp-set-dup.1 b/doc/lp-set-dup.1 index 39a7c2b..03d3217 100644 --- a/doc/lp-set-dup.1 +++ b/doc/lp-set-dup.1 @@ -15,11 +15,38 @@ then perform required tasks on Launchpad. .SH OPTIONS Listed below are the command line options for \fBlp\-set\-dup\fR: .TP -.B \-h or \-\-help +.BR \-h ", " \-\-help Display a help message and exit. .TP .B \-f Skip confirmation prompt. +.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 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 BACKPORTPACKAGE_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE +The default value for \fB--lpinstance\fR. + +.SH SEE ALSO +.BR ubuntu\-dev\-tools (5) .SH AUTHORS \fBlp\-set\-dup\fR was written by Loïc Minier , diff --git a/lp-set-dup b/lp-set-dup index 63bb54f..b93d3e4 100755 --- a/lp-set-dup +++ b/lp-set-dup @@ -23,12 +23,13 @@ # Loïc Minier import sys - from optparse import OptionParser -import ubuntutools.lp.libsupport as lp_libsupport from launchpadlib.errors import HTTPError +import ubuntutools.lp.libsupport as lp_libsupport +from ubuntutools.config import UDTConfig + def die(message): print >> sys.stderr, "Fatal: " + message sys.exit(1) @@ -36,19 +37,29 @@ def die(message): if __name__ == '__main__': usage = "Usage: %prog [-f] [...]" optParser = OptionParser(usage) - optParser.add_option("-f", action = "store_true", - dest = "force", default = False, - help = "Skip confirmation prompt") - + optParser.add_option("-f", + help="Skip confirmation prompt", + dest="force", default=False, action="store_true") + optParser.add_option("-l", "--lpinstance", metavar="INSTANCE", + help="Launchpad instance to connect to (default: production)", + dest="lpinstance", default=None) + optParser.add_option("--no-conf", + help="Don't read config files or environment variables.", + dest="no_conf", default=False, action="store_true") (options, args) = optParser.parse_args() if len(args) < 2: optParser.error("Need at least a new main bug and a bug to dup") + config = UDTConfig(options.no_conf) + if options.lpinstance is None: + options.lpinstance = config.get_value("LPINSTANCE") + launchpad = None try: print "Setting up Launchpad" - launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools") + launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools", + server=options.lpinstance) print "Launchpad setup complete" except ImportError: suggestion = "check whether python-launchpadlib is installed"