~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-10-15 21:34:10 UTC
  • mto: This revision was merged to the branch mainline in revision 3791.
  • Revision ID: john@arbash-meinel.com-20081015213410-g19sy2rpgxcl2sew
Change the name to ChunkWriter.set_optimize()

Also allow it to be passed during __init__ and pass it in from
BTreeBuilder.

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 bzrlib import errors, trace
24
 
from bzrlib.config import AuthenticationConfig, GlobalConfig
 
23
from bzrlib import errors
 
24
from bzrlib.config import GlobalConfig
25
25
from bzrlib.transport import get_transport
26
26
 
27
27
 
36
36
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
37
37
 
38
38
 
39
 
class MismatchedUsernames(errors.BzrError):
40
 
 
41
 
    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
42
 
            ' account name.  Please re-run launchpad-login.')
43
 
 
44
 
 
45
39
def get_lp_login(_config=None):
46
 
    """Return the user's Launchpad username.
47
 
 
48
 
    :raises: MismatchedUsername if authentication.conf and bazaar.conf
49
 
        disagree about username.
50
 
    """
51
 
    if _config is None:
52
 
        _config = GlobalConfig()
53
 
 
54
 
    username = _config.get_user_option('launchpad_username')
55
 
    if username is not None:
56
 
        auth = AuthenticationConfig()
57
 
        auth_usernames = _get_auth_user(auth)
58
 
        for auth_username in auth_usernames.values():
59
 
            if auth_username is not None and auth_username != username:
60
 
                raise MismatchedUsernames()
61
 
        # Auto-upgrading
62
 
        if None in auth_usernames.values():
63
 
            trace.note('Setting ssh/sftp usernames for launchpad.net.')
64
 
            _set_auth_user(username, auth)
65
 
    return username
66
 
 
67
 
 
68
 
def _set_global_option(username, _config=None):
69
 
    if _config is None:
70
 
        _config = GlobalConfig()
71
 
    _config.set_user_option('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')
72
45
 
73
46
 
74
47
def set_lp_login(username, _config=None):
75
48
    """Set the user's Launchpad username"""
76
 
    _set_global_option(username, _config)
77
 
    _set_auth_user(username)
78
 
 
79
 
 
80
 
def _get_auth_user(auth=None):
81
 
    if auth is None:
82
 
        auth = AuthenticationConfig()
83
 
    return {'production': auth.get_user('ssh', 'bazaar.launchpad.net'),
84
 
            'staging': auth.get_user('ssh', 'bazaar.staging.launchpad.net'),}
85
 
 
86
 
def _set_auth_user(username, auth=None):
87
 
    if auth is None:
88
 
        auth = AuthenticationConfig()
89
 
    auth.set_credentials(
90
 
        'Launchpad', 'bazaar.launchpad.net', username, 'ssh')
91
 
    auth.set_credentials(
92
 
        'Launchpad Staging', 'bazaar.staging.launchpad.net', username, 'ssh')
 
49
    if _config is None:
 
50
        _config = GlobalConfig()
 
51
 
 
52
    _config.set_user_option('launchpad_username', username)
93
53
 
94
54
 
95
55
def check_lp_login(username, _transport=None):