/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: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

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