/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/smart/bzrdir.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
17
17
"""Server-side bzrdir related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import branch, errors, repository, urlutils
 
20
from bzrlib import branch, errors, repository
21
21
from bzrlib.bzrdir import (
22
22
    BzrDir,
23
23
    BzrDirFormat,
34
34
class SmartServerRequestOpenBzrDir(SmartServerRequest):
35
35
 
36
36
    def do(self, path):
 
37
        from bzrlib.bzrdir import BzrDirFormat
37
38
        try:
38
39
            t = self.transport_from_client_path(path)
39
40
        except errors.PathNotChild:
55
56
        return SuccessfulSmartServerResponse((answer,))
56
57
 
57
58
 
58
 
class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
59
 
 
60
 
    def do(self, path):
61
 
        """Is there a BzrDir present, and if so does it have a working tree?
62
 
 
63
 
        New in 2.1.
64
 
        """
65
 
        try:
66
 
            t = self.transport_from_client_path(path)
67
 
        except errors.PathNotChild:
68
 
            # The client is trying to ask about a path that they have no access
69
 
            # to.
70
 
            return SuccessfulSmartServerResponse(('no',))
71
 
        try:
72
 
            bd = BzrDir.open_from_transport(t)
73
 
        except errors.NotBranchError:
74
 
            answer = ('no',)
75
 
        else:
76
 
            answer = ('yes',)
77
 
            if bd.has_workingtree():
78
 
                answer += ('yes',)
79
 
            else:
80
 
                answer += ('no',)
81
 
        return SuccessfulSmartServerResponse(answer)
82
 
 
83
 
 
84
59
class SmartServerRequestBzrDir(SmartServerRequest):
85
60
 
86
61
    def do(self, path, *args):
88
63
        try:
89
64
            self._bzrdir = BzrDir.open_from_transport(
90
65
                self.transport_from_client_path(path))
91
 
        except errors.NotBranchError, e:
92
 
            return FailedSmartServerResponse(('nobranch',))
 
66
        except errors.NotBranchError:
 
67
            return FailedSmartServerResponse(('nobranch', ))
93
68
        return self.do_bzrdir_request(*args)
94
69
 
95
70
    def _boolean_to_yes_no(self, a_boolean):
110
85
        """Get the relative path for repository from current_transport."""
111
86
        # the relpath of the bzrdir in the found repository gives us the
112
87
        # path segments to pop-out.
113
 
        relpath = repository.user_transport.relpath(
 
88
        relpath = repository.bzrdir.root_transport.relpath(
114
89
            current_transport.base)
115
90
        if len(relpath):
116
91
            segments = ['..'] * len(relpath.split('/'))
379
354
    def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
380
355
        force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
381
356
        make_working_trees, shared_repo):
382
 
        """Initialize a bzrdir at path as per
383
 
        BzrDirFormat.initialize_on_transport_ex.
384
 
 
385
 
        New in 1.16.  (Replaces BzrDirFormat.initialize_ex verb from 1.15).
386
 
 
387
 
        :return: return SuccessfulSmartServerResponse((repo_path, rich_root,
388
 
            tree_ref, external_lookup, repo_network_name,
389
 
            repo_bzrdir_network_name, bzrdir_format_network_name,
390
 
            NoneTrueFalse(stacking), final_stack, final_stack_pwd,
391
 
            repo_lock_token))
 
357
        """Initialize a bzrdir at path as per BzrDirFormat.initialize_ex
 
358
 
 
359
        :return: SmartServerResponse()
392
360
        """
393
361
        target_transport = self.transport_from_client_path(path)
394
362
        format = network_format_registry.get(bzrdir_network_name)
415
383
            repo_bzrdir_name = ''
416
384
            final_stack = None
417
385
            final_stack_pwd = None
418
 
            repo_lock_token = ''
419
386
        else:
420
387
            repo_path = self._repo_relpath(bzrdir.root_transport, repo)
421
388
            if repo_path == '':
426
393
            repo_bzrdir_name = repo.bzrdir._format.network_name()
427
394
            final_stack = repository_policy._stack_on
428
395
            final_stack_pwd = repository_policy._stack_on_pwd
429
 
            # It is returned locked, but we need to do the lock to get the lock
430
 
            # token.
431
 
            repo.unlock()
432
 
            repo_lock_token = repo.lock_write() or ''
433
 
            if repo_lock_token:
434
 
                repo.leave_lock_in_place()
435
 
            repo.unlock()
436
396
        final_stack = final_stack or ''
437
397
        final_stack_pwd = final_stack_pwd or ''
438
 
 
439
 
        # We want this to be relative to the bzrdir.
440
 
        if final_stack_pwd:
441
 
            final_stack_pwd = urlutils.relative_url(
442
 
                target_transport.base, final_stack_pwd)
443
 
 
444
 
        # Can't meaningfully return a root path.
445
 
        if final_stack.startswith('/'):
446
 
            client_path = self._root_client_path + final_stack[1:]
447
 
            final_stack = urlutils.relative_url(
448
 
                self._root_client_path, client_path)
449
 
            final_stack_pwd = '.'
450
 
 
451
398
        return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
452
399
            external_lookup, repo_name, repo_bzrdir_name,
453
400
            bzrdir._format.network_name(),
454
401
            self._serialize_NoneTrueFalse(stacking), final_stack,
455
 
            final_stack_pwd, repo_lock_token))
 
402
            final_stack_pwd))
456
403
 
457
404
 
458
405
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
465
412
                return SuccessfulSmartServerResponse(('ok', ''))
466
413
            else:
467
414
                return SuccessfulSmartServerResponse(('ok', reference_url))
468
 
        except errors.NotBranchError, e:
469
 
            return FailedSmartServerResponse(('nobranch',))
 
415
        except errors.NotBranchError:
 
416
            return FailedSmartServerResponse(('nobranch', ))
470
417
 
471
418
 
472
419
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
481
428
                return SuccessfulSmartServerResponse(('branch', format))
482
429
            else:
483
430
                return SuccessfulSmartServerResponse(('ref', reference_url))
484
 
        except errors.NotBranchError, e:
485
 
            return FailedSmartServerResponse(('nobranch',))
486
 
 
487
 
 
488
 
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
489
 
 
490
 
    def do_bzrdir_request(self):
491
 
        """Open a branch at path and return the reference or format.
492
 
        
493
 
        This version introduced in 2.1.
494
 
 
495
 
        Differences to SmartServerRequestOpenBranchV2:
496
 
          * can return 2-element ('nobranch', extra), where 'extra' is a string
497
 
            with an explanation like 'location is a repository'.  Previously
498
 
            a 'nobranch' response would never have more than one element.
499
 
        """
500
 
        try:
501
 
            reference_url = self._bzrdir.get_branch_reference()
502
 
            if reference_url is None:
503
 
                br = self._bzrdir.open_branch(ignore_fallbacks=True)
504
 
                format = br._format.network_name()
505
 
                return SuccessfulSmartServerResponse(('branch', format))
506
 
            else:
507
 
                return SuccessfulSmartServerResponse(('ref', reference_url))
508
 
        except errors.NotBranchError, e:
509
 
            # Stringify the exception so that its .detail attribute will be
510
 
            # filled out.
511
 
            str(e)
512
 
            resp = ('nobranch',)
513
 
            detail = e.detail
514
 
            if detail:
515
 
                if detail.startswith(': '):
516
 
                    detail = detail[2:]
517
 
                resp += (detail,)
518
 
            return FailedSmartServerResponse(resp)
519
 
 
 
431
        except errors.NotBranchError:
 
432
            return FailedSmartServerResponse(('nobranch', ))