mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
* ubuntutools/lp/lpapiwrapper.py: Implement a singleton for LP API access (with lazy initialisation)
* ubuntutools/lp/functions.py: Use the new singleton
This commit is contained in:
parent
2ff5ec5ec0
commit
39211b67e0
@ -21,14 +21,12 @@
|
||||
import urllib2
|
||||
import sys
|
||||
from udtexceptions import PackageNotFoundException, SeriesNotFoundException
|
||||
import libsupport as lp_libsupport
|
||||
from lpapiwrapper import Launchpad
|
||||
import launchpadlib
|
||||
from re import findall
|
||||
|
||||
# Takes time to initialise - move to top level so we only pay the penalty
|
||||
# once. Should probably make this a proper class so we can instansiate
|
||||
# singleton-style (lazily).
|
||||
launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools")
|
||||
# Singleton to access LP API
|
||||
launchpad = Launchpad
|
||||
|
||||
def getUbuntuDistribution():
|
||||
ubuntu = launchpad.distributions['ubuntu']
|
||||
|
40
ubuntutools/lp/lpapiwrapper.py
Normal file
40
ubuntutools/lp/lpapiwrapper.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# lpapiwrapper.py - wrapper class around the LP API for use in the
|
||||
# ubuntu-dev-tools package
|
||||
#
|
||||
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 3
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# Please see the /usr/share/common-licenses/GPL file for the full text
|
||||
# of the GNU General Public License license.
|
||||
#
|
||||
# Based on code written by Jonathan Davies <jpds@ubuntu.com>
|
||||
|
||||
# Uncomment for tracing LP API calls
|
||||
#import httplib2
|
||||
#httplib2.debuglevel = 1
|
||||
|
||||
import libsupport
|
||||
|
||||
# Singleton for Launchpad API access
|
||||
class Launchpad(object):
|
||||
__lp = None
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if not self.__lp:
|
||||
self.__lp = libsupport.get_launchpad('ubuntu-dev-tools')
|
||||
return getattr(self.__lp, attr)
|
||||
|
||||
def __call__(self):
|
||||
return self
|
||||
Launchpad = Launchpad()
|
Loading…
x
Reference in New Issue
Block a user