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

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

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