diff --git a/backportpackage b/backportpackage index 3ec373a..1703c6e 100755 --- a/backportpackage +++ b/backportpackage @@ -25,6 +25,7 @@ import tempfile from debian.deb822 import Dsc import launchpadlib.launchpad +from ubuntutools.builder import getBuilder from ubuntutools.logger import Logger devnull = open('/dev/null', 'r+') @@ -43,10 +44,6 @@ def check_call(cmd, *args, **kwargs): def parse(args): usage = 'Usage: %prog [options] ' p = optparse.OptionParser(usage) - p.add_option('-u', '--upload', - dest='upload', - help='Specify an upload destination (required)', - metavar='UPLOAD') p.add_option('-t', '--to', dest='dest_releases', default=[], @@ -58,6 +55,20 @@ def parse(args): default=None, help='Backport from SOURCE release (default: devel release)', metavar='SOURCE') + p.add_option('-b', '--build', + dest='build', + default=False, + action='store_true', + help='Build the package before uploading (default: %default)') + p.add_option('-B', '--builder', + dest='builder', + default=None, + help='Specify the package builder (default: pbuilder)', + metavar='BUILDER') + p.add_option('-u', '--upload', + dest='upload', + help='Specify an upload destination', + metavar='UPLOAD') p.add_option('-v', '--version', dest='version', default=None, @@ -74,8 +85,6 @@ def parse(args): p.error('You must specify a source package') if not opts.dest_releases: p.error('You must specify at least one destination release') - if not opts.upload: - p.error('You must specify an upload destination') return opts, args @@ -143,16 +152,42 @@ def fetch_package(workdir, package, opts): def get_backport_version(version, upload, release): v = version + ('~%s1' % release) - if upload.startswith('ppa:'): + if upload and upload.startswith('ppa:'): v += '~ppa1' return v def get_backport_dist(upload, release): - if upload == 'ubuntu': + if not upload or upload == 'ubuntu': return '%s-backports' % release else: return release +def do_build(workdir, package, release, bp_version, opts): + builder = getBuilder(opts.builder) + if not builder: + return + + builder.build(os.path.join(workdir, + '%s_%s.dsc' % (package, bp_version)), + release, + workdir) + +def do_upload(workdir, package, bp_version, opts): + prompt = 'Do you want to upload this to %s? [Y/n]' % opts.upload + while True: + answer = raw_input(prompt).strip().lower() + if answer in ('', 'y', 'yes'): + break + elif answer in ('n', 'no'): + return + + check_call(['dput', + opts.upload, + '%s_%s_source.changes' % + (package, bp_version)], + cwd=workdir) + + def do_backport(workdir, package, dscfile, release, opts): dsc = Dsc(open(os.path.join(workdir, dscfile))) v = dsc['Version'] @@ -181,20 +216,12 @@ def do_backport(workdir, package, dscfile, release, opts): bp_version = bp_version[bp_version.find(':')+1:] print 'Please check the package in file://%s carefully' % workdir - prompt = 'Do you want to upload this to %s? [Y/n]' % opts.upload - while True: - answer = raw_input(prompt).strip().lower() - if answer in ('', 'y', 'yes'): - check_call(['dput', - opts.upload, - '%s_%s_source.changes' % - (package, bp_version)], - cwd=workdir) + if opts.build: + do_build(workdir, package, release, bp_version, opts) + if opts.upload: + do_upload(workdir, package, bp_version, opts) - break - elif answer in ('n', 'no'): - break - shutil.rmtree(srcdir) + shutil.rmtree(srcdir) def main(args): global lp diff --git a/doc/backportpackage.1 b/doc/backportpackage.1 index 0234a91..341beaf 100644 --- a/doc/backportpackage.1 +++ b/doc/backportpackage.1 @@ -13,22 +13,32 @@ backportpackage \- helper to test package backports .B backportpackage \-h .SH OPTIONS .TP -.BR \-u \fIUPLOAD\fR, \-\-upload=\fIUPLOAD\fR -\fBRequired\fR. Upload to \fIUPLOAD\fR with \fBdput\fR(1) (after -confirmation). -.TP -.BR \-t \fIDEST\fR, \-\-to=\fIDEST\fR +.B \-t \fIDEST\fR, \-\-to=\fIDEST\fR \fBRequired\fR. Backport the package to the specified Ubuntu release. This option may be specified multiple times, but must be specified at least once. .TP -.BR \-f \fISOURCE\fR, \-\-from=\fISOURCE\fR +.B \-f \fISOURCE\fR, \-\-from=\fISOURCE\fR Backport the package from the specified Ubuntu release. If neither this option nor \fB\-\-version\fR are specified, then \fBbackportpackage\fR defaults to the current Ubuntu development release. .TP -.BR \-v \fIVERSION\fR, \-\-version=\fIVERSION\fR +.B \-b, \-\-build +Build the package with the specified builder before uploading. Note +for \fBpbuilder\fR(8) users: This assumes the common configuration, +where the \fBDIST\fR environment is read by \fBpbuilderrc\fR(5) to +select the correct base image. +.TP +.B \-B \fIBUILDER\fR, \fB\-\-builder\fR=\fIBUILDER +Use the specified builder to build the package. Supported are +\fBpbuilder\fR(8) and \fBsbuild\fR(1). This overrides +\fBUBUNTUTOOLS_BUILDER\fR. The default is \fBpbuilder\fR(8). +.TP +.B \-u \fIUPLOAD\fR, \-\-upload=\fIUPLOAD\fR +Upload to \fIUPLOAD\fR with \fBdput\fR(1) (after confirmation). +.TP +.B \-v \fIVERSION\fR, \-\-version=\fIVERSION\fR If the \fB\-\-from\fR option is specified, then \fBbackportpackage\fR verifies that the current version of \fIsource package\fR in \fISOURCE\fR is the same as \fIVERSION\fR. Otherwise, @@ -36,19 +46,27 @@ verifies that the current version of \fIsource package\fR in package\fR, regardless of the release in which it was published (or if that version is still current). .TP -.BR \-l \fIINSTANCE\fR, \-\-launchpad=\fIINSTANCE\fR +.B \-l \fIINSTANCE\fR, \-\-launchpad=\fIINSTANCE\fR Use the specified instance of Launchpad (e.g. "staging"), instead of the default of "production". .SH DESCRIPTION \fBbackportpackage\fR fetches a package from one Ubuntu release and creates a no-change backport of that package to a previous release, -uploading the resulting backport for testing. +optionally doing a test build of the package and/or uploading the +resulting backport for testing. .PP The backported package is fetched and built in a temporary directory in \fB/tmp\fR, which is removed once the script finishes running. .PP \fBbackportpackage\fR is only recommended for testing backports in a PPA, not uploading backports to the Ubuntu archive. +.SH ENVIRONMENT +.TP +.B UBUNTUTOOLS_BUILDER +The default builder for Ubuntu development tools that support it +(including \fBbackportpackage\fR. Supported are \fBpbuilder\fR(8) and +\fBsbuild\fR(1). If unset and not provided on the command line, +\fBpbuilder\fR(8) is used. .SH AUTHOR \fBbackportpackage\fR and this manpage were written by Evan Broder