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
|
|
|
#
|
2008-08-04 20:51:47 +02:00
|
|
|
# Copyright (C) 2008 Iain Lane <iain@orangesquash.org.uk>
|
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# BackportFromLP class taken from prevu tool, which is:
|
|
|
|
# Copyright (C) 2006 John Dong <jdong@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
|
|
|
|
2009-05-28 03:12:35 -04:00
|
|
|
# ubuntu-dev-tools modules.
|
2010-03-20 20:22:55 +01:00
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad
|
|
|
|
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
|
|
|
|
PackageNotFoundException, PocketDoesNotExistError)
|
|
|
|
from ubuntutools.misc import splitReleasePocket
|
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-03-20 20:22:55 +01:00
|
|
|
print "E: dget is not installed - please install the 'devscripts' package" \
|
2009-05-28 03:37:38 -04:00
|
|
|
" and rerun this script again."
|
|
|
|
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)
|
|
|
|
(options, args) = optParser.parse_args()
|
2010-03-20 20:22:55 +01:00
|
|
|
|
|
|
|
if not args:
|
|
|
|
optParser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name
|
|
|
|
|
2009-06-12 00:14:22 +02:00
|
|
|
try:
|
2010-03-20 20:22:55 +01:00
|
|
|
(release, pocket) = splitReleasePocket(release)
|
|
|
|
except PocketDoesNotExistError, e:
|
|
|
|
print 'E: %s' % e
|
|
|
|
sys.exit(1)
|
2009-11-07 19:20:46 +00:00
|
|
|
|
2010-03-20 20:22:55 +01:00
|
|
|
try:
|
|
|
|
spph = Distribution('ubuntu').getArchive().getSourcePackage(package, release, pocket)
|
2009-06-12 00:14:22 +02:00
|
|
|
except (SeriesNotFoundException, PackageNotFoundException), e:
|
2010-03-20 20:22:55 +01:00
|
|
|
print 'E: %s' % e
|
2009-06-12 00:14:22 +02:00
|
|
|
sys.exit(1)
|
2008-08-13 10:56:53 +01:00
|
|
|
|
2010-03-20 20:22:55 +01:00
|
|
|
dsc_url = [url for url in spph.sourceFileUrls() if url.endswith('.dsc')]
|
|
|
|
assert dsc_url, 'No .dsc file found'
|
2009-11-07 19:20:46 +00:00
|
|
|
|
2008-08-11 14:20:38 +01:00
|
|
|
# All good - start downloading...
|
2010-03-20 20:22:55 +01:00
|
|
|
print 'Fetching the source for %s from %s (%s)...' % (
|
|
|
|
package, release.capitalize(), pocket)
|
2010-12-14 18:22:51 +01:00
|
|
|
if subprocess.call(['/usr/bin/dget', '-xu', urllib.unquote(dsc_url[0])]) == 0:
|
2010-03-20 20:22:55 +01:00
|
|
|
print 'Success!'
|
|
|
|
else:
|
|
|
|
print 'Failed to fetch and extrace the source.', \
|
|
|
|
'Please check the output for the error.'
|