mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-05 14:01:33 +00:00
Allow reusing existing Launchpads with lpapicache
This commit is contained in:
parent
62073c1085
commit
adc2b7869d
@ -56,7 +56,7 @@ class _Launchpad(object):
|
|||||||
|
|
||||||
def login(self, service=service):
|
def login(self, service=service):
|
||||||
'''Enforce a non-anonymous login.'''
|
'''Enforce a non-anonymous login.'''
|
||||||
if '_Launchpad__lp' not in self.__dict__:
|
if not self.logged_in:
|
||||||
try:
|
try:
|
||||||
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools',
|
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools',
|
||||||
server=service)
|
server=service)
|
||||||
@ -68,14 +68,26 @@ class _Launchpad(object):
|
|||||||
|
|
||||||
def login_anonymously(self, service=service, api_version=api_version):
|
def login_anonymously(self, service=service, api_version=api_version):
|
||||||
'''Enforce an anonymous login.'''
|
'''Enforce an anonymous login.'''
|
||||||
if '_Launchpad__lp' not in self.__dict__:
|
if not self.logged_in:
|
||||||
self.__lp = launchpad.Launchpad.login_anonymously(
|
self.__lp = launchpad.Launchpad.login_anonymously(
|
||||||
'ubuntu-dev-tools', service_root=service, version=api_version)
|
'ubuntu-dev-tools', service_root=service, version=api_version)
|
||||||
else:
|
else:
|
||||||
raise AlreadyLoggedInError('Already logged in to Launchpad.')
|
raise AlreadyLoggedInError('Already logged in to Launchpad.')
|
||||||
|
|
||||||
|
def login_existing(self, lp):
|
||||||
|
'''Use an already logged in Launchpad object'''
|
||||||
|
if not self.logged_in:
|
||||||
|
self.__lp = lp
|
||||||
|
else:
|
||||||
|
raise AlreadyLoggedInError('Already logged in to Launchpad.')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logged_in(self):
|
||||||
|
'''Are we logged in?'''
|
||||||
|
return '_Launchpad__lp' in self.__dict__
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if '_Launchpad__lp' not in self.__dict__:
|
if not self.logged_in:
|
||||||
self.login()
|
self.login()
|
||||||
return getattr(self.__lp, attr)
|
return getattr(self.__lp, attr)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user