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
|
|
|
|
from optparse import OptionParser
|
2008-07-03 17:37:57 +01:00
|
|
|
|
2010-12-29 23:13:48 +02:00
|
|
|
from ubuntutools.archive import UbuntuSourcePackage
|
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,
|
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():
|
2008-08-11 19:32:46 +01:00
|
|
|
usage = "Usage: %prog <package> [release]"
|
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
|
|
|
|
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-12-27 22:33:01 +01:00
|
|
|
(release, pocket) = split_release_pocket(release)
|
2010-12-30 17:13:58 +02:00
|
|
|
except PocketDoesNotExistError, e:
|
|
|
|
Logger.error(str(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)
|
2010-12-30 17:13:58 +02:00
|
|
|
except (SeriesNotFoundException, PackageNotFoundException), e:
|
|
|
|
Logger.error(str(e))
|
2009-06-12 00:14:22 +02:00
|
|
|
sys.exit(1)
|
2008-08-13 10:56:53 +01:00
|
|
|
|
2010-12-29 23:13:48 +02:00
|
|
|
srcpkg = UbuntuSourcePackage(package, spph.getVersion(),
|
|
|
|
component=spph.getComponent(),
|
|
|
|
mirrors=[options.ubuntu_mirror])
|
|
|
|
srcpkg.pull()
|
|
|
|
if not options.download_only:
|
|
|
|
srcpkg.unpack()
|
2010-12-25 16:32:29 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|