/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/lp_api.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tools for dealing with the Launchpad API."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# Importing this module will be expensive, since it imports launchpadlib and
20
22
# its dependencies. However, our plan is to only load this module when it is
21
23
# needed by a command that uses it.
22
24
 
23
25
 
24
26
import re
25
 
from urllib.parse import (
26
 
    urlparse,
27
 
    urlunparse,
28
 
    )
 
27
try:
 
28
    from urllib.parse import (
 
29
        urlparse,
 
30
        urlunparse,
 
31
        )
 
32
except ImportError:  # python < 3
 
33
    from urlparse import (
 
34
        urlparse,
 
35
        urlunparse,
 
36
        )
29
37
 
30
38
from ... import (
31
39
    branch,
32
 
    bedding,
 
40
    config,
33
41
    errors,
34
42
    osutils,
35
43
    trace,
52
60
except ImportError as e:
53
61
    raise LaunchpadlibMissing(e)
54
62
 
55
 
from launchpadlib.credentials import RequestTokenAuthorizationEngine
56
63
from launchpadlib.launchpad import (
57
64
    Launchpad,
58
65
    )
62
69
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 3)
63
70
 
64
71
 
 
72
# We use production as the default because edge has been deprecated circa
 
73
# 2010-11 (see bug https://bugs.launchpad.net/bzr/+bug/583667)
 
74
DEFAULT_INSTANCE = 'production'
 
75
 
 
76
LAUNCHPAD_DOMAINS = {
 
77
    'production': 'launchpad.net',
 
78
    'staging': 'staging.launchpad.net',
 
79
    'qastaging': 'qastaging.launchpad.net',
 
80
    'demo': 'demo.launchpad.net',
 
81
    'dev': 'launchpad.dev',
 
82
    }
 
83
 
 
84
LAUNCHPAD_BAZAAR_DOMAINS = [
 
85
    'bazaar.%s' % domain
 
86
    for domain in LAUNCHPAD_DOMAINS.values()]
 
87
 
 
88
 
65
89
def get_cache_directory():
66
90
    """Return the directory to cache launchpadlib objects in."""
67
 
    return osutils.pathjoin(bedding.cache_dir(), 'launchpad')
 
91
    return osutils.pathjoin(config.config_dir(), 'launchpad')
68
92
 
69
93
 
70
94
def parse_launchpadlib_version(version_number):
99
123
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
100
124
 
101
125
 
102
 
def get_auth_engine(base_url):
103
 
    return Launchpad.authorization_engine_factory(base_url, 'breezy')
104
 
 
105
 
 
106
 
def get_credential_store():
107
 
    return Launchpad.credential_store_factory(None)
108
 
 
109
 
 
110
126
def connect_launchpad(base_url, timeout=None, proxy_info=None,
111
127
                      version=Launchpad.DEFAULT_VERSION):
112
128
    """Log in to the Launchpad API.
116
132
    if proxy_info is None:
117
133
        import httplib2
118
134
        proxy_info = httplib2.proxy_info_from_environment('https')
119
 
    try:
120
 
        cache_directory = get_cache_directory()
121
 
    except EnvironmentError:
122
 
        cache_directory = None
123
 
    credential_store = get_credential_store()
124
 
    authorization_engine = get_auth_engine(base_url)
 
135
    cache_directory = get_cache_directory()
125
136
    return Launchpad.login_with(
126
137
        'breezy', base_url, cache_directory, timeout=timeout,
127
 
        credential_store=credential_store,
128
 
        authorization_engine=authorization_engine,
129
138
        proxy_info=proxy_info, version=version)
130
139
 
131
140