mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 23:51:08 +00:00
91 lines
3.8 KiB
Python
Executable File
91 lines
3.8 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# pull-debian-source -- pull a source package from Launchpad
|
|
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
|
|
# Inspired by a tool of the same name by Nathan Handler.
|
|
#
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# copyright notice and this permission notice appear in all copies.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
# PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
import optparse
|
|
import sys
|
|
|
|
from ubuntutools.archive import DebianSourcePackage, DownloadError, rmadison
|
|
from ubuntutools.config import UDTConfig
|
|
from ubuntutools.distro_info import DebianDistroInfo
|
|
from ubuntutools.logger import Logger
|
|
|
|
def main():
|
|
usage = 'Usage: %prog <package> [release|version]'
|
|
parser = optparse.OptionParser(usage)
|
|
parser.add_option('-d', '--download-only',
|
|
dest='download_only', default=False, action='store_true',
|
|
help='Do not extract the source package')
|
|
parser.add_option('-m', '--mirror', metavar='UBUNTU_MIRROR',
|
|
dest='debian_mirror',
|
|
help='Preferred Debian mirror (default: %s)'
|
|
% UDTConfig.defaults['DEBIAN_MIRROR'])
|
|
parser.add_option('-s', '--security-mirror', metavar='DEBSEC_MIRROR',
|
|
dest='debsec_mirror',
|
|
help='Preferred Debian Security mirror (default: %s)'
|
|
% UDTConfig.defaults['DEBSEC_MIRROR'])
|
|
parser.add_option('--no-conf',
|
|
dest='no_conf', default=False, action='store_true',
|
|
help="Don't read config files or environment variables")
|
|
(options, args) = parser.parse_args()
|
|
if not args:
|
|
parser.error('Must specify package name')
|
|
elif len(args) > 2:
|
|
parser.error('Too many arguments. '
|
|
'Must only specify package and (optionally) release.')
|
|
|
|
config = UDTConfig(options.no_conf)
|
|
if options.debian_mirror is None:
|
|
options.debian_mirror = config.get_value('DEBIAN_MIRROR')
|
|
if options.debsec_mirror is None:
|
|
options.debsec_mirror = config.get_value('DEBSEC_MIRROR')
|
|
|
|
package = args[0].lower()
|
|
|
|
version = args[1] if len(args) > 1 else 'unstable'
|
|
component = None
|
|
|
|
debian_info = DebianDistroInfo()
|
|
if debian_info.codename(version, default=version) in debian_info.all:
|
|
suite = debian_info.codename(version, default=version)
|
|
line = list(rmadison('debian', package, suite, 'source'))
|
|
if not line:
|
|
Logger.error('Unable to find %s in Debian suite "%s".', package,
|
|
suite)
|
|
sys.exit(1)
|
|
line = line[-1]
|
|
version = line['version']
|
|
component = line['component']
|
|
|
|
Logger.normal('Downloading %s version %s', package, version)
|
|
srcpkg = DebianSourcePackage(package, version, component=component,
|
|
mirrors=[options.debian_mirror,
|
|
options.debsec_mirror])
|
|
try:
|
|
srcpkg.pull()
|
|
except DownloadError, e:
|
|
Logger.error('Failed to download: %s', str(e))
|
|
sys.exit(1)
|
|
if not options.download_only:
|
|
srcpkg.unpack()
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
Logger.normal('Aborting at user request')
|