sponsor-patch: Add new --lpinstance and --no-conf options and support

configuration files.
This commit is contained in:
Benjamin Drung 2010-12-21 21:42:32 +01:00
parent 9bf33b330b
commit 41cc2fa194
4 changed files with 85 additions and 45 deletions

6
debian/changelog vendored
View File

@ -22,7 +22,11 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low
* ubuntutools/lp/lpapicache.py: Allow easier selection of 'staging' as LP * ubuntutools/lp/lpapicache.py: Allow easier selection of 'staging' as LP
instance to use (lp: #693060). instance to use (lp: #693060).
-- Michael Bienia <geser@ubuntu.com> 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 <bdrung@ubuntu.com> Tue, 21 Dec 2010 21:39:54 +0100
ubuntu-dev-tools (0.108) experimental; urgency=low ubuntu-dev-tools (0.108) experimental; urgency=low

View File

@ -45,11 +45,11 @@ The changelog timestamp is touched.
.PP .PP
Should any checks (or the build fail), the user has an option to edit Should any checks (or the build fail), the user has an option to edit
the patched source and try building it again. the patched source and try building it again.
.PP
The sources and patches will be downloaded into the working directory Unless a working directory is specified, the sources and patches will be
(which defaults to the current directory). downloaded into a temporary directory in \fB/tmp\fR, which is removed once the
The output of the build tool will be placed in script finishes running.
\fIworkdir\fR/\fIsourcepkg\fB\-buildresult/\fR. The output of the build tool will be placed in \fIworkdir\fR/\fBbuildresult/\fR.
.SH OPTIONS .SH OPTIONS
.TP .TP
@ -61,16 +61,26 @@ by \fBpbuilderrc\fR(5) to select the correct base image.
.B \-B \fIBUILDER\fR, \fB\-\-builder\fR=\fIBUILDER .B \-B \fIBUILDER\fR, \fB\-\-builder\fR=\fIBUILDER
Use the specify builder to build the package. Use the specify builder to build the package.
Supported are \fBpbuilder\fR(8), \fBpbuilder-dist\fR(1), and \fBsbuild\fR(1). 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). The default is \fBpbuilder\fR(8).
.TP .TP
.BR \-e ", " \-\-edit .BR \-e ", " \-\-edit
Launch a sub-shell to allow editing of the patched source before Launch a sub-shell to allow editing of the patched source before
building. building.
.TP .TP
.BR \-h ", " \-\-help
Display a help message and exit.
.TP
.B \-k \fIKEY\fR, \fB\-\-key\fR=\fIKEY .B \-k \fIKEY\fR, \fB\-\-key\fR=\fIKEY
Specify a key ID for signing the upload. Specify a key ID for signing the upload.
.TP .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 .BR \-s ", " \-\-sponsor
Shortcut for sponsored uploads. Equivalent to \fB\-b \-u ubuntu\fR. Shortcut for sponsored uploads. Equivalent to \fB\-b \-u ubuntu\fR.
.TP .TP
@ -84,30 +94,33 @@ Update the build environment before attempting to build.
Print more information. Print more information.
.TP .TP
.B \-w \fIDIR\fR, \fB\-\-workdir\fR=\fIDIR .B \-w \fIDIR\fR, \fB\-\-workdir\fR=\fIDIR
Use the specified working directory, creating it if necessary, instead Use the specified working directory, creating it if necessary.
of the current directory. This overrides \fBSPONSOR_PATCH_WORKDIR\fR. If \fIWORKDIR\fR is not specified, a temporary directory is created, which is
.TP deleted before \fIsponsor-patch\fR exits.
.BR \-h ", " \-\-help
Display a help message and exit.
.SH ENVIRONMENT .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 .TP
.B UBUNTUTOOLS_BUILDER .BR SPONSOR_PATCH_BUILDER ", " UBUNTUTOOLS_BUILDER
The default builder for Ubuntu development tools that support it (including The default value for \fB\-\-builder\fR.
\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.
.TP .TP
.B SPONSOR_PATCH_BUILDER .BR SPONSOR_PATCH_LPINSTANCE ", " UBUNTUTOOLS_LPINSTANCE
The default builder for \fBsponsor\-patch\fR. The default value for \fB--lpinstance\fR.
If specified, this overrides \fBUBUNTUTOOLS_BUILDER\fR.
.TP .TP
.B SPONSOR_PATCH_WORKDIR .BR SPONSOR_PATCH_UPDATE_BUILDER ", " UBUNTUTOOLS_UPDATE_BUILDER
The default working directory for \fBsponsor\-patch\fR. If unset and not The default value for \fB--update\fR.
provided on the command line, the current directory is used. .TP
.BR SPONSOR_PATCH_WORKDIR ", " UBUNTUTOOLS_WORKDIR
The default value for \fB--workdir\fR.
.SH EXAMPLES .SH EXAMPLES
Test-building and sponsoring an upload of bug \fB1234\fR: 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 (8),
.BR pbuilder-dist (1), .BR pbuilder-dist (1),
.BR sbuild (1), .BR sbuild (1),
.BR ubuntu\-dev\-tools (5)
.BR update\-maintainer (1) .BR update\-maintainer (1)
.SH AUTHORS .SH AUTHORS

View File

@ -16,8 +16,11 @@
import optparse import optparse
import os import os
import shutil
import sys import sys
import tempfile
from ubuntutools.config import UDTConfig
from ubuntutools.builder import getBuilder from ubuntutools.builder import getBuilder
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.sponsor_patch.main import main from ubuntutools.sponsor_patch.main import main
@ -27,27 +30,22 @@ usage = "%s [options] <bug number>" % (script_name)
epilog = "See %s(1) for more info." % (script_name) epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog) 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", parser.add_option("-b", "--build", dest="build",
help="Build the package with the specified builder.", help="Build the package with the specified builder.",
action="store_true", default=False) action="store_true", default=False)
parser.add_option("-B", "--builder", dest="builder", parser.add_option("-B", "--builder", dest="builder", default=None,
help="Specify the package builder (default pbuilder)", help="Specify the package builder (default pbuilder)")
default=default_builder)
parser.add_option("-e", "--edit", parser.add_option("-e", "--edit",
help="launch sub-shell to allow editing of the patch", help="launch sub-shell to allow editing of the patch",
dest="edit", action="store_true", default=False) dest="edit", action="store_true", default=False)
parser.add_option("-k", "--key", dest="keyid", default=None, parser.add_option("-k", "--key", dest="keyid", default=None,
help="Specify the key ID to be used for signing.") 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", parser.add_option("-s", "--sponsor", help="sponsoring; equals -b -u ubuntu",
dest="sponsoring", action="store_true", default=False) dest="sponsoring", action="store_true", default=False)
parser.add_option("-u", "--upload", dest="upload", default=None, 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.") help="Update the build environment before building.")
parser.add_option("-v", "--verbose", help="print more information", parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False) dest="verbose", action="store_true", default=False)
parser.add_option("-w", "--workdir", dest="workdir", parser.add_option("-w", "--workdir", dest="workdir", default=None,
default=default_workdir,
help="Specify a working directory.") help="Specify a working directory.")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -78,6 +75,16 @@ else:
Logger.error("Invalid bug number specified: %s" % (bug_number)) Logger.error("Invalid bug number specified: %s" % (bug_number))
sys.exit(1) 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) builder = getBuilder(options.builder)
if not builder: if not builder:
sys.exit(1) sys.exit(1)
@ -86,5 +93,20 @@ if options.sponsoring:
options.build = True options.build = True
options.upload = "ubuntu" options.upload = "ubuntu"
main(bug_number, options.update, options.build, options.edit, options.keyid, if not options.upload and not options.workdir:
options.upload, options.workdir, builder, options.verbose) 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)

View File

@ -207,8 +207,8 @@ def apply_patch(task, patch):
edit = True edit = True
return edit return edit
def main(bug_number, update, build, edit, keyid, upload, workdir, builder, def main(bug_number, build, builder, edit, keyid, lpinstance, update, upload,
verbose=False): workdir, verbose=False):
workdir = os.path.expanduser(workdir) workdir = os.path.expanduser(workdir)
if not os.path.isdir(workdir): if not os.path.isdir(workdir):
try: try:
@ -222,7 +222,7 @@ def main(bug_number, update, build, edit, keyid, upload, workdir, builder,
os.chdir(workdir) os.chdir(workdir)
lp = launchpadlib.launchpad.Launchpad.login_anonymously("sponsor-patch", lp = launchpadlib.launchpad.Launchpad.login_anonymously("sponsor-patch",
"production") lpinstance)
bug = lp.bugs[bug_number] bug = lp.bugs[bug_number]
(patch, branch) = get_patch_or_branch(bug) (patch, branch) = get_patch_or_branch(bug)