~ubuntu-branches/debian/wheezy/lptools/wheezy

« back to all changes in this revision

Viewing changes to lptools/config.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2011-11-04 14:42:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20111104144229-brnisezz1ojeofwo
Tags: 0.0.1~bzr34-1
* New upstream snapshot.
* Switch from cdbs to new style debhelper.
* Switch to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Configuration glue for lptools."""
20
20
 
21
21
__all__ = [
 
22
    "data_dir",
22
23
    "ensure_dir",
23
24
    "get_launchpad",
24
25
    ]
25
26
 
 
27
import os
26
28
import os.path
27
29
 
28
30
from launchpadlib.launchpad import Launchpad
34
36
        os.makedirs(dir)
35
37
 
36
38
 
37
 
def get_launchpad(appname):
 
39
def get_launchpad(appname, instance=None):
38
40
    """Get a login to launchpad for lptools caching in cachedir.
39
 
    
 
41
 
40
42
    Note that caching is not multiple-process safe in launchpadlib,
41
43
    and the appname parameter is used to create per-app cachedirs.
42
44
 
43
45
    :param appname: The name of the app used to create per-app
44
46
        cachedirs.
45
 
    """
46
 
    return Launchpad.login_with("lptools-%s" % appname, "production")
 
47
    :param instance: Launchpad instance to use
 
48
    """
 
49
    if instance is None:
 
50
        instance = os.getenv("LPINSTANCE")
 
51
    if instance is None:
 
52
        instance = "production"
 
53
    return Launchpad.login_with("lptools-%s" % appname, instance)
 
54
 
 
55
 
 
56
def data_dir():
 
57
    """Return the arch-independent data directory.
 
58
    """
 
59
    # Running from source directory?
 
60
    ret = os.path.join(os.path.dirname(__file__), "..")
 
61
    if os.path.exists(os.path.join(ret, "templates")):
 
62
        return ret
 
63
    else:
 
64
        return os.path.abspath(os.path.join(os.path.dirname(__file__),
 
65
            "../../../../share/lptools"))