diff --git a/ubuntu-build b/ubuntu-build index a08a7ef..3e02141 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -30,6 +30,7 @@ from ubuntutools.lp.udtexceptions import (SeriesNotFoundException, PackageNotFoundException, PocketDoesNotExistError,) from ubuntutools.lp.lpapicache import Distribution, PersonTeam +from launchpadlib.credentials import TokenAuthorizationException from ubuntutools.misc import split_release_pocket from ubuntutools import getLogger @@ -135,12 +136,14 @@ def main(): Logger.error(error) sys.exit(1) - # Get the ubuntu archive try: - ubuntu_archive = Distribution('ubuntu').getArchive() - # Will fail here if we have no credentials, bail out - except IOError: + # Will fail here if we have no credentials, bail out + Launchpad.login() + except TokenAuthorizationException: sys.exit(1) + + # Get the ubuntu archive + ubuntu_archive = Distribution('ubuntu').getArchive() # Get list of published sources for package in question. try: sources = ubuntu_archive.getSourcePackage(package, release, pocket) diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 7d5e44e..3d82cd7 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -74,12 +74,14 @@ class _Launchpad(object): def login(self, service=service, api_version=api_version): '''Enforce a non-anonymous login.''' if not self.logged_in: - try: - self.__lp = LP.login_with('ubuntu-dev-tools', service, - version=api_version) - except IOError as error: - Logger.error(str(error)) - raise + self.__lp = LP.login_with('ubuntu-dev-tools', service, + version=api_version) + # Unfortunately launchpadlib may 'login' using cached + # credentials, without actually verifying if the credentials + # are valid; which can lead to this 'login' not actually + # logging in. + # So, this forces actual LP access here, to force actual login. + self.__lp.me else: raise AlreadyLoggedInError('Already logged in to Launchpad.')