mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-31 21:01:07 +00:00
Better handle errors when going to LP
This commit is contained in:
parent
ce044d17df
commit
728bb807d5
5
debian/changelog
vendored
5
debian/changelog
vendored
@ -13,7 +13,10 @@ ubuntu-dev-tools (0.39ubuntu1) intrepid; urgency=low
|
|||||||
* common.py:
|
* common.py:
|
||||||
- Add functions mkdir and readlist.
|
- Add functions mkdir and readlist.
|
||||||
|
|
||||||
-- Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> Tue, 12 Aug 2008 20:09:42 +0200
|
[ Iain Lane ]
|
||||||
|
* pull-lp-source: Better handle errors when going to LP
|
||||||
|
|
||||||
|
-- Iain Lane <iain@orangesquash.org.uk> Wed, 13 Aug 2008 10:56:12 +0100
|
||||||
|
|
||||||
ubuntu-dev-tools (0.38ubuntu1) intrepid; urgency=low
|
ubuntu-dev-tools (0.38ubuntu1) intrepid; urgency=low
|
||||||
|
|
||||||
|
@ -34,26 +34,26 @@ from optparse import OptionParser
|
|||||||
|
|
||||||
class BackportFromLP:
|
class BackportFromLP:
|
||||||
|
|
||||||
def __getitem__(self, name):
|
def __getitem__(self, name):
|
||||||
return getattr(self, name)
|
return getattr(self, name)
|
||||||
|
|
||||||
def __init__(self, package, target_release):
|
def __init__(self, package, target_release):
|
||||||
self.package = package
|
self.package = package
|
||||||
self.target_release = target_release
|
self.target_release = target_release
|
||||||
self.__prepare_sources()
|
self.__prepare_sources()
|
||||||
|
|
||||||
def __prepare_sources(self):
|
def __prepare_sources(self):
|
||||||
# Scrape the source package from Launchpad :)
|
# Scrape the source package from Launchpad :)
|
||||||
contents = urllib2.urlopen('https://launchpad.net/ubuntu/%(target_release)s/+source/%(package)s' % self).read()
|
contents = urllib2.urlopen('https://launchpad.net/ubuntu/%(target_release)s/+source/%(package)s' % 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 \
|
||||||
subprocess.call(['dget', '-x', 'http://launchpad.net%s' % links[0]]) == 0:
|
subprocess.call(['dget', '-xu', '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. ' +\
|
||||||
'Ensure that the package specified is a valid source ' +\
|
'Ensure that the package specified is a valid source ' +\
|
||||||
'package name and that Launchpad is not down.'
|
'package name and that Launchpad is not down.'
|
||||||
|
|
||||||
default_release = 'intrepid'
|
default_release = 'intrepid'
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
release = os.getenv('DIST') or default_release
|
release = os.getenv('DIST') or default_release
|
||||||
|
|
||||||
# Correct-ish args, can proceed.
|
# Correct-ish args, can proceed.
|
||||||
# Check release by checking if Launchpad page exists
|
# Check release by checking if Launchpad page exists
|
||||||
try:
|
try:
|
||||||
urllib2.urlopen("https://launchpad.net/ubuntu/%s" % release)
|
urllib2.urlopen("https://launchpad.net/ubuntu/%s" % release)
|
||||||
@ -84,20 +84,43 @@ if __name__ == '__main__':
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check package exists.
|
# Check package exists.
|
||||||
sourcePage = urllib2.urlopen("https://launchpad.net/ubuntu/%s/+source/%s" % \
|
try:
|
||||||
(release, package)).read()
|
|
||||||
m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, \
|
sourcePage = urllib2.urlopen("https://launchpad.net/ubuntu/%s/+source/%s" % \
|
||||||
package.replace('+', '\+')), sourcePage)
|
(release, package)).read()
|
||||||
if not m:
|
m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, \
|
||||||
print >> sys.stderr, "The '%s' package does not appear to exist in " \
|
package.replace('+', '\+')), sourcePage)
|
||||||
"the '%s' release." % (package, release)
|
|
||||||
|
if not m:
|
||||||
|
print >> sys.stderr, "The '%s' package does not appear to exist in " \
|
||||||
|
"the '%s' release." % (package, release)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
except urllib2.HTTPError, e: # Raised on 404
|
||||||
|
|
||||||
|
if e.code == 404:
|
||||||
|
|
||||||
|
print >> sys.stderr, "The '%s' package does not appear to exist in " \
|
||||||
|
"the '%s' release." % (package, release)
|
||||||
|
|
||||||
|
else: # Other code, probably LP malfunction
|
||||||
|
|
||||||
|
print >> sys.stderr, "Error when checking Launchpad for package: %s " % e
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
except urllib2.URLError, e: # Other error (NXDOMAIN, ...)
|
||||||
|
|
||||||
|
(_, reason) = e.reason
|
||||||
|
|
||||||
|
print >> sys.stderr, "Error when checking Launchpad for package: %s " % reason
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# All good - start downloading...
|
# All good - start downloading...
|
||||||
try:
|
try:
|
||||||
print 'Attempting to get %s from release %s...' % \
|
print 'Attempting to get %s from release %s...' % \
|
||||||
(package, release.capitalize())
|
(package, release.capitalize())
|
||||||
BackportFromLP(package, release)
|
BackportFromLP(package, release)
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
print 'Error when downloading package %s from release %s: %s.' % \
|
print 'Error when downloading package %s from release %s: %s.' % \
|
||||||
(package, release, e)
|
(package, release, e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user