/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
 
 
21
19
# Importing this module will be expensive, since it imports launchpadlib and
22
20
# its dependencies. However, our plan is to only load this module when it is
23
21
# needed by a command that uses it.
24
22
 
25
23
 
26
 
import httplib2
27
24
import re
28
 
try:
29
 
    from urllib.parse import (
30
 
        urlparse,
31
 
        urlunparse,
32
 
        )
33
 
except ImportError:  # python < 3
34
 
    from urlparse import (
35
 
        urlparse,
36
 
        urlunparse,
37
 
        )
 
25
from urllib.parse import (
 
26
    urlparse,
 
27
    urlunparse,
 
28
    )
38
29
 
39
30
from ... import (
40
31
    branch,
41
 
    config,
 
32
    bedding,
42
33
    errors,
43
34
    osutils,
44
35
    trace,
45
36
    transport,
46
37
    )
47
38
from ...i18n import gettext
48
 
from .lp_registration import (
49
 
    InvalidLaunchpadInstance,
50
 
    )
 
39
 
 
40
 
 
41
class LaunchpadlibMissing(errors.DependencyNotPresent):
 
42
 
 
43
    _fmt = ("launchpadlib is required for Launchpad API access. "
 
44
            "Please install the launchpadlib package.")
 
45
 
 
46
    def __init__(self, e):
 
47
        super(LaunchpadlibMissing, self).__init__(
 
48
            'launchpadlib', e)
51
49
 
52
50
try:
53
51
    import launchpadlib
54
52
except ImportError as e:
55
 
    raise errors.DependencyNotPresent('launchpadlib', e)
 
53
    raise LaunchpadlibMissing(e)
56
54
 
 
55
from launchpadlib.credentials import RequestTokenAuthorizationEngine
57
56
from launchpadlib.launchpad import (
58
 
    STAGING_SERVICE_ROOT,
59
57
    Launchpad,
60
58
    )
61
59
from launchpadlib import uris
62
60
 
63
61
# 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)
 
62
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 3)
67
63
 
68
64
 
69
65
def get_cache_directory():
70
66
    """Return the directory to cache launchpadlib objects in."""
71
 
    return osutils.pathjoin(config.config_dir(), 'launchpad')
 
67
    return osutils.pathjoin(bedding.cache_dir(), 'launchpad')
72
68
 
73
69
 
74
70
def parse_launchpadlib_version(version_number):
96
92
        return staging_root.replace('staging', 'qastaging')
97
93
 
98
94
 
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
95
class NoLaunchpadBranch(errors.BzrError):
119
96
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
120
97
 
122
99
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
123
100
 
124
101
 
125
 
def login(service, timeout=None, proxy_info=None,
126
 
          version=Launchpad.DEFAULT_VERSION):
 
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
def connect_launchpad(base_url, timeout=None, proxy_info=None,
 
111
                      version=Launchpad.DEFAULT_VERSION):
127
112
    """Log in to the Launchpad API.
128
113
 
129
114
    :return: The root `Launchpad` object from launchpadlib.
130
115
    """
131
116
    if proxy_info is None:
 
117
        import httplib2
132
118
        proxy_info = httplib2.proxy_info_from_environment('https')
133
 
    cache_directory = get_cache_directory()
134
 
    launchpad = Launchpad.login_with(
135
 
        'bzr', _get_api_url(service), cache_directory, timeout=timeout,
 
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)
 
125
    return Launchpad.login_with(
 
126
        'breezy', base_url, cache_directory, timeout=timeout,
 
127
        credential_store=credential_store,
 
128
        authorization_engine=authorization_engine,
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):
206
196
    @staticmethod
207
197
    def tweak_url(url, launchpad):
208
198
        """Adjust a URL to work with staging, if needed."""
209
 
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
 
199
        if str(launchpad._root_uri) == uris.STAGING_SERVICE_ROOT:
210
200
            return url.replace('bazaar.launchpad.net',
211
201
                               'bazaar.staging.launchpad.net')
212
202
        elif str(launchpad._root_uri) == lookup_service_root('qastaging'):