From 6db05720f3484a18ce688dee21d997be181c62b8 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Sat, 7 Nov 2009 19:20:46 +0000 Subject: [PATCH] Conditional LP API usage & better p-l-s errors * lpapicache: Do not immediately bail out if we have no credentials to login. Clients are now expected to handle the lack of credentials themselves. * pull-lp-source: Make LP API use optional - fall back to a hardcoded default release if we aren't using it. (LP: #477670) * pull-lp-source: Detect more failure conditions and give a nice error instead of a trace * buildd, requestsync: Detect & bail if we don't have credentials and need them. These scripts cannot continue under those circumstances. --- buildd | 6 ++++- debian/changelog | 14 +++++++++++ pull-lp-source | 45 +++++++++++++++++++++++------------- requestsync | 5 ++++ ubuntutools/lp/lpapicache.py | 2 +- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/buildd b/buildd index 31eb182..f640b43 100755 --- a/buildd +++ b/buildd @@ -124,7 +124,11 @@ if not options.batch: sys.exit(1) # Get the ubuntu archive - ubuntu_archive = Distribution('ubuntu').getArchive() + try: + ubuntu_archive = Distribution('ubuntu').getArchive() + # Will fail here if we have no credentials, bail out + except IOError: + sys.exit(1) # Get list of published sources for package in question. try: sources = ubuntu_archive.getSourcePackage(package, release, pocket) diff --git a/debian/changelog b/debian/changelog index 5180500..8ddf450 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +ubuntu-dev-tools (0.83) UNRELEASED; urgency=low + + * lpapicache: Do not immediately bail out if we have no credentials to + login. Clients are now expected to handle the lack of credentials + themselves. + * pull-lp-source: Make LP API use optional - fall back to a hardcoded + default release if we aren't using it. (LP: #477670) + * pull-lp-source: Detect more failure conditions and give a nice error + instead of a trace + * buildd, requestsync: Detect & bail if we don't have credentials and need + them. These scripts cannot continue under those circumstances. + + -- Iain Lane Sat, 07 Nov 2009 19:18:27 +0000 + ubuntu-dev-tools (0.82) lucid; urgency=low [ Iain Lane ] diff --git a/pull-lp-source b/pull-lp-source index c025064..3a632af 100755 --- a/pull-lp-source +++ b/pull-lp-source @@ -53,39 +53,52 @@ class BackportFromLP: 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('href=\"(.*\.dsc)\"', contents) + try: + contents = urllib2.urlopen('https://launchpad.net/ubuntu/%(target_release)s/+source/%(package)s' % self).read() + links = re.findall('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.' + 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.' + except urllib2.HTTPError: + 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.' if __name__ == '__main__': usage = "Usage: %prog [release]" optParser = OptionParser(usage) (options, args) = optParser.parse_args() + release = None 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 Distribution('ubuntu').getDevelopmentSeries().name - - # Arguments are correct, proceed. - # Check that the Ubuntu release and package specified exists. try: + if len(args) == 2: # Custom distribution specified. + release = str(args[1]).lower() + else: + release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name + + # Arguments are correct, proceed. + # Check that the Ubuntu release and package specified exists. Distribution('ubuntu').getArchive().getSourcePackage(package, release) + except IOError, e: + print "This is non-fatal, continuing..." except (SeriesNotFoundException, PackageNotFoundException), e: print e sys.exit(1) + # We won't have been able to get the release if there are no LP credentials, hardcode it + # also could bail out here if others think that is better + if release is None: + release = 'lucid' + # All good - start downloading... try: print 'Attempting to get %s from release %s...' % \ diff --git a/requestsync b/requestsync index 9febe9a..ceb9fcc 100755 --- a/requestsync +++ b/requestsync @@ -76,6 +76,11 @@ if __name__ == '__main__': if options.lpapi: from ubuntutools.requestsync.lp import * from ubuntutools.lp.lpapicache import Distribution, PersonTeam + # See if we have LP credentials and exit if we don't - cannot continue in this case + try: + Launchpad.login() + except IOError: + sys.exit(1) else: from ubuntutools.requestsync.mail import * if not getEmailAddress(): diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index fa267d9..b0150fd 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -43,7 +43,7 @@ class Launchpad(object): self.__lp = libsupport.get_launchpad('ubuntu-dev-tools') except IOError, error: print >> sys.stderr, 'E: %s' % error - sys.exit(1) + raise error return self def __getattr__(self, attr):