mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-06-08 06:21:29 +00:00
* pull-lp-source:
- Use optparse for option handling. - Check that 'distro' exists on Launchpad. - Use subprocess for dget calls.
This commit is contained in:
parent
45a5d024b3
commit
3d4017fe77
4
debian/changelog
vendored
4
debian/changelog
vendored
@ -4,6 +4,10 @@ ubuntu-dev-tools (0.37ubuntu1) intrepid; urgency=low
|
|||||||
* get-branches: Open the teams code page before making a new directory.
|
* get-branches: Open the teams code page before making a new directory.
|
||||||
* doc/get-branches.1: Created.
|
* doc/get-branches.1: Created.
|
||||||
* hugdaylist: Improved argument and error handling.
|
* hugdaylist: Improved argument and error handling.
|
||||||
|
* pull-lp-source:
|
||||||
|
- Use optparse for option handling.
|
||||||
|
- Check that 'distro' exists on Launchpad.
|
||||||
|
- Use subprocess for dget calls.
|
||||||
|
|
||||||
-- Jonathan Patrick Davies <jpds@ubuntu.com> Sun, 10 August 2008 22:07:58 +0100
|
-- Jonathan Patrick Davies <jpds@ubuntu.com> Sun, 10 August 2008 22:07:58 +0100
|
||||||
|
|
||||||
|
@ -22,11 +22,13 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
# TODO: Determine before going to LP whether a source package and distro exist or not.
|
|
||||||
# TODO: Determine current development distro programatically
|
# TODO: Determine current development distro programatically
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import urllib2
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
class BackportFromLP:
|
class BackportFromLP:
|
||||||
|
|
||||||
@ -40,13 +42,13 @@ class BackportFromLP:
|
|||||||
|
|
||||||
def __prepare_sources(self):
|
def __prepare_sources(self):
|
||||||
# Scrape the source package from Launchpad :)
|
# Scrape the source package from Launchpad :)
|
||||||
import re
|
import re
|
||||||
|
|
||||||
contents = os.popen('wget -q https://launchpad.net/ubuntu/%(target_distro)s/+source/%(package)s -O-' % self).read()
|
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)
|
links = re.findall('a href=\"(.*\.dsc)\"', contents)
|
||||||
|
|
||||||
if len(links) == 1 and \
|
if len(links) == 1 and \
|
||||||
(os.system('dget -x http://launchpad.net%s' % links[0])) == 0:
|
subprocess.call(['dget', '-x', 'http://launchpad.net%s' % links[0]]) == 0:
|
||||||
print '\nSuccess!'
|
print '\nSuccess!'
|
||||||
else:
|
else:
|
||||||
raise ValueError, '\nFailed to fetch and extract the source. ' +\
|
raise ValueError, '\nFailed to fetch and extract the source. ' +\
|
||||||
@ -55,33 +57,49 @@ class BackportFromLP:
|
|||||||
|
|
||||||
default_distro = 'intrepid'
|
default_distro = 'intrepid'
|
||||||
|
|
||||||
def usage():
|
|
||||||
print 'Usage: %s <package> [distro]' % sys.argv[0]
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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]
|
||||||
|
|
||||||
args = sys.argv[1:] or []
|
if len(args) == 2: # Custom distribution specified.
|
||||||
|
distro = args[1]
|
||||||
|
else:
|
||||||
|
distro = os.getenv('DIST') or default_distro
|
||||||
|
|
||||||
if args == [] or args[0] in ('-h', '--help'):
|
# Correct-ish args, can proceed.
|
||||||
usage()
|
# Check distro by checking if Launchpad page exists
|
||||||
sys.exit(0)
|
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)
|
||||||
|
|
||||||
if len(args) >= 1:
|
# Check package exists.
|
||||||
package = args[0]
|
""" 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)
|
||||||
|
"""
|
||||||
|
|
||||||
if len(args) == 2:
|
# All good - start downloading...
|
||||||
distro = args[1]
|
try:
|
||||||
elif len(args) == 1:
|
print 'Attempting to get %s from distro %s...' % \
|
||||||
distro = os.getenv('DIST') or default_distro
|
(package, distro.capitalize())
|
||||||
else: # incorrect args
|
BackportFromLP(package, distro)
|
||||||
usage()
|
except ValueError, e:
|
||||||
sys.exit(1)
|
print 'Error when downloading package %s from distro %s: %s' % \
|
||||||
|
(package, distro, e)
|
||||||
# Correct-ish args, can proceed
|
|
||||||
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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user