* pull-lp-source:

- Use optparse for option handling.
  - Check that 'distro' exists on Launchpad.
  - Use subprocess for dget calls.
This commit is contained in:
Jonathan Patrick Davies 2008-08-11 14:20:38 +01:00
parent 45a5d024b3
commit 3d4017fe77
2 changed files with 51 additions and 29 deletions

4
debian/changelog vendored
View File

@ -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

View File

@ -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:
@ -46,7 +48,7 @@ class BackportFromLP:
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()
args = sys.argv[1:] or [] if not args:
print >> sys.stderr, "Need arguments."
optParser.print_help()
sys.exit(1)
if args == [] or args[0] in ('-h', '--help'): package = args[0]
usage()
sys.exit(0)
if len(args) >= 1: if len(args) == 2: # Custom distribution specified.
package = args[0] distro = args[1]
else:
distro = os.getenv('DIST') or default_distro
if len(args) == 2: # Correct-ish args, can proceed.
distro = args[1] # Check distro by checking if Launchpad page exists
elif len(args) == 1: try:
distro = os.getenv('DIST') or default_distro urllib2.urlopen("https://launchpad.net/ubuntu/%s" % distro)
else: # incorrect args except urllib2.HTTPError:
usage() print >> sys.stderr, "The distribution '%s' does not appear to exist on " \
sys.exit(1) "Launchpad." % distro
sys.exit(1)
# Correct-ish args, can proceed # Check package exists.
try: """ TODO: Find a way to check that the package exists here.
print 'Attempting to get %s from distro %s...' % \ madison = subprocess.Popen(['rmadison', '-u', 'ubuntu', '-a', 'source', \
(package, distro.capitalize()) '-s', distro, package], stdout = subprocess.PIPE)
BackportFromLP(package, distro) out = madison.communicate()[0]
except ValueError, e: print madison.returncode
print 'Error when downloading package %s from distro %s: %s' % \ assert (madison.returncode == 0)
(package, distro, e) 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)