mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-03 23:44:19 +00:00 
			
		
		
		
	Add mirror support to pull-lp-source
This commit is contained in:
		
							parent
							
								
									088341fa7c
								
							
						
					
					
						commit
						0d51908f40
					
				@ -78,6 +78,8 @@ The default value for \fB\-\-debian\-mirror\fR.
 | 
			
		||||
The default value for \fB\-\-debsec\-mirror\fR.
 | 
			
		||||
 | 
			
		||||
.SH SEE ALSO
 | 
			
		||||
.BR debdiff (1),
 | 
			
		||||
.BR dget (1),
 | 
			
		||||
.BR pull\-debian\-source (1),
 | 
			
		||||
.BR ubuntu\-dev\-tools (5)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -52,6 +52,9 @@ package\-wide variable.
 | 
			
		||||
The default value for \fB\-\-mirror\fR.
 | 
			
		||||
 | 
			
		||||
.SH SEE ALSO
 | 
			
		||||
.BR dget (1),
 | 
			
		||||
.BR pull\-debian\-debdiff (1),
 | 
			
		||||
.BR pull\-lp\-source (1),
 | 
			
		||||
.BR ubuntu\-dev\-tools (5)
 | 
			
		||||
 | 
			
		||||
.SH AUTHOR
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
pull\-lp\-source \- download a source package from Launchpad
 | 
			
		||||
 | 
			
		||||
.SH SYNOPSIS
 | 
			
		||||
.B pull\-lp\-source \fR[\fB\-h\fR]\fB <\fBsource package\fR> [\fItarget release\fR]
 | 
			
		||||
.B pull\-lp\-source \fR[\fIoptions\fR]\fB <\fBsource package\fR> [\fItarget release\fR]
 | 
			
		||||
 | 
			
		||||
.SH DESCRIPTION
 | 
			
		||||
\fBpull\-lp\-source\fR downloads and extracts the latest version of
 | 
			
		||||
@ -15,21 +15,52 @@ version in that release will be downloaded instead.
 | 
			
		||||
.SH OPTIONS
 | 
			
		||||
Listed below are the command line options for pull\-lp\-source:
 | 
			
		||||
.TP
 | 
			
		||||
.B \-h, \-\-help
 | 
			
		||||
Display a help message and exit.
 | 
			
		||||
.TP
 | 
			
		||||
.B <source package>
 | 
			
		||||
This is the source package that you would like to be downloaded from Launchpad.
 | 
			
		||||
.TP
 | 
			
		||||
.B [target release]
 | 
			
		||||
This is the release that you would like the source package to be downloaded from.
 | 
			
		||||
This value defaults to the current development release.
 | 
			
		||||
 | 
			
		||||
.SH ENVIRONMENT VARIABLES
 | 
			
		||||
.TP
 | 
			
		||||
.BR \-h ", " \-\-help
 | 
			
		||||
Display a help message and exit.
 | 
			
		||||
.TP
 | 
			
		||||
.B \-m \fIUBUNTU_MIRROR\fR, \fB\-\-mirror\fR=\fIUBUNTU_MIRROR\fR
 | 
			
		||||
Use the specified Ubuntu mirror.
 | 
			
		||||
Should be in the form \fBhttp://archive.ubuntu.com/ubuntu\fR.
 | 
			
		||||
If the package isn't found on this mirror, \fBpull\-lp\-source\fR will
 | 
			
		||||
fall back to Launchpad, as its name implies.
 | 
			
		||||
.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.
 | 
			
		||||
.TP
 | 
			
		||||
.B
 | 
			
		||||
DIST
 | 
			
		||||
Specifies the default target.
 | 
			
		||||
 | 
			
		||||
.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 PULL_LP_SOURCE_UBUNTU_MIRROR ", " UBUNTUTOOLS_UBUNTU_MIRROR
 | 
			
		||||
The default value for \fB\-\-mirror\fR.
 | 
			
		||||
 | 
			
		||||
.SH SEE ALSO
 | 
			
		||||
.BR dget (1),
 | 
			
		||||
.BR pull\-debian\-source (1),
 | 
			
		||||
.BR pull\-debian\-debdiff (1),
 | 
			
		||||
.BR ubuntu\-dev\-tools (5)
 | 
			
		||||
 | 
			
		||||
.SH AUTHOR
 | 
			
		||||
.PP
 | 
			
		||||
\fBpull\-lp\-source\fR and this manual page were written by Iain Lane
 | 
			
		||||
 | 
			
		||||
@ -32,35 +32,24 @@ except ImportError:
 | 
			
		||||
 | 
			
		||||
from ubuntutools.config import UDTConfig
 | 
			
		||||
