/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-01-24 01:55:52 UTC
  • mfrom: (7240.5.8 lp-refactoring)
  • Revision ID: breezy.the.bot@gmail.com-20190124015552-2cofvorutfgmzlp6
Some refactoring of the Launchpad module, ahead of removing xmlrpc support.

Merged from https://code.launchpad.net/~jelmer/brz/lp-refactoring/+merge/361934

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
64
61
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 3)
65
62
 
66
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()]
 
79
 
 
80
 
67
81
def get_cache_directory():
68
82
    """Return the directory to cache launchpadlib objects in."""
69
83
    return osutils.pathjoin(config.config_dir(), 'launchpad')
94
108
        return staging_root.replace('staging', 'qastaging')
95
109
 
96
110
 
97
 
def _get_api_url(service):
98
 
    """Return the root URL of the Launchpad API.
99
 
 
100
 
    e.g. For the 'staging' Launchpad service, this function returns
101
 
    launchpadlib.launchpad.STAGING_SERVICE_ROOT.
102
 
 
103
 
    :param service: A `LaunchpadService` object.
104
 
    :return: A URL as a string.
105
 
    """
106
 
    if service._lp_instance is None:
107
 
        lp_instance = service.DEFAULT_INSTANCE
108
 
    else:
109
 
        lp_instance = service._lp_instance
110
 
    try:
111
 
        return lookup_service_root(lp_instance)
112
 
    except ValueError:
113
 
        raise InvalidLaunchpadInstance(lp_instance)
114
 
 
115
 
 
116
111
class NoLaunchpadBranch(errors.BzrError):
117
112
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
118
113
 
120
115
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
121
116
 
122
117
 
123
 
def login(service, timeout=None, proxy_info=None,
124
 
          version=Launchpad.DEFAULT_VERSION):
 
118
def connect_launchpad(base_url, timeout=None, proxy_info=None,
 
119
                      version=Launchpad.DEFAULT_VERSION):
125
120
    """Log in to the Launchpad API.
126
121
 
127
122
    :return: The root `Launchpad` object from launchpadlib.
130
125
        proxy_info = httplib2.proxy_info_from_environment('https')
131
126
    cache_directory = get_cache_directory()
132
127
    return Launchpad.login_with(
133
 
        'breezy', _get_api_url(service), cache_directory, timeout=timeout,
 
128
        'breezy', base_url, cache_directory, timeout=timeout,
134
129
        proxy_info=proxy_info, version=version)
135
130
 
136
131
 
 
132
 
137
133
class LaunchpadBranch(object):
138
134
    """Provide bzr and lp API access to a Launchpad branch."""
139
135