mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 07:54:03 +00:00 
			
		
		
		
	backportpackage: Accept a URL or path to a .dsc file as an alternative to a source package name
This commit is contained in:
		
							parent
							
								
									2585452cbb
								
							
						
					
					
						commit
						b50fbb7750
					
				@ -41,7 +41,7 @@ def check_call(cmd, *args, **kwargs):
 | 
			
		||||
        error('%s returned %d' % (cmd, ret))
 | 
			
		||||
 | 
			
		||||
def parse(args):
 | 
			
		||||
    usage = 'Usage: %prog [options] <source package>'
 | 
			
		||||
    usage = 'Usage: %prog [options] <source package name or .dsc URL/file>'
 | 
			
		||||
    p = optparse.OptionParser(usage)
 | 
			
		||||
    p.add_option('-d', '--destination',
 | 
			
		||||
                 dest='dest_releases',
 | 
			
		||||
@ -86,7 +86,7 @@ def parse(args):
 | 
			
		||||
 | 
			
		||||
    opts, args = p.parse_args(args)
 | 
			
		||||
    if len(args) != 1:
 | 
			
		||||
        p.error('You must specify a source package')
 | 
			
		||||
        p.error('You must specify a single source package or a .dsc URL/path')
 | 
			
		||||
    if not opts.upload and not opts.build:
 | 
			
		||||
        p.error('Nothing to do')
 | 
			
		||||
 | 
			
		||||
@ -129,9 +129,7 @@ def find_version_package(lp, package, version):
 | 
			
		||||
        error('Version %s of package %s was never published in Ubuntu' %
 | 
			
		||||
              (version, package))
 | 
			
		||||
 | 
			
		||||
def fetch_package(lp, workdir, package, version, source_release):
 | 
			
		||||
    # Returns the path to the .dsc file that was fetched
 | 
			
		||||
 | 
			
		||||
def dscurl_from_package(lp, workdir, package, version, source_release):
 | 
			
		||||
    if not source_release and not version:
 | 
			
		||||
        source_release = lp.distributions['ubuntu'].current_series.name
 | 
			
		||||
 | 
			
		||||
@ -144,15 +142,34 @@ def fetch_package(lp, workdir, package, version, source_release):
 | 
			
		||||
 | 
			
		||||
    for f in srcpkg.sourceFileUrls():
 | 
			
		||||
        if f.endswith('.dsc'):
 | 
			
		||||
            check_call(['dget',
 | 
			
		||||
                        '--download-only',
 | 
			
		||||
                        '--allow-unauthenticated',
 | 
			
		||||
                        urllib.unquote(f)],
 | 
			
		||||
                       cwd=workdir)
 | 
			
		||||
            return os.path.join(workdir, os.path.basename(f))
 | 
			
		||||
            return urllib.unquote(f)
 | 
			
		||||
    else:
 | 
			
		||||
        error('Package %s contains no .dsc file' % package)
 | 
			
		||||
 | 
			
		||||
def dscurl_from_dsc(package):
 | 
			
		||||
    path = os.path.abspath(os.path.expanduser(package))
 | 
			
		||||
    if os.path.exists(path):
 | 
			
		||||
        return 'file://%s' % path
 | 
			
		||||
    else:
 | 
			
		||||
        # Can't resolve it as a local path? Let's just hope it's good
 | 
			
		||||
        # as-is
 | 
			
		||||
        return package
 | 
			
		||||
 | 
			
		||||
def fetch_package(lp, workdir, package, version, source_release):
 | 
			
		||||
    # Returns the path to the .dsc file that was fetched
 | 
			
		||||
 | 
			
		||||
    if package.endswith('.dsc'):
 | 
			
		||||
        dsc = dscurl_from_dsc(package)
 | 
			
		||||
    else:
 | 
			
		||||
        dsc = dscurl_from_package(lp, workdir, package, version, source_release)
 | 
			
		||||
 | 
			
		||||
    check_call(['dget',
 | 
			
		||||
                '--download-only',
 | 
			
		||||
                '--allow-unauthenticated',
 | 
			
		||||
                dsc],
 | 
			
		||||
               cwd=workdir)
 | 
			
		||||
    return os.path.join(workdir, os.path.basename(dsc))
 | 
			
		||||
 | 
			
		||||
def get_backport_version(version, upload, release):
 | 
			
		||||
    v = version + ('~%s1' % release)
 | 
			
		||||
    if upload and upload.startswith('ppa:'):
 | 
			
		||||
@ -191,10 +208,7 @@ def do_upload(workdir, package, bp_version, upload):
 | 
			
		||||
               cwd=workdir)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def do_backport(workdir, package, dscfile, release, build, builder, upload):
 | 
			
		||||
    dsc = Dsc(open(os.path.join(workdir, dscfile)))
 | 
			
		||||
    v = dsc['Version']
 | 
			
		||||
 | 
			
		||||
