#!/usr/bin/python # # pull-debian-source -- pull a source package from Launchpad # Copyright (C) 2011, Stefano Rivera # 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, rmadison from ubuntutools.config import UDTConfig from ubuntutools.logger import Logger def main(): usage = 'Usage: %prog [release]' 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() if len(args) > 1: suite = args[1].lower() else: suite = 'unstable' line = list(rmadison('debian', package, suite, 'source')) if not line: Logger.error('Unable to find %s in %s.', package, suite) sys.exit(1) line = line[-1] srcpkg = DebianSourcePackage(package, line['version'], component=line['component'], mirrors=[options.debian_mirror, options.debsec_mirror]) srcpkg.pull() if not options.download_only: srcpkg.unpack() if __name__ == '__main__': main()