3
0
mirror of https://git.launchpad.net/ubuntu-dev-tools synced 2025-03-14 08:31:13 +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:
Michael Bienia 2010-02-20 17:07:03 +01:00
parent 0dfe4b4731
commit 8c114519e8
2 changed files with 29 additions and 19 deletions

@ -26,6 +26,7 @@
import sys import sys
import launchpadlib.launchpad as launchpad
from launchpadlib.errors import HTTPError from launchpadlib.errors import HTTPError
from launchpadlib.uris import lookup_service_root from launchpadlib.uris import lookup_service_root
from lazr.restfulclient.resource import Entry from lazr.restfulclient.resource import Entry
@ -35,28 +36,33 @@ from ubuntutools.lp import service
from ubuntutools.lp.udtexceptions import * from ubuntutools.lp.udtexceptions import *
class Launchpad(object): class Launchpad(object):
''' Singleton for LP API access. ''' '''Singleton for LP API access.'''
__lp = None
def login(self): def login(self):
''' '''Enforce a non-anonymous login.'''
Enforce a login through the LP API. if '_Launchpad__lp' not in self.__dict__:
''' try:
if not self.__lp: self.__lp = libsupport.get_launchpad('ubuntu-dev-tools')
try: except IOError, error:
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools') print >> sys.stderr, 'E: %s' % error
except IOError, error: raise
print >> sys.stderr, 'E: %s' % error else:
raise error raise AlreadyLoggedInError('Already logged in to Launchpad.')
return self
def __getattr__(self, attr): def login_anonymously(self):
if not self.__lp: '''Enforce an anonymous login.'''
self.login() if '_Launchpad__lp' not in self.__dict__:
return getattr(self.__lp, attr) self.__lp = launchpad.Launchpad.login_anonymously('ubuntu-dev-tools', service)
else:
raise AlreadyLoggedInError('Already logged in to Launchpad.')
def __call__(self): def __getattr__(self, attr):
return self if '_Launchpad__lp' not in self.__dict__:
self.login()
return getattr(self.__lp, attr)
def __call__(self):
return self
Launchpad = Launchpad() Launchpad = Launchpad()

@ -13,3 +13,7 @@ class PocketDoesNotExistException(BaseException):
class ArchiveNotFoundException(BaseException): class ArchiveNotFoundException(BaseException):
""" Thrown when an archive for a distibution is not found """ """ Thrown when an archive for a distibution is not found """
pass pass
class AlreadyLoggedInError(Exception):
'''Raised when a second login is attempted.'''
pass