mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-16 01:21:07 +00:00
Strip out old launchpad credential handling code
This commit is contained in:
parent
6bbdecfd7e
commit
755166deec
@ -26,62 +26,13 @@ import urllib
|
|||||||
import urlparse
|
import urlparse
|
||||||
import httplib2
|
import httplib2
|
||||||
|
|
||||||
try:
|
from launchpadlib.launchpad import Launchpad
|
||||||
from launchpadlib.credentials import Credentials
|
from launchpadlib.errors import HTTPError
|
||||||
from launchpadlib.launchpad import Launchpad
|
|
||||||
from launchpadlib.errors import HTTPError
|
|
||||||
except ImportError:
|
|
||||||
print ("Unable to import launchpadlib module, is python-launchpadlib "
|
|
||||||
"installed?")
|
|
||||||
sys.exit(1)
|
|
||||||
except:
|
|
||||||
Credentials = None
|
|
||||||
Launchpad = None
|
|
||||||
|
|
||||||
from ubuntutools.lp import (service, api_version)
|
from ubuntutools.lp import (service, api_version)
|
||||||
|
|
||||||
def find_credentials(consumer, files, level=None):
|
def get_launchpad(consumer, server=service, cache=None):
|
||||||
""" search for credentials matching 'consumer' in path for given access
|
return Launchpad.login_with(consumer, server, cache, version=api_version)
|
||||||
level. """
|
|
||||||
if Credentials is None:
|
|
||||||
raise ImportError
|
|
||||||
|
|
||||||
for f in files:
|
|
||||||
cred = Credentials()
|
|
||||||
try:
|
|
||||||
cred.load(open(f))
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
if cred.consumer.key == consumer:
|
|
||||||
return cred
|
|
||||||
|
|
||||||
raise IOError("No credentials found for '%s', please see the "
|
|
||||||
"manage-credentials manpage for help on how to create "
|
|
||||||
"one for this consumer." % consumer)
|
|
||||||
|
|
||||||
def get_credentials(consumer, cred_file=None, level=None):
|
|
||||||
files = list()
|
|
||||||
|
|
||||||
if cred_file:
|
|
||||||
files.append(cred_file)
|
|
||||||
|
|
||||||
if "LPCREDENTIALS" in os.environ:
|
|
||||||
files.append(os.environ["LPCREDENTIALS"])
|
|
||||||
|
|
||||||
files.append(os.path.join(os.getcwd(), "lp_credentials.txt"))
|
|
||||||
|
|
||||||
# Add all files which have our consumer name to file listing.
|
|
||||||
for x in glob.glob(os.path.expanduser("~/.cache/lp_credentials/%s*.txt" %
|
|
||||||
consumer)):
|
|
||||||
files.append(x)
|
|
||||||
|
|
||||||
return find_credentials(consumer, files, level)
|
|
||||||
|
|
||||||
def get_launchpad(consumer, server=service, cache=None,
|
|
||||||
cred_file=None, level=None):
|
|
||||||
credentials = get_credentials(consumer, cred_file, level)
|
|
||||||
cache = cache or os.environ.get("LPCACHE", None)
|
|
||||||
return Launchpad(credentials, server, cache, version=api_version)
|
|
||||||
|
|
||||||
def query_to_dict(query_string):
|
def query_to_dict(query_string):
|
||||||
result = dict()
|
result = dict()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user