/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/account.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
than once for each place that needs to take it into account.
21
21
"""
22
22
 
23
 
from bzrlib import errors, trace
24
 
from bzrlib.config import AuthenticationConfig, GlobalConfig
25
 
from bzrlib.transport import get_transport
26
 
 
 
23
from ... import (
 
24
    errors,
 
25
    trace,
 
26
    transport,
 
27
    )
 
28
from ...config import AuthenticationConfig, GlobalStack
 
29
from ...i18n import gettext
27
30
 
28
31
LAUNCHPAD_BASE = 'https://launchpad.net/'
29
32
 
39
42
 
40
43
class MismatchedUsernames(errors.BzrError):
41
44
 
42
 
    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
 
45
    _fmt = ('breezy.conf and authentication.conf disagree about launchpad'
43
46
            ' account name.  Please re-run launchpad-login.')
44
47
 
45
48
 
46
49
def get_lp_login(_config=None):
47
50
    """Return the user's Launchpad username.
48
51
 
49
 
    :raises: MismatchedUsername if authentication.conf and bazaar.conf
 
52
    :raises: MismatchedUsername if authentication.conf and breezy.conf
50
53
        disagree about username.
51
54
    """
52
55
    if _config is None:
53
 
        _config = GlobalConfig()
 
56
        _config = GlobalStack()
54
57
 
55
 
    username = _config.get_user_option('launchpad_username')
 
58
    username = _config.get('launchpad_username')
56
59
    if username is not None:
57
60
        auth = AuthenticationConfig()
58
61
        auth_username = _get_auth_user(auth)
59
62
        # Auto-upgrading
60
63
        if auth_username is None:
61
 
            trace.note('Setting ssh/sftp usernames for launchpad.net.')
 
64
            trace.note(gettext('Setting ssh/sftp usernames for launchpad.net.'))
62
65
            _set_auth_user(username, auth)
63
66
        elif auth_username != username:
64
67
            raise MismatchedUsernames()
67
70
 
68
71
def _set_global_option(username, _config=None):
69
72
    if _config is None:
70
 
        _config = GlobalConfig()
71
 
    _config.set_user_option('launchpad_username', username)
 
73
        _config = GlobalStack()
 
74
    if username is None:
 
75
        _config.remove('launchpad_username')
 
76
    else:
 
77
        _config.set('launchpad_username', username)
72
78
 
73
79
 
74
80
def set_lp_login(username, _config=None):
75
81
    """Set the user's Launchpad username"""
76
82
    _set_global_option(username, _config)
77
 
    _set_auth_user(username)
 
83
    if username is not None:
 
84
        _set_auth_user(username)
78
85
 
79
86
 
80
87
def _get_auth_user(auth=None):
83
90
    username = auth.get_user('ssh', '.launchpad.net')
84
91
    return username
85
92
 
 
93
 
86
94
def _set_auth_user(username, auth=None):
87
95
    if auth is None:
88
96
        auth = AuthenticationConfig()
97
105
    uploaded SSH keys.
98
106
    """
99
107
    if _transport is None:
100
 
        _transport = get_transport(LAUNCHPAD_BASE)
 
108
        _transport = transport.get_transport_from_url(LAUNCHPAD_BASE)
101
109
 
102
110
    try:
103
111
        data = _transport.get_bytes('~%s/+sshkeys' % username)