Merge lp:~jelmer/lptools/standard-login into lp:lptools

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Martin Pool
Approved revision: 25
Merged at revision: 26
Proposed branch: lp:~jelmer/lptools/standard-login
Merge into: lp:lptools
Diff against target: 71 lines (+8/-45)
1 file modified
lptools/config.py (+8/-45)
To merge this branch: bzr merge lp:~jelmer/lptools/standard-login
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+73122@code.launchpad.net

Description of the change

Use the standard Launchpad.login_with method to log in, and remove the related boiler plate code.

This means relying on a newer version of launchpadlib, which will make backporting of lptools harder. Is that a problem?

To post a comment you must log in.
lp:~jelmer/lptools/standard-login updated
25. By Jelmer Vernooij

Use production instance by default.

Revision history for this message
Martin Pool (mbp) wrote :

Hooray for removing duplicated code.

It might be worth checking there is a specific version check against lplib so that people will get a clean message if it's out of date.

I think the api changes in lplib will make it a bit hard to support multiple versions and I don't think it's a priority compared to just getting the code moving on the current version.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lptools/config.py'
2--- lptools/config.py 2010-02-20 04:46:06 +0000
3+++ lptools/config.py 2011-08-27 12:32:23 +0000
4@@ -21,17 +21,11 @@
5 __all__ = [
6 "ensure_dir",
7 "get_launchpad",
8- "lptools_cachedir",
9- "lptools_credentials_path",
10 ]
11
12 import os.path
13
14-from launchpadlib.credentials import Credentials
15-from launchpadlib.launchpad import EDGE_SERVICE_ROOT
16-from xdg.BaseDirectory import xdg_cache_home
17-
18-from lptools import launchpad
19+from launchpadlib.launchpad import Launchpad
20
21
22 def ensure_dir(dir):
23@@ -43,41 +37,10 @@
24 def get_launchpad(appname):
25 """Get a login to launchpad for lptools caching in cachedir.
26
27- Note that caching is not multiple-process safe in launchpadlib, and the
28- appname parameter is used to create per-app cachedirs.
29-
30- :param appname: The name of the app used to create per-app cachedirs.
31- """
32- cachedir = os.path.join(xdg_cache_home, appname)
33- ensure_dir(cachedir)
34- credspath = lptools_credentials_path()
35- if os.path.exists(credspath):
36- creds = Credentials()
37- with file(credspath) as f:
38- creds.load(f)
39- return launchpad.Launchpad(creds, EDGE_SERVICE_ROOT, cachedir)
40- else:
41- result = launchpad.Launchpad.get_token_and_login('lptools',
42- EDGE_SERVICE_ROOT, cachedir)
43- with file(credspath, "w") as f:
44- result.credentials.save(f)
45- return result
46-
47-
48-def lptools_cachedir():
49- """Return the cachedir for common lptools things.
50-
51- This is xdg_cache_home/lptools.
52- """
53- return os.path.join(xdg_cache_home, "lptools")
54-
55-
56-def lptools_credentials_path():
57- """Return the path to the lptools credentials file.
58-
59- This also ensures the path is usable by checking it's containing directory
60- exists.
61- """
62- cachedir = lptools_cachedir()
63- ensure_dir(cachedir)
64- return os.path.join(lptools_cachedir(), 'credentials')
65+ Note that caching is not multiple-process safe in launchpadlib,
66+ and the appname parameter is used to create per-app cachedirs.
67+
68+ :param appname: The name of the app used to create per-app
69+ cachedirs.
70+ """
71+ return Launchpad.login_with("lptools-%s" % appname, "production")

Subscribers

People subscribed via source and target branches