from ubuntutools.logger import Logger
 | 
			
		||||
from ubuntutools.misc import dsc_name, dsc_url
 | 
			
		||||
 | 
			
		||||
DEFAULT_DEBIAN_MIRROR = 'http://ftp.debian.org/debian'
 | 
			
		||||
DEFAULT_DEBSEC_MIRROR = 'http://security.debian.org'
 | 
			
		||||
 | 
			
		||||
opts = None
 | 
			
		||||
 | 
			
		||||
def dsc_name(package, version):
 | 
			
		||||
    "Return the source package dsc filename for the given package"
 | 
			
		||||
    if ':' in version:
 | 
			
		||||
        version = version.split(':', 1)[1]
 | 
			
		||||
    return '%s_%s.dsc' % (package, version)
 | 
			
		||||
 | 
			
		||||
def build_url(mirror, package, version):
 | 
			
		||||
    "Build a source package URL"
 | 
			
		||||
    group = package[:4] if package.startswith('lib') else package[0]
 | 
			
		||||
    fn = dsc_name(package, version)
 | 
			
		||||
    # TODO: Not all packages are main :)
 | 
			
		||||
    # Practically this is fine, as it'll be found on snapshot, but still ugly.
 | 
			
		||||
    return os.path.join(mirror, 'pool', 'main', group, package, fn)
 | 
			
		||||
 | 
			
		||||
def pull(package, version, unpack=False):
 | 
			
		||||
    "Download Debian source package version version"
 | 
			
		||||
    urls = []
 | 
			
		||||
    # TODO: Not all packages are main :)
 | 
			
		||||
    # Practically this is fine, as it'll be found on snapshot, but still ugly.
 | 
			
		||||
    if opts.debsec_mirror and opts.debsec_mirror != DEFAULT_DEBSEC_MIRROR:
 | 
			
		||||
        urls.append(build_url(opts.debsec_mirror, package, version))
 | 
			
		||||
    urls.append(build_url(DEFAULT_DEBSEC_MIRROR, package, version))
 | 
			
		||||
        urls.append(dsc_url(opts.debsec_mirror, 'main', package, version))
 | 
			
		||||
    urls.append(dsc_url(DEFAULT_DEBSEC_MIRROR, 'main', package, version))
 | 
			
		||||
    if opts.debian_mirror and opts.debian_mirror != DEFAULT_DEBIAN_MIRROR:
 | 
			
		||||
        urls.append(build_url(opts.debian_mirror, package, version))
 | 
			
		||||
    urls.append(build_url(DEFAULT_DEBIAN_MIRROR, package, version))
 | 
			
		||||
        urls.append(dsc_url(opts.debian_mirror, 'main', package, version))
 | 
			
		||||
    urls.append(dsc_url(DEFAULT_DEBIAN_MIRROR, 'main', package, version))
 | 
			
		||||
 | 
			
		||||
    for url in urls:
 | 
			
		||||
        cmd = ('dget', '-u' + 'x' if unpack else 'd', url)
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,8 @@
 | 
			
		||||
# pull-lp-source -- pull a source package from Launchpad
 | 
			
		||||
# Basic usage: pull-lp-source <source package> [<release>]
 | 
			
		||||
#
 | 
			
		||||
# Copyright (C) 2008 Iain Lane <iain@orangesquash.org.uk>
 | 
			
		||||
#
 | 
			
		||||
# BackportFromLP class taken from prevu tool, which is:
 | 
			
		||||
# Copyright (C) 2006 John Dong <jdong@ubuntu.com>
 | 
			
		||||
# Copyright (C) 2008, Iain Lane <iain@orangesquash.org.uk>,
 | 
			
		||||
#               2010, Stefano Rivera <stefanor@ubuntu.com>
 | 
			
		||||
#
 | 
			
		||||
# ##################################################################
 | 
			
		||||
#
 | 
			
		||||
@ -31,25 +29,36 @@ import subprocess
 | 
			
		||||
import urllib
 | 
			
		||||
from optparse import OptionParser
 | 
			
		||||
 | 
			
		||||
# ubuntu-dev-tools modules.
 | 
			
		||||
from ubuntutools.config import UDTConfig
 | 
			
		||||
from ubuntutools.logger import Logger
 | 
			
		||||
from ubuntutools.lp.lpapicache import Distribution, Launchpad
 | 
			
		||||
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
 | 
			
		||||
        PackageNotFoundException, PocketDoesNotExistError)
 | 
			
		||||
from ubuntutools.misc import splitReleasePocket
 | 
			
		||||
from ubuntutools.misc import splitReleasePocket, dsc_name, dsc_url
 | 
			
		||||
 | 
			
		||||
