/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-01-24 20:24:41 UTC
  • mfrom: (7252 work)
  • mto: This revision was merged to the branch mainline in revision 7254.
  • Revision ID: jelmer@jelmer.uk-20190124202441-n0ukvy8tj64fok1a
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    transport,
46
46
    )
47
47
from ...i18n import gettext
48
 
from .lp_registration import (
49
 
    InvalidLaunchpadInstance,
50
 
    )
51
48
 
52
49
try:
53
50
    import launchpadlib
61
58
from launchpadlib import uris
62
59
 
63
60
# Declare the minimum version of launchpadlib that we need in order to work.
64
 
# 1.6.0 is the version of launchpadlib packaged in Ubuntu 10.04, the most
65
 
# recent Ubuntu LTS release supported on the desktop at the time of writing.
66
 
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 0)
 
61
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 3)
 
62
 
 
63
 
 
64
# We use production as the default because edge has been deprecated circa
 
65
# 2010-11 (see bug https://bugs.launchpad.net/bzr/+bug/583667)
 
66
DEFAULT_INSTANCE = 'production'
 
67
 
 
68
LAUNCHPAD_DOMAINS = {
 
69
    'production': 'launchpad.net',
 
70
    'staging': 'staging.launchpad.net',
 
71
    'qastaging': 'qastaging.launchpad.net',
 
72
    'demo': 'demo.launchpad.net',
 
73
    'dev': 'launchpad.dev',
 
74
    }
 
75
 
 
76
LAUNCHPAD_BAZAAR_DOMAINS = [
 
77
    'bazaar.%s' % domain
 
78
    for domain in LAUNCHPAD_DOMAINS.values()]
67
79
 
68
80
 
69
81
def get_cache_directory():
96
108
        return staging_root.replace('staging', 'qastaging')
97
109
 
98
110
 
99
 
def _get_api_url(service):
100
 
    """Return the root URL of the Launchpad API.
101
 
 
102
 
    e.g. For the 'staging' Launchpad service, this function returns
103
 
    launchpadlib.launchpad.STAGING_SERVICE_ROOT.
104
 
 
105
 
    :param service: A `LaunchpadService` object.
106
 
    :return: A URL as a string.
107
 
    """
108
 
    if service._lp_instance is None:
109
 
        lp_instance = service.DEFAULT_INSTANCE
110
 
    else:
111
 
        lp_instance = service._lp_instance
112
 
    try:
113
 
        return lookup_service_root(lp_instance)
114
 
    except ValueError:
115
 
        raise InvalidLaunchpadInstance(lp_instance)
116
 
 
117
 
 
118
111
class NoLaunchpadBranch(errors.BzrError):
119
112
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
120
113
 
122
115
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
123
116
 
124
117
 
125
 
def login(service, timeout=None, proxy_info=None,
126
 
          version=Launchpad.DEFAULT_VERSION):
 
118
def connect_launchpad(base_url, timeout=None, proxy_info=None,
 
119
                      version=Launchpad.DEFAULT_VERSION):
127
120
    """Log in to the Launchpad API.
128
121
 
129
122
    :return: The root `Launchpad` object from launchpadlib.
131
124
    if proxy_info is None:
132
125
        proxy_info = httplib2.proxy_info_from_environment('https')
133
126
    cache_directory = get_cache_directory()
134
 
    launchpad = Launchpad.login_with(
135
 
        'bzr', _get_api_url(service), cache_directory, timeout=timeout,
 
127
    return Launchpad.login_with(
 
128
        'breezy', base_url, cache_directory, timeout=timeout,
136
129
        proxy_info=proxy_info, version=version)
137
 
    # XXX: Work-around a minor security bug in launchpadlib < 1.6.3, which
138
 
    # would create this directory with default umask.
139
 
    osutils.chmod_if_possible(cache_directory, 0o700)
140
 
    return launchpad
 
130
 
141
131
 
142
132
 
143
133
class LaunchpadBranch(object):