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
|
|
|
#
|
2011-01-31 19:01:10 +02:00
|
|
|
# Copyright (C) 2008, Iain Lane <iain@orangesquash.org.uk>,
|
|
|
|
# 2010-2011, 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
|
|
|
|
from optparse import OptionParser
|
2008-07-03 17:37:57 +01:00
|
|
|
|
2011-05-23 23:41:00 +02:00
|
|
|
from devscripts.logger import Logger
|
2011-06-25 17:53:44 +02:00
|
|
|
from distro_info import UbuntuDistroInfo
|
2011-05-23 23:41:00 +02:00
|
|
|
|
2011-01-31 19:01:10 +02:00
|
|
|
from ubuntutools.archive import UbuntuSourcePackage, DownloadError
|
2010-12-24 12:00:03 +02:00
|
|
|
from ubuntutools.config import UDTConfig
|
2010-03-20 20:22:55 +01:00
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad
|
|
|
|
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
|
2010-12-28 00:23:53 +02:00
|
|
|
PackageNotFoundException,
|
|
|
|
PocketDoesNotExistError)
|
|
|
|
from ubuntutools.misc import split_release_pocket
|
2008-08-27 10:22:08 +01:00
|
|
|
|
2010-12-25 16:32:29 +01:00
|
|
|
def main():
|
2011-03-05 00:48:58 +02:00
|
|
|
usage = "Usage: %prog <package> [release|version]"
|
2010-12-25 16:32:29 +01:00
|
|
|
opt_parser = OptionParser(usage)
|
|
|
|
opt_parser.add_option('-d', '--download-only',
|
|
|
|
dest='download_only', default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Do not extract the source package")
|
|
|
|
opt_parser.add_option('-m', '--mirror', metavar='UBUNTU_MIRROR',
|
|
|
|
dest='ubuntu_mirror',
|
|
|
|
help='Preferred Ubuntu mirror (default: Launchpad)')
|
|
|
|
opt_parser.add_option('--no-conf',
|
|
|
|
dest='no_conf', default=False, action='store_true',
|
|
|
|
help="Don't read config files or environment "
|
|
|
|
"variables")
|
|
|
|
(options, args) = opt_parser.parse_args()
|
2010-03-20 20:22:55 +01:00
|
|
|
if not args:
|
2010-12-25 16:32:29 +01:00
|
|
|
opt_parser.error("Must specify package name")
|
2010-12-24 12:00:03 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-03-05 00:48:58 +02:00
|
|
|
ubuntu_info = UbuntuDistroInfo()
|
|
|
|
if len(args) > 1: # Custom distribution specified.
|
|
|
|
version = str(args[1])
|
2010-03-20 20:22:55 +01:00
|
|
|
else:
|
2011-03-05 00:48:58 +02:00
|
|
|
version = os.getenv('DIST') or ubuntu_info.devel()
|
|
|
|
component = None
|
2010-03-20 20:22:55 +01:00
|
|
|
|
2011-03-05 00:48:58 +02:00
|
|
|
# Release, not package version number:
|
2011-03-06 00:56:14 +02:00
|
|
|
release = None
|
|
|
|
pocket = None
|
|
|
|
try:
|
2011-11-23 01:45:49 +02:00
|
|
|
(release, pocket) = split_release_pocket(version, default=None)
|
2011-03-06 00:56:14 +02:00
|
|
|
except PocketDoesNotExistError, e:
|
|
|
|
pass
|
2011-11-23 01:45:49 +02:00
|
|
|
if release in ubuntu_info.all:
|
2011-03-05 00:48:58 +02:00
|
|
|
try:
|
|
|
|
spph = Distribution('ubuntu').getArchive().getSourcePackage(package,
|
|
|
|
release,
|
|
|
|
pocket)
|
|
|
|
except (SeriesNotFoundException, PackageNotFoundException), e:
|
|
|
|
Logger.error(str(e))
|
|
|
|
sys.exit(1)
|
|
|
|
version = spph.getVersion()
|
|
|
|
component = spph.getComponent()
|
2008-08-13 10:56:53 +01:00
|
|
|
|
2011-03-05 00:48:58 +02:00
|
|
|
Logger.normal('Downloading %s version %s', package, version)
|
|
|
|
srcpkg = UbuntuSourcePackage(package, version, component=component,
|
2010-12-29 23:13:48 +02:00
|
|
|
mirrors=[options.ubuntu_mirror])
|
2011-01-31 19:01:10 +02:00
|
|
|
try:
|
|
|
|
srcpkg.pull()
|
|
|
|
except DownloadError, e:
|
|
|
|
Logger.error('Failed to download: %s', str(e))
|
|
|
|
sys.exit(1)
|
2010-12-29 23:13:48 +02:00
|
|
|
if not options.download_only:
|
|
|
|
srcpkg.unpack()
|
2010-12-25 16:32:29 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-03-06 01:04:22 +02:00
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
2011-03-06 01:12:24 +02:00
|
|
|
Logger.normal('User abort.')
|