/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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
 
23
from __future__ import absolute_import
26
24
 
 
25
from ... import (
 
26
    errors,
 
27
    trace,
 
28
    transport,
 
29
    )
 
30
from ...config import AuthenticationConfig, GlobalStack
 
31
from ...i18n import gettext
27
32
 
28
33
LAUNCHPAD_BASE = 'https://launchpad.net/'
29
34
 
39
44
 
40
45
class MismatchedUsernames(errors.BzrError):
41
46
 
42
 
    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
 
47
    _fmt = ('breezy.conf and authentication.conf disagree about launchpad'
43
48
            ' account name.  Please re-run launchpad-login.')
44
49
 
45
50
 
46
51
def get_lp_login(_config=None):
47
52
    """Return the user's Launchpad username.
48
53
 
49
 
    :raises: MismatchedUsername if authentication.conf and bazaar.conf
 
54
    :raises: MismatchedUsername if authentication.conf and breezy.conf
50
55
        disagree about username.
51
56
    """
52
57
    if _config is None:
53
 
        _config = GlobalConfig()
 
58
        _config = GlobalStack()
54
59
 
55
 
    username = _config.get_user_option('launchpad_username')
 
60
    username = _config.get('launchpad_username')
56
61
    if username is not None:
57
62
        auth = AuthenticationConfig()
58
63
        auth_username = _get_auth_user(auth)
59
64
        # Auto-upgrading
60
65
        if auth_username is None:
61
 
            trace.note('Setting ssh/sftp usernames for launchpad.net.')
 
66
            trace.note(gettext('Setting ssh/sftp usernames for launchpad.net.'))
62
67
            _set_auth_user(username, auth)
63
68
        elif auth_username != username:
64
69
            raise MismatchedUsernames()
67
72
 
68
73
def _set_global_option(username, _config=None):
69
74
    if _config is None:
70
 
        _config = GlobalConfig()
71
 
    _config.set_user_option('launchpad_username', username)
 
75
        _config = GlobalStack()
 
76
    if username is None:
 
77
        _config.remove('launchpad_username')
 
78
    else:
 
79
        _config.set('launchpad_username', username)
72
80
 
73
81
 
74
82
def set_lp_login(username, _config=None):
75
83
    """Set the user's Launchpad username"""
76
84
    _set_global_option(username, _config)
77
 
    _set_auth_user(username)
 
85
    if username is not None:
 
86
        _set_auth_user(username)
78
87
 
79
88
 
80
89
def _get_auth_user(auth=None):
83
92
    username = auth.get_user('ssh', '.launchpad.net')
84
93
    return username
85
94
 
 
95
 
86
96
def _set_auth_user(username, auth=None):
87
97
    if auth is None:
88
98
        auth = AuthenticationConfig()
97
107
    uploaded SSH keys.
98
108
    """
99
109
    if _transport is None:
100
 
        _transport = get_transport(LAUNCHPAD_BASE)
 
110
        _transport = transport.get_transport_from_url(LAUNCHPAD_BASE)
101
111
 
102
112
    try:
103
113
        data = _transport.get_bytes('~%s/+sshkeys' % username)