mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-14 00:21:08 +00:00
ubuntutools/lp/lpapicache.py:
* Add support for anonymous login to the Launchpad singleton. ubuntutools/lp/udtexceptions.py: * Add AlreadyLoggedInError
This commit is contained in:
parent
0dfe4b4731
commit
8c114519e8
@ -26,6 +26,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
import launchpadlib.launchpad as launchpad
|
||||
from launchpadlib.errors import HTTPError
|
||||
from launchpadlib.uris import lookup_service_root
|
||||
from lazr.restfulclient.resource import Entry
|
||||
@ -35,28 +36,33 @@ from ubuntutools.lp import service
|
||||
from ubuntutools.lp.udtexceptions import *
|
||||
|
||||
class Launchpad(object):
|
||||
''' Singleton for LP API access. '''
|
||||
__lp = None
|
||||
'''Singleton for LP API access.'''
|
||||
|
||||
def login(self):
|
||||
'''
|
||||
Enforce a login through the LP API.
|
||||
'''
|
||||
if not self.__lp:
|
||||
try:
|
||||
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools')
|
||||
except IOError, error:
|
||||
print >> sys.stderr, 'E: %s' % error
|
||||
raise error
|
||||
return self
|
||||
def login(self):
|
||||
'''Enforce a non-anonymous login.'''
|
||||
if '_Launchpad__lp' not in self.__dict__:
|
||||
try:
|
||||
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools')
|
||||
except IOError, error:
|
||||
print >> sys.stderr, 'E: %s' % error
|
||||
raise
|
||||
else:
|
||||
raise AlreadyLoggedInError('Already logged in to Launchpad.')
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if not self.__lp:
|
||||
self.login()
|
||||
return getattr(self.__lp, attr)
|
||||
def login_anonymously(self):
|
||||
'''Enforce an anonymous login.'''
|
||||
if '_Launchpad__lp' not in self.__dict__:
|
||||
self.__lp = launchpad.Launchpad.login_anonymously('ubuntu-dev-tools', service)
|
||||
else:
|
||||
raise AlreadyLoggedInError('Already logged in to Launchpad.')
|
||||
|
||||
def __call__(self):
|
||||
return self
|
||||
def __getattr__(self, attr):
|
||||
if '_Launchpad__lp' not in self.__dict__:
|
||||
self.login()
|
||||
return getattr(self.__lp, attr)
|
||||
|
||||
def __call__(self):
|
||||
return self
|
||||
Launchpad = Launchpad()
|
||||
|
||||
|
||||
|
@ -13,3 +13,7 @@ class PocketDoesNotExistException(BaseException):
|
||||
class ArchiveNotFoundException(BaseException):
|
||||
""" Thrown when an archive for a distibution is not found """
|
||||
pass
|
||||
|
||||
class AlreadyLoggedInError(Exception):
|
||||
'''Raised when a second login is attempted.'''
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user