From 41cc2fa1943ae2711ae0316d454d973af891efef Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 21 Dec 2010 21:42:32 +0100 Subject: [PATCH] sponsor-patch: Add new --lpinstance and --no-conf options and support configuration files. --- debian/changelog | 6 ++- doc/sponsor-patch.1 | 62 +++++++++++++++++++------------ sponsor-patch | 56 +++++++++++++++++++--------- ubuntutools/sponsor_patch/main.py | 6 +-- 4 files changed, 85 insertions(+), 45 deletions(-) diff --git a/debian/changelog b/debian/changelog index 08f8689..87d027a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,7 +22,11 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low * ubuntutools/lp/lpapicache.py: Allow easier selection of 'staging' as LP instance to use (lp: #693060). - -- Michael Bienia Tue, 21 Dec 2010 19:14:57 +0100 + [ Benjamin Drung ] + * sponsor-patch: Add new --lpinstance and --no-conf options and support + configuration files. + + -- Benjamin Drung Tue, 21 Dec 2010 21:39:54 +0100 ubuntu-dev-tools (0.108) experimental; urgency=low diff --git a/doc/sponsor-patch.1 b/doc/sponsor-patch.1 index ee592fd..66cb516 100644 --- a/doc/sponsor-patch.1 +++ b/doc/sponsor-patch.1 @@ -45,11 +45,11 @@ The changelog timestamp is touched. .PP Should any checks (or the build fail), the user has an option to edit the patched source and try building it again. - -The sources and patches will be downloaded into the working directory -(which defaults to the current directory). -The output of the build tool will be placed in -\fIworkdir\fR/\fIsourcepkg\fB\-buildresult/\fR. +.PP +Unless a working directory is specified, the sources and patches will be +downloaded into a temporary directory in \fB/tmp\fR, which is removed once the +script finishes running. +The output of the build tool will be placed in \fIworkdir\fR/\fBbuildresult/\fR. .SH OPTIONS .TP @@ -61,16 +61,26 @@ by \fBpbuilderrc\fR(5) to select the correct base image. .B \-B \fIBUILDER\fR, \fB\-\-builder\fR=\fIBUILDER Use the specify builder to build the package. Supported are \fBpbuilder\fR(8), \fBpbuilder-dist\fR(1), and \fBsbuild\fR(1). -This overrides \fBUBUNTUTOOLS_BUILDER\fR and \fBSPONSOR_PATCH_BUILDER\fR. The default is \fBpbuilder\fR(8). .TP .BR \-e ", " \-\-edit Launch a sub-shell to allow editing of the patched source before building. .TP +.BR \-h ", " \-\-help +Display a help message and exit. +.TP .B \-k \fIKEY\fR, \fB\-\-key\fR=\fIKEY Specify a key ID for signing the upload. .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. +.TP .BR \-s ", " \-\-sponsor Shortcut for sponsored uploads. Equivalent to \fB\-b \-u ubuntu\fR. .TP @@ -84,30 +94,33 @@ Update the build environment before attempting to build. Print more information. .TP .B \-w \fIDIR\fR, \fB\-\-workdir\fR=\fIDIR -Use the specified working directory, creating it if necessary, instead -of the current directory. This overrides \fBSPONSOR_PATCH_WORKDIR\fR. -.TP -.BR \-h ", " \-\-help -Display a help message and exit. +Use the specified working directory, creating it if necessary. +If \fIWORKDIR\fR is not specified, a temporary directory is created, which is +deleted before \fIsponsor-patch\fR exits. .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 -.B UBUNTUTOOLS_BUILDER -The default builder for Ubuntu development tools that support it (including -\fBsponsor\-patch\fR). -Supported are \fBpbuilder\fR(8), \fBpbuilder-dist\fR(1), and \fBsbuild\fR(1). -If unset and not provided on the command line, \fBpbuilder\fR(8) is used. - +.BR SPONSOR_PATCH_BUILDER ", " UBUNTUTOOLS_BUILDER +The default value for \fB\-\-builder\fR. .TP -.B SPONSOR_PATCH_BUILDER -The default builder for \fBsponsor\-patch\fR. -If specified, this overrides \fBUBUNTUTOOLS_BUILDER\fR. - +.BR SPONSOR_PATCH_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE +The default value for \fB--lpinstance\fR. .TP -.B SPONSOR_PATCH_WORKDIR -The default working directory for \fBsponsor\-patch\fR. If unset and not -provided on the command line, the current directory is used. +.BR SPONSOR_PATCH_UPDATE_BUILDER ", " UBUNTUTOOLS_UPDATE_BUILDER +The default value for \fB--update\fR. +.TP +.BR SPONSOR_PATCH_WORKDIR ", " UBUNTUTOOLS_WORKDIR +The default value for \fB--workdir\fR. .SH EXAMPLES Test-building and sponsoring an upload of bug \fB1234\fR: @@ -133,6 +146,7 @@ Performing a test build of bug \fB1234\fR in your PPA: .BR pbuilder (8), .BR pbuilder-dist (1), .BR sbuild (1), +.BR ubuntu\-dev\-tools (5) .BR update\-maintainer (1) .SH AUTHORS diff --git a/sponsor-patch b/sponsor-patch index 49000a5..7addeee 100755 --- a/sponsor-patch +++ b/sponsor-patch @@ -16,8 +16,11 @@ import optparse import os +import shutil import sys +import tempfile +from ubuntutools.config import UDTConfig from ubuntutools.builder import getBuilder from ubuntutools.logger import Logger from ubuntutools.sponsor_patch.main import main @@ -27,27 +30,22 @@ usage = "%s [options] " % (script_name) epilog = "See %s(1) for more info." % (script_name) parser = optparse.OptionParser(usage=usage, epilog=epilog) -if "SPONSOR_PATCH_WORKDIR" in os.environ: - default_workdir = os.path.abspath(os.environ["SPONSOR_PATCH_WORKDIR"]) -else: - default_workdir = os.getcwd() - -if "SPONSOR_PATCH_BUILDER" in os.environ: - default_builder = os.environ["SPONSOR_PATCH_BUILDER"] -else: - default_builder = None - parser.add_option("-b", "--build", dest="build", help="Build the package with the specified builder.", action="store_true", default=False) -parser.add_option("-B", "--builder", dest="builder", - help="Specify the package builder (default pbuilder)", - default=default_builder) +parser.add_option("-B", "--builder", dest="builder", default=None, + help="Specify the package builder (default pbuilder)") parser.add_option("-e", "--edit", help="launch sub-shell to allow editing of the patch", dest="edit", action="store_true", default=False) parser.add_option("-k", "--key", dest="keyid", default=None, help="Specify the key ID to be used for signing.") +parser.add_option("-l", "--lpinstance", dest="lpinstance", default=None, + help="Launchpad instance to connect to (default: production)", + metavar="INSTANCE") +parser.add_option("--no-conf", dest="no_conf", default=False, + help="Don't read config files or environment variables.", + action="store_true") parser.add_option("-s", "--sponsor", help="sponsoring; equals -b -u ubuntu", dest="sponsoring", action="store_true", default=False) parser.add_option("-u", "--upload", dest="upload", default=None, @@ -57,8 +55,7 @@ parser.add_option("-U", "--update", dest="update", default=False, help="Update the build environment before building.") parser.add_option("-v", "--verbose", help="print more information", dest="verbose", action="store_true", default=False) -parser.add_option("-w", "--workdir", dest="workdir", - default=default_workdir, +parser.add_option("-w", "--workdir", dest="workdir", default=None, help="Specify a working directory.") (options, args) = parser.parse_args() @@ -78,6 +75,16 @@ else: Logger.error("Invalid bug number specified: %s" % (bug_number)) sys.exit(1) +config = UDTConfig(options.no_conf) +if options.builder is None: + options.builder = config.get_value("BUILDER") +if options.lpinstance is None: + options.lpinstance = config.get_value("LPINSTANCE") +if not options.update: + options.update = config.get_value("UPDATE_BUILDER", boolean=True) +if options.workdir is None: + options.workdir = config.get_value("WORKDIR") + builder = getBuilder(options.builder) if not builder: sys.exit(1) @@ -86,5 +93,20 @@ if options.sponsoring: options.build = True options.upload = "ubuntu" -main(bug_number, options.update, options.build, options.edit, options.keyid, - options.upload, options.workdir, builder, options.verbose) +if not options.upload and not options.workdir: + Logger.error("Please specify either a working directory or an upload " + "target!") + sys.exit(1) + +if options.workdir is None: + workdir = tempfile.mkdtemp(prefix=script_name+"-") +else: + workdir = options.workdir + +try: + main(bug_number, options.build, builder, options.edit, options.keyid, + options.lpinstance, options.update, options.upload, workdir, + options.verbose) +finally: + if options.workdir is None: + shutil.rmtree(workdir) diff --git a/ubuntutools/sponsor_patch/main.py b/ubuntutools/sponsor_patch/main.py index dce1477..1504f48 100644 --- a/ubuntutools/sponsor_patch/main.py +++ b/ubuntutools/sponsor_patch/main.py @@ -207,8 +207,8 @@ def apply_patch(task, patch): edit = True return edit -def main(bug_number, update, build, edit, keyid, upload, workdir, builder, - verbose=False): +def main(bug_number, build, builder, edit, keyid, lpinstance, update, upload, + workdir, verbose=False): workdir = os.path.expanduser(workdir) if not os.path.isdir(workdir): try: @@ -222,7 +222,7 @@ def main(bug_number, update, build, edit, keyid, upload, workdir, builder, os.chdir(workdir) lp = launchpadlib.launchpad.Launchpad.login_anonymously("sponsor-patch", - "production") + lpinstance) bug = lp.bugs[bug_number] (patch, branch) = get_patch_or_branch(bug)