mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 15:41:09 +00:00
93 lines
3.1 KiB
Python
Executable File
93 lines
3.1 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# pull-lp-source -- pull a source package from Launchpad
|
|
# Basic usage: pull-lp-source <source package> [<release>]
|
|
#
|
|
# 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 re
|
|
import subprocess
|
|
import sys
|
|
import urllib2
|
|
from optparse import OptionParser
|
|
|
|
# ubuntu-dev-tools modules.
|
|
import ubuntutools.lp.functions as lp_functions
|
|
from ubuntutools import packages
|
|
|
|
class BackportFromLP:
|
|
|
|
def __getitem__(self, name):
|
|
return getattr(self, name)
|
|
|
|
def __init__(self, package, target_release):
|
|
self.package = package
|
|
self.target_release = target_release
|
|
self.__prepare_sources()
|
|
|
|
def __prepare_sources(self):
|
|
# Scrape the source package from Launchpad :)
|
|
contents = urllib2.urlopen('https://launchpad.net/ubuntu/%(target_release)s/+source/%(package)s' % self).read()
|
|
links = re.findall('a href=\"(.*\.dsc)\"', contents)
|
|
|
|
if len(links) == 1 and \
|
|
subprocess.call(['dget', '-xu', 'https://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_release = lp_functions.ubuntuDevelopmentSeries()
|
|
|
|
if __name__ == '__main__':
|
|
usage = "Usage: %prog <package> [release]"
|
|
optParser = OptionParser(usage)
|
|
(options, args) = optParser.parse_args()
|
|
|
|
if not args: optParser.error("Arguments required.")
|
|
|
|
package = str(args[0]).lower()
|
|
|
|
if len(args) == 2: # Custom distribution specified.
|
|
release = str(args[1]).lower()
|
|
else:
|
|
release = os.getenv('DIST') or default_release
|
|
|
|
# Arguments are correct, proceed.
|
|
# Check that the Ubuntu release specified exists.
|
|
lp_functions.doesUbuntuReleaseExist(release)
|
|
|
|
# Check package exists.
|
|
packages.checkSourceExists(package, release)
|
|
|
|
# All good - start downloading...
|
|
try:
|
|
print 'Attempting to get %s from release %s...' % \
|
|
(package, release.capitalize())
|
|
BackportFromLP(package, release)
|
|
except ValueError, e:
|
|
print 'Error when downloading package %s from release %s: %s.' % \
|
|
(package, release, e)
|