mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
107 lines
3.4 KiB
Python
Executable File
107 lines
3.4 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# pull-lp-source -- pull a source package from Launchpad
|
|
# Basic usage: pull-lp-source <source package> [<distro>]
|
|
#
|
|
# Copyright (C) 2008 Iain Lane <iain@orangesquash.org.uk>
|
|
#
|
|
# BackportFromLP class taken from prevu tool, which is:
|
|
# Copyright (C) 2006 John Dong <jdong@ubuntu.com>
|
|
#
|
|
# ##################################################################
|
|
#
|
|
# 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.
|
|
#
|
|
# 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.
|
|
#
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
|
#
|
|
# ##################################################################
|
|
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import urllib2
|
|
from optparse import OptionParser
|
|
|
|
class BackportFromLP:
|
|
|
|
def __getitem__(self, name):
|
|
return getattr(self, name)
|
|
|
|
def __init__(self, package, target_distro):
|
|
self.package = package
|
|
self.target_distro = target_distro
|
|
self.__prepare_sources()
|
|
|
|
def __prepare_sources(self):
|
|
# Scrape the source package from Launchpad :)
|
|
import re
|
|
|
|
contents = os.popen('wget -q https://launchpad.net/ubuntu/%(target_distro)s/+source/%(package)s -O-' % self).read()
|
|
links = re.findall('a href=\"(.*\.dsc)\"', contents)
|
|
|
|
if len(links) == 1 and \
|
|
subprocess.call(['dget', '-x', 'http://launchpad.net%s' % links[0]]) == 0:
|
|
print '\nSuccess!'
|
|
else:
|
|
raise ValueError, '\nFailed to fetch and extract the source. ' +\
|
|
'Ensure that the package specified is a valid source ' +\
|
|
'package name and that Launchpad is not down.'
|
|
|
|
default_distro = 'intrepid'
|
|
|
|
if __name__ == '__main__':
|
|
usage = "Usage: %prog <package> [distribution]"
|
|
optParser = OptionParser(usage)
|
|
(options, args) = optParser.parse_args()
|
|
|
|
if not args:
|
|
print >> sys.stderr, "Need arguments."
|
|
optParser.print_help()
|
|
sys.exit(1)
|
|
|
|
package = args[0]
|
|
|
|
if len(args) == 2: # Custom distribution specified.
|
|
distro = args[1]
|
|
else:
|
|
distro = os.getenv('DIST') or default_distro
|
|
|
|
# Correct-ish args, can proceed.
|
|
# Check distro by checking if Launchpad page exists
|
|
try:
|
|
urllib2.urlopen("https://launchpad.net/ubuntu/%s" % distro)
|
|
except urllib2.HTTPError:
|
|
print >> sys.stderr, "The distribution '%s' does not appear to exist on " \
|
|
"Launchpad." % distro
|
|
sys.exit(1)
|
|
|
|
# Check package exists.
|
|
""" TODO: Find a way to check that the package exists here.
|
|
madison = subprocess.Popen(['rmadison', '-u', 'ubuntu', '-a', 'source', \
|
|
'-s', distro, package], stdout = subprocess.PIPE)
|
|
out = madison.communicate()[0]
|
|
print madison.returncode
|
|
assert (madison.returncode == 0)
|
|
if madison == 0:
|
|
print "The '%s' package doesn't appear to exist in %s." % (package, distro)
|
|
sys.exit(1)
|
|
"""
|
|
|
|
# All good - start downloading...
|
|
try:
|
|
print 'Attempting to get %s from distro %s...' % \
|
|
(package, distro.capitalize())
|
|
BackportFromLP(package, distro)
|
|
except ValueError, e:
|
|
print 'Error when downloading package %s from distro %s: %s' % \
|
|
(package, distro, e)
|