2008-07-03 17:37:57 +01:00
|
|
|
#!/usr/bin/python
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
2008-07-03 17:37:57 +01:00
|
|
|
# pull-lp-source -- pull a source package from Launchpad
|
2008-08-11 19:24:39 +01:00
|
|
|
# Basic usage: pull-lp-source <source package> [<release>]
|
2008-07-03 17:37:57 +01:00
|
|
|
#
|
2010-12-24 12:00:03 +02:00
|
|
|
# Copyright (C) 2008, Iain Lane <iain@orangesquash.org.uk>,
|
|
|
|
# 2010, Stefano Rivera <stefanor@ubuntu.com>
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
|
|
|
#
|
2008-07-03 17:37:57 +01:00
|
|
|
# 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.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-07-03 17:37:57 +01:00
|
|
|
# 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.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
2008-07-03 17:37:57 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2008-07-03 17:37:57 +01:00
|
|
|
|
|
|
|
|
2008-08-04 20:51:47 +02:00
|
|
|
import os
|
2008-08-11 14:20:38 +01:00
|
|
|
import sys
|
2010-03-20 20:22:55 +01:00
|
|
|
import subprocess
|
2010-12-14 18:22:51 +01:00
|
|
|
import urllib
|
2008-08-11 14:20:38 +01:00
|
|
|
from optparse import OptionParser
|
2008-07-03 17:37:57 +01:00
|
|
|
|
2010-12-24 12:00:03 +02:00
|
|
|
from ubuntutools.config import UDTConfig
|
|
|
|
from ubuntutools.logger import Logger
|
2010-03-20 20:22:55 +01:00
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad
|
|
|
|
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
|
|
|
|
PackageNotFoundException, PocketDoesNotExistError)
|
2010-12-24 12:00:03 +02:00
|
|
|
from ubuntutools.misc import splitReleasePocket, dsc_name, dsc_url
|
2008-08-27 10:22:08 +01:00
|
|
|
|
2009-05-28 03:37:38 -04:00
|
|
|
if not os.path.exists("/usr/bin/dget"):
|
2010-12-24 12:00:03 +02:00
|
|
|
print ("E: dget is not installed - please install the 'devscripts' package"
|
|
|
|
" and rerun this script again.")
|
2009-05-28 03:37:38 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2008-08-04 20:51:47 +02:00
|
|
|
if __name__ == '__main__':
|
2008-08-11 19:32:46 +01:00
|
|
|
usage = "Usage: %prog <package> [release]"
|
2008-08-11 14:20:38 +01:00
|
|
|
optParser = OptionParser(usage)
|
2010-12-24 12:16:34 +02:00
|
|
|
optParser.add_option('-d', '--download-only',
|
|
|
|
dest='download_only', default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Do not extract the source package")
|
2010-12-24 12:00:03 +02:00
|
|
|
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")
|
2008-08-11 14:20:38 +01:00
|
|
|
(options, args) = optParser.parse_args()
|
2010-03-20 20:22:55 +01:00
|
|
|
if not args:
|
2010-12-24 12:00:03 +02:00
|
|
|
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')
|
2010-03-20 20:22:55 +01:00
|
|
|
|
|
|
|
# Login anonymously to LP
|
|
|
|
Launchpad.login_anonymously()
|
|
|
|
|
2008-08-27 10:22:08 +01:00
|
|
|
package = str(args[0]).lower()
|
2008-07-03 17:37:57 +01:00
|
|
|
|
2010-03-20 20:22:55 +01:00
|
|
|
if len(args) >= 2: # Custom distribution specified.
|
|
|
|
release = str(args[1]).lower()
|
|
|
|
else:
|
2010-12-24 12:04:46 +02:00
|
|
|
release = os.getenv('DIST') or (Distribution('ubuntu')
|
|
|
|
.getDevelopmentSeries().name)
|
2010-03-20 20:22:55 +01:00
|
|
|
|
2009-06-12 00:14:22 +02:00
|
|
|
try:
|
2010-03-20 20:22:55 +01:00
|
|
|
(release, pocket) = splitReleasePocket(release)
|
|
|
|
except PocketDoesNotExistError, e:
|
2010-12-24 12:04:46 +02:00
|
|
|
Logger.error(e)
|
2010-03-20 20:22:55 +01:00
|
|
|
sys.exit(1)
|
2009-11-07 19:20:46 +00:00
|
|
|
|
2010-03-20 20:22:55 +01:00
|
|
|
try:
|
2010-12-24 12:04:46 +02:00
|
|
|
spph = Distribution('ubuntu').getArchive().getSourcePackage(package,
|
|
|
|
release,
|
|
|
|
pocket)
|
2009-06-12 00:14:22 +02:00
|
|
|
except (SeriesNotFoundException, PackageNotFoundException), e:
|
2010-12-24 12:04:46 +02:00
|
|
|
Logger.error(e)
|
2009-06-12 00:14:22 +02:00
|
|
|
sys.exit(1)
|
2008-08-13 10:56:53 +01:00
|
|
|
|
2010-12-24 12:16:34 +02:00
|
|
|
urls = []
|
2010-12-24 12:00:03 +02:00
|
|
|
if options.ubuntu_mirror:
|
2010-12-24 12:16:34 +02:00
|
|
|
urls.append(dsc_url(options.ubuntu_mirror, spph.getComponent(),
|
|
|
|
package, spph.getVersion()))
|
|
|
|
dsc_url = [url for url in spph.sourceFileUrls() if url.endswith('.dsc')]
|
|
|
|
assert dsc_url, 'No .dsc file found'
|
|
|
|
urls.append(urllib.unquote(dsc_url[0]))
|
|
|
|
|
|
|
|
Logger.normal('Fetching the source for %s from %s (%s)...',
|
|
|
|
package, release.capitalize(), pocket)
|
|
|
|
for url in urls:
|
|
|
|
cmd = ('dget', '-u' + 'd' if options.download_only else 'x', url)
|
2010-12-24 12:00:03 +02:00
|
|
|
Logger.command(cmd)
|
|
|
|
r = subprocess.call(cmd)
|
|
|
|
if r == 0:
|
|
|
|
Logger.normal("Success!")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2010-12-24 12:16:34 +02:00
|
|
|
Logger.error('Failed to fetch and extrace the source. '
|
|
|
|
'Please check the output for the error.')
|
|
|
|
sys.exit(1)
|