~lifeless/bzrtools/trunk

« back to all changes in this revision

Viewing changes to show_paths.py

  • Committer: Robert Collins
  • Date: 2008-07-08 04:11:21 UTC
  • mfrom: (623.1.33 bzrtools)
  • Revision ID: robertc@robertcollins.net-20080708041121-lo0k7os2y03uclt2
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
"""Show paths used by bzr itself and push/pull locations for current branch
4
 
Written by Alexander Belchenko, 2006
5
 
"""
6
 
 
7
 
from bzrlib.commands import register_command
8
 
from command import BzrToolsCommand
9
 
from bzrlib.option import Option
10
 
 
11
 
 
12
 
FORMAT = '%18s: %s'
13
 
 
14
 
 
15
 
def _bzr_system_info(to_file):
16
 
    import os
17
 
    import site
18
 
    import sys
19
 
 
20
 
    import bzrlib
21
 
    from bzrlib.config import config_dir
22
 
    from bzrlib import osutils
23
 
    from bzrlib.plugin import DEFAULT_PLUGIN_PATH
24
 
    from bzrlib import plugins
25
 
    from bzrlib import trace
26
 
 
27
 
    print >>to_file, FORMAT % ('Python interpreter', sys.executable)
28
 
    print >>to_file, FORMAT % ('Python library',
29
 
                               os.path.dirname(site.__file__))
30
 
 
31
 
    print >>to_file, FORMAT % ('bzr executable', osutils.realpath(sys.argv[0]))
32
 
    print >>to_file, FORMAT % ('bzrlib', osutils.realpath(bzrlib.__path__[0]))
33
 
 
34
 
    print >>to_file, FORMAT % ('bzr config dir', osutils.realpath(config_dir()))
35
 
 
36
 
    dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(os.pathsep)
37
 
    dirs.insert(0, os.path.dirname(plugins.__file__))
38
 
    if len(dirs) == 1:
39
 
        print >>to_file, FORMAT % ('bzr plugins dir', osutils.realpath(dirs[0]))
40
 
    else:
41
 
        print >>to_file, FORMAT % ('bzr plugins dirs', osutils.realpath(dirs[0]))
42
 
        for dir_ in dirs[1:]:
43
 
            print >>to_file, FORMAT % ('', osutils.realpath(dir_))
44
 
 
45
 
    print >>to_file, FORMAT % ('.bzr.log', osutils.realpath(trace._bzr_log_file.name))
46
 
#/def _bzr_system_info
47
 
 
48
 
 
49
 
class cmd_show_paths(BzrToolsCommand):
50
 
    """Show paths used by bzr itself and for current branch.
51
 
 
52
 
    The standard "bzr info" command now includes this functionality.
53
 
 
54
 
    If you run this command from branch you'll see
55
 
    saved path locations for current branch:
56
 
 
57
 
        * branch root - root directory of current branch
58
 
        * pull from   - default location for pull command
59
 
        * push to     - default location for push command
60
 
        * bound to    - for checkouts: location of repository branch
61
 
        * submit to   - default reference location for bundle generation
62
 
    """
63
 
 
64
 
    takes_options = [Option('system',
65
 
                            help='Show full bzr system information.'),
66
 
                    ]
67
 
    takes_args = ['branch?']
68
 
 
69
 
    hidden = True
70
 
 
71
 
    _see_also = ['info']
72
 
 
73
 
    def run(self, system=False, branch=u'.'):
74
 
        import sys
75
 
 
76
 
        from bzrlib.branch import Branch
77
 
        from bzrlib.errors import NotBranchError, NoWorkingTree
78
 
        from bzrlib import urlutils
79
 
        from bzrlib.workingtree import WorkingTree
80
 
 
81
 
        def local_path(path):
82
 
            if path.startswith("file://"):
83
 
                return urlutils.local_path_from_url(path)
84
 
            else:
85
 
                return urlutils.unescape(path)
86
 
 
87
 
        to_file = getattr(self, 'outf', sys.stdout)
88
 
 
89
 
        if system:
90
 
            print >>to_file, "*** Main bzr paths info ***"
91
 
            _bzr_system_info(to_file)
92
 
 
93
 
        try:
94
 
            branch = Branch.open_containing(branch)[0]
95
 
 
96
 
            if system:
97
 
                print >>to_file
98
 
            print >>to_file, "*** Current branch paths info ***"
99
 
 
100
 
            branch_root = branch.bzrdir.root_transport.base
101
 
            print >>to_file, FORMAT % ('branch root', local_path(branch_root))
102
 
 
103
 
            pull_loc = branch.get_parent() or 'None'
104
 
            print >>to_file, FORMAT % ('branch pull from', local_path(pull_loc))
105
 
 
106
 
            push_loc = branch.get_push_location() or 'None'
107
 
            print >>to_file, FORMAT % ('branch push to', local_path(push_loc))
108
 
 
109
 
            bound_loc = branch.get_bound_location() or 'None'
110
 
            print >>to_file, FORMAT % ('bound to branch', local_path(bound_loc))
111
 
 
112
 
            if hasattr(branch, 'get_submit_branch'):
113
 
                submit_loc = branch.get_submit_branch() or 'None'
114
 
                print >>to_file, FORMAT % ('submit to branch', local_path(submit_loc))
115
 
 
116
 
        except NotBranchError:
117
 
            if not system:
118
 
                raise
119
 
#/class cmd_show_paths
120
 
 
121
 
 
122
 
register_command(cmd_show_paths)