~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/account.py

(vila) Empty arguments in EDITOR are now properly preserved. (Vincent
 Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Functions to manage the user's Launchpad user ID.
18
18
 
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 bzrlib import (
 
26
    errors,
 
27
    trace,
 
28
    transport,
 
29
    )
 
30
from bzrlib.config import AuthenticationConfig, GlobalStack
 
31
from bzrlib.i18n import gettext
27
32
 
28
33
LAUNCHPAD_BASE = 'https://launchpad.net/'
29
34
 
33
38
 
34
39
 
35
40
class NoRegisteredSSHKeys(errors.BzrError):
36
 
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
 
41
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad.\n" \
 
42
        "See <https://launchpad.net/people/+me>"
37
43
 
38
44
 
39
45
class MismatchedUsernames(errors.BzrError):
49
55
        disagree about username.
50
56
    """
51
57
    if _config is None:
52
 
        _config = GlobalConfig()
 
58
        _config = GlobalStack()
53
59
 
54
 
    username = _config.get_user_option('launchpad_username')
 
60
    username = _config.get('launchpad_username')
55
61
    if username is not None:
56
62
        auth = AuthenticationConfig()
57
63
        auth_username = _get_auth_user(auth)
58
64
        # Auto-upgrading
59
65
        if auth_username is None:
60
 
            trace.note('Setting ssh/sftp usernames for launchpad.net.')
 
66
            trace.note(gettext('Setting ssh/sftp usernames for launchpad.net.'))
61
67
            _set_auth_user(username, auth)
62
68
        elif auth_username != username:
63
69
            raise MismatchedUsernames()
66
72
 
67
73
def _set_global_option(username, _config=None):
68
74
    if _config is None:
69
 
        _config = GlobalConfig()
70
 
    _config.set_user_option('launchpad_username', username)
 
75
        _config = GlobalStack()
 
76
    _config.set('launchpad_username', username)
71
77
 
72
78
 
73
79
def set_lp_login(username, _config=None):
79
85
def _get_auth_user(auth=None):
80
86
    if auth is None:
81
87
        auth = AuthenticationConfig()
82
 
    return auth.get_user('ssh', '.launchpad.net')
 
88
    username = auth.get_user('ssh', '.launchpad.net')
 
89
    return username
83
90
 
84
91
def _set_auth_user(username, auth=None):
85
92
    if auth is None:
95
102
    uploaded SSH keys.
96
103
    """
97
104
    if _transport is None:
98
 
        _transport = get_transport(LAUNCHPAD_BASE)
 
105
        _transport = transport.get_transport_from_url(LAUNCHPAD_BASE)
99
106
 
100
107
    try:
101
108
        data = _transport.get_bytes('~%s/+sshkeys' % username)