Merge branch 'lp1984113' of git+ssh://git.launchpad.net/~ddstreet/ubuntu-dev-tools

MR: https://code.launchpad.net/~ddstreet/ubuntu-dev-tools/+git/ubuntu-dev-tools/+merge/428101
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
This commit is contained in:
Mattia Rizzolo 2022-08-22 17:57:07 +02:00
commit 05af489f64
No known key found for this signature in database
GPG Key ID: 0816B9E18C762BAD
2 changed files with 15 additions and 10 deletions

View File

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

View File

@ -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.')