def do_backport(workdir, package, dscfile, version, release, build, builder, upload):
 | 
			
		||||
    check_call(['dpkg-source',
 | 
			
		||||
                '-x',
 | 
			
		||||
                dscfile,
 | 
			
		||||
@ -202,7 +216,7 @@ def do_backport(workdir, package, dscfile, release, build, builder, upload):
 | 
			
		||||
               cwd=workdir)
 | 
			
		||||
    srcdir = os.path.join(workdir, package)
 | 
			
		||||
 | 
			
		||||
    bp_version = get_backport_version(v, upload, release)
 | 
			
		||||
    bp_version = get_backport_version(version, upload, release)
 | 
			
		||||
    bp_dist = get_backport_dist(upload, release)
 | 
			
		||||
 | 
			
		||||
    check_call(['dch',
 | 
			
		||||
@ -230,7 +244,7 @@ def do_backport(workdir, package, dscfile, release, build, builder, upload):
 | 
			
		||||
def main(args):
 | 
			
		||||
    os.environ['DEB_VENDOR'] = 'Ubuntu'
 | 
			
		||||
 | 
			
		||||
    opts, (package,) = parse(args[1:])
 | 
			
		||||
    opts, (package_or_dsc,) = parse(args[1:])
 | 
			
		||||
 | 
			
		||||
    script_name = os.path.basename(sys.argv[0])
 | 
			
		||||
    lp = launchpadlib.launchpad.Launchpad.login_anonymously(script_name,
 | 
			
		||||
@ -254,14 +268,19 @@ def main(args):
 | 
			
		||||
    try:
 | 
			
		||||
        dscfile = fetch_package(lp,
 | 
			
		||||
                                workdir,
 | 
			
		||||
                                package,
 | 
			
		||||
                                package_or_dsc,
 | 
			
		||||
                                opts.version,
 | 
			
		||||
                                opts.source_release)
 | 
			
		||||
 | 
			
		||||
        dsc = Dsc(open(os.path.join(workdir, dscfile)))
 | 
			
		||||
        package = dsc['Source']
 | 
			
		||||
        version = dsc['Version']
 | 
			
		||||
 | 
			
		||||
        for release in opts.dest_releases:
 | 
			
		||||
            do_backport(workdir,
 | 
			
		||||
                        package,
 | 
			
		||||
                        dscfile,
 | 
			
		||||
                        version,
 | 
			
		||||
                        release,
 | 
			
		||||
                        opts.build,
 | 
			
		||||
                        opts.builder,
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ backportpackage \- helper to test package backports
 | 
			
		||||
.B backportpackage \fR[\fIadditional options\fR]
 | 
			
		||||
\-\-upload <\fIupload target\fR>
 | 
			
		||||
.br
 | 
			
		||||
<\fIsource package\fR>
 | 
			
		||||
<\fIsource package name or .dsc URL/file\fR>
 | 
			
		||||
.PP
 | 
			
		||||
.B backportpackage \-h
 | 
			
		||||
.SH OPTIONS
 | 
			
		||||
@ -42,7 +42,8 @@ If the \fB\-\-source\fR option is specified, then
 | 
			
		||||
package\fR in \fISOURCE\fR is the same as \fIVERSION\fR. Otherwise,
 | 
			
		||||
\fBbackportpackage\fR finds version \fIVERSION\fR of \fIsource
 | 
			
		||||
package\fR, regardless of the release in which it was published (or if
 | 
			
		||||
that version is still current).
 | 
			
		||||
that version is still current). This option is ignored if a .dsc URL
 | 
			
		||||
or path is passed in instead of a source package name.
 | 
			
		||||
.TP
 | 
			
		||||
.B \-w \fIWORKDIR\fR, \-\-workdir=\fIWORKDIR\fR
 | 
			
		||||
If \fIWORKDIR\fR is specified, then all files are downloaded,
 | 
			
		||||
@ -54,13 +55,14 @@ deleted before \fIbackportpackage\fR exits.
 | 
			
		||||
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,
 | 
			
		||||
optionally doing a test build of the package and/or uploading the
 | 
			
		||||
resulting backport for testing.
 | 
			
		||||
\fBbackportpackage\fR fetches a package from one Ubuntu release or
 | 
			
		||||
from a specified .dsc path or URL and creates a no-change backport of
 | 
			
		||||
that package to a previous release, 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.
 | 
			
		||||
Unless a working directory is specified, 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.
 | 
			
		||||
@ -68,7 +70,7 @@ PPA, not uploading backports to the Ubuntu archive.
 | 
			
		||||
.TP
 | 
			
		||||
.B UBUNTUTOOLS_BUILDER
 | 
			
		||||
The default builder for Ubuntu development tools that support it
 | 
			
		||||
(including \fBbackportpackage\fR. Supported are \fBpbuilder\fR(8) and
 | 
			
		||||
(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 EXAMPLES
 | 
			
		||||
@ -85,7 +87,16 @@ test-build both locally, leaving all build products in the current
 | 
			
		||||
working directory:
 | 
			
		||||
.IP
 | 
			
		||||
.nf
 | 
			
		||||
.B backportpackage -b -s maverick -d karmic -d lucid -w . squashfs-tools
 | 
			
		||||
.B backportpackage -b -s maverick -d karmic -d lucid -w . \\\\
 | 
			
		||||
.B "  "squashfs-tools
 | 
			
		||||
.fi
 | 
			
		||||
.PP
 | 
			
		||||
Fetch a package from a PPA, backport it to Hardy, then upload it back
 | 
			
		||||
to the same PPA:
 | 
			
		||||
.IP
 | 
			
		||||
.nf
 | 
			
		||||
.B backportpackage -d hardy -u ppa:\fIuser\fR/\fIppa\fR \\\\
 | 
			
		||||
.B "  "https://launchpad.net/\fIsome/file.dsc\fR
 | 
			
		||||
.fi
 | 
			
		||||
.SH AUTHOR
 | 
			
		||||
\fBbackportpackage\fR and this manpage were written by Evan Broder
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user