~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2008-03-20 15:10:05 UTC
  • mto: This revision was merged to the branch mainline in revision 3299.
  • Revision ID: john@arbash-meinel.com-20080320151005-z9lajjy69m20of17
uncommit --local in an unbound branch raises the same exception as commit --local

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 __future__ import absolute_import
 
23
from bzrlib import errors
 
24
from bzrlib.config import GlobalConfig
 
25
from bzrlib.transport import get_transport
24
26
 
25
 
from bzrlib import (
26
 
    errors,
27
 
    trace,
28
 
    transport,
29
 
    )
30
 
from bzrlib.config import AuthenticationConfig, GlobalStack
31
 
from bzrlib.i18n import gettext
32
27
 
33
28
LAUNCHPAD_BASE = 'https://launchpad.net/'
34
29
 
38
33
 
39
34
 
40
35
class NoRegisteredSSHKeys(errors.BzrError):
41
 
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad.\n" \
42
 
        "See <https://launchpad.net/people/+me>"
43
 
 
44
 
 
45
 
class MismatchedUsernames(errors.BzrError):
46
 
 
47
 
    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
48
 
            ' account name.  Please re-run launchpad-login.')
 
36
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
49
37
 
50
38
 
51
39
def get_lp_login(_config=None):
52
 
    """Return the user's Launchpad username.
53
 
 
54
 
    :raises: MismatchedUsername if authentication.conf and bazaar.conf
55
 
        disagree about username.
56
 
    """
57
 
    if _config is None:
58
 
        _config = GlobalStack()
59
 
 
60
 
    username = _config.get('launchpad_username')
61
 
    if username is not None:
62
 
        auth = AuthenticationConfig()
63
 
        auth_username = _get_auth_user(auth)
64
 
        # Auto-upgrading
65
 
        if auth_username is None:
66
 
            trace.note(gettext('Setting ssh/sftp usernames for launchpad.net.'))
67
 
            _set_auth_user(username, auth)
68
 
        elif auth_username != username:
69
 
            raise MismatchedUsernames()
70
 
    return username
71
 
 
72
 
 
73
 
def _set_global_option(username, _config=None):
74
 
    if _config is None:
75
 
        _config = GlobalStack()
76
 
    _config.set('launchpad_username', username)
 
40
    """Return the user's Launchpad username"""
 
41
    if _config is None:
 
42
        _config = GlobalConfig()
 
43
 
 
44
    return _config.get_user_option('launchpad_username')
77
45
 
78
46
 
79
47
def set_lp_login(username, _config=None):
80
48
    """Set the user's Launchpad username"""
81
 
    _set_global_option(username, _config)
82
 
    _set_auth_user(username)
83
 
 
84
 
 
85
 
def _get_auth_user(auth=None):
86
 
    if auth is None:
87
 
        auth = AuthenticationConfig()
88
 
    username = auth.get_user('ssh', '.launchpad.net')
89
 
    return username
90
 
 
91
 
def _set_auth_user(username, auth=None):
92
 
    if auth is None:
93
 
        auth = AuthenticationConfig()
94
 
    auth.set_credentials(
95
 
        'Launchpad', '.launchpad.net', username, 'ssh')
 
49
    if _config is None:
 
50
        _config = GlobalConfig()
 
51
 
 
52
    _config.set_user_option('launchpad_username', username)
96
53
 
97
54
 
98
55
def check_lp_login(username, _transport=None):
102
59
    uploaded SSH keys.
103
60
    """
104
61
    if _transport is None:
105
 
        _transport = transport.get_transport_from_url(LAUNCHPAD_BASE)
 
62
        _transport = get_transport(LAUNCHPAD_BASE)
106
63
 
107
64
    try:
108
65
        data = _transport.get_bytes('~%s/+sshkeys' % username)