if not os.path.exists("/usr/bin/dget"):
 | 
			
		||||
    print "E: dget is not installed - please install the 'devscripts' package" \
 | 
			
		||||
        " and rerun this script again."
 | 
			
		||||
    print ("E: dget is not installed - please install the 'devscripts' package"
 | 
			
		||||
           " and rerun this script again.")
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    usage = "Usage: %prog <package> [release]"
 | 
			
		||||
    optParser = OptionParser(usage)
 | 
			
		||||
    optParser.add_option('-m', '--mirror', metavar='UBUNTU_MIRROR',
 | 
			
		||||
                         dest='ubuntu_mirror',
 | 
			
		||||
                         help='Preferred Ubuntu mirror '
 | 
			
		||||
                              '(default: Launchpad)')
 | 
			
		||||
    optParser.add_option('--no-conf',
 | 
			
		||||
                         dest='no_conf', default=False, action='store_true',
 | 
			
		||||
                         help="Don't read config files or environment "
 | 
			
		||||
                              "variables")
 | 
			
		||||
    (options, args) = optParser.parse_args()
 | 
			
		||||
 | 
			
		||||
    if not args:
 | 
			
		||||
        optParser.print_help()
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
        optParser.error("Must specify package name")
 | 
			
		||||
 | 
			
		||||
    config = UDTConfig(options.no_conf)
 | 
			
		||||
    if options.ubuntu_mirror is None:
 | 
			
		||||
        options.ubuntu_mirror = config.get_value('UBUNTU_MIRROR')
 | 
			
		||||
 | 
			
		||||
    # Login anonymously to LP
 | 
			
		||||
    Launchpad.login_anonymously()
 | 
			
		||||
@ -73,6 +82,16 @@ if __name__ == '__main__':
 | 
			
		||||
        print 'E: %s' % e
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
 | 
			
		||||
    if options.ubuntu_mirror:
 | 
			
		||||
        url = dsc_url(options.ubuntu_mirror, spph.getComponent(), package,
 | 
			
		||||
                      spph.getVersion())
 | 
			
		||||
        cmd = ('dget', '-xu', url)
 | 
			
		||||
        Logger.command(cmd)
 | 
			
		||||
        r = subprocess.call(cmd)
 | 
			
		||||
        if r == 0:
 | 
			
		||||
            Logger.normal("Success!")
 | 
			
		||||
            sys.exit(0)
 | 
			
		||||
 | 
			
		||||
    dsc_url = [url for url in spph.sourceFileUrls() if url.endswith('.dsc')]
 | 
			
		||||
    assert dsc_url, 'No .dsc file found'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,9 @@
 | 
			
		||||
#
 | 
			
		||||
# misc.py - misc functions for the Ubuntu Developer Tools scripts.
 | 
			
		||||
#
 | 
			
		||||
# Copyright (C) 2008 Jonathan Davies <jpds@ubuntu.com>
 | 
			
		||||
# Copyright (C) 2008-2009 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
 | 
			
		||||
# Copyright (C) 2008,      Jonathan Davies <jpds@ubuntu.com>,
 | 
			
		||||
#               2008-2009, Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>,
 | 
			
		||||
#               2010,      Stefano Rivera <stefanor@ubuntu.com>
 | 
			
		||||
#
 | 
			
		||||
# ##################################################################
 | 
			
		||||
#
 | 
			
		||||
@ -22,6 +23,7 @@
 | 
			
		||||
 | 
			
		||||
# Modules.
 | 
			
		||||
import os
 | 
			
		||||
import os.path
 | 
			
		||||
from subprocess import Popen, PIPE
 | 
			
		||||
 | 
			
		||||
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
 | 
			
		||||
@ -116,3 +118,15 @@ def splitReleasePocket(release):
 | 
			
		||||
                                          pocket)
 | 
			
		||||
 | 
			
		||||
    return (release, pocket)
 | 
			
		||||
 | 
			
		||||
def dsc_name(package, version):
 | 
			
		||||
    "Return the source package dsc filename for the given package"
 | 
			
		||||
    if ':' in version:
 | 
			
		||||
        version = version.split(':', 1)[1]
 | 
			
		||||
    return '%s_%s.dsc' % (package, version)
 | 
			
		||||
 | 
			
		||||
def dsc_url(mirror, component, package, version):
 | 
			
		||||
    "Build a source package URL"
 | 
			
		||||
    group = package[:4] if package.startswith('lib') else package[0]
 | 
			
		||||
    fn = dsc_name(package, version)
 | 
			
		||||
    return os.path.join(mirror, 'pool', component, group, package, fn)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user