mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 07:54:03 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			87 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python
 | 
						|
#
 | 
						|
# 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>
 | 
						|
#
 | 
						|
# ##################################################################
 | 
						|
#
 | 
						|
# This program is free software; you can redistribute it and/or
 | 
						|
# modify it under the terms of the GNU General Public License
 | 
						|
# as published by the Free Software Foundation; either version 3
 | 
						|
# of the License, or (at your option) any later version.
 | 
						|
#
 | 
						|
# This program is distributed in the hope that it will be useful,
 | 
						|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
# GNU General Public License for more details.
 | 
						|
#
 | 
						|
# See file /usr/share/common-licenses/GPL for more details.
 | 
						|
#
 | 
						|
# ##################################################################
 | 
						|
 | 
						|
 | 
						|
import os
 | 
						|
import sys
 | 
						|
import subprocess
 | 
						|
import urllib
 | 
						|
from optparse import OptionParser
 | 
						|
 | 
						|
# ubuntu-dev-tools modules.
 | 
						|
from ubuntutools.lp.lpapicache import Distribution, Launchpad
 | 
						|
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
 | 
						|
        PackageNotFoundException, PocketDoesNotExistError)
 | 
						|
from ubuntutools.misc import splitReleasePocket
 | 
						|
 | 
						|
if not os.path.exists("/usr/bin/dget"):
 | 
						|
    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)
 | 
						|
    (options, args) = optParser.parse_args()
 | 
						|
 | 
						|
    if not args:
 | 
						|
        optParser.print_help()
 | 
						|
        sys.exit(1)
 | 
						|
 | 
						|
    # Login anonymously to LP
 | 
						|
    Launchpad.login_anonymously()
 | 
						|
 | 
						|
    package = str(args[0]).lower()
 | 
						|
 | 
						|
    if len(args) >= 2: # Custom distribution specified.
 | 
						|
        release = str(args[1]).lower()
 | 
						|
    else:
 | 
						|
        release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name
 | 
						|
 | 
						|
    try:
 | 
						|
        (release, pocket) = splitReleasePocket(release)
 | 
						|
    except PocketDoesNotExistError, e:
 | 
						|
        print 'E: %s' % e
 | 
						|
        sys.exit(1)
 | 
						|
 | 
						|
    try:
 | 
						|
        spph = Distribution('ubuntu').getArchive().getSourcePackage(package, release, pocket)
 | 
						|
    except (SeriesNotFoundException, PackageNotFoundException), e:
 | 
						|
        print 'E: %s' % e
 | 
						|
        sys.exit(1)
 | 
						|
 | 
						|
    dsc_url = [url for url in spph.sourceFileUrls() if url.endswith('.dsc')]
 | 
						|
    assert dsc_url, 'No .dsc file found'
 | 
						|
 | 
						|
    # All good - start downloading...
 | 
						|
    print 'Fetching the source for %s from %s (%s)...' % (
 | 
						|
            package, release.capitalize(), pocket)
 | 
						|
    if subprocess.call(['/usr/bin/dget', '-xu', urllib.unquote(dsc_url[0])]) == 0:
 | 
						|
        print 'Success!'
 | 
						|
    else:
 | 
						|
        print 'Failed to fetch and extrace the source.', \
 | 
						|
                'Please check the output for the error.'
 |