~abentley/bzrtools/bzrtools.dev

0.8.1 by Alexander Belchenko
first version
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
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
7
from bzrlib.commands import register_command
8
from command import BzrToolsCommand
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
9
from bzrlib.option import Option
10
11
0.8.7 by Alexander Belchenko
Change formatting
12
FORMAT = '%18s: %s'
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
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)
0.8.7 by Alexander Belchenko
Change formatting
28
    print >>to_file, FORMAT % ('Python library',
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
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
0.8.1 by Alexander Belchenko
first version
47
48
568 by Aaron Bentley
Don't check version when running non-bzrtools commands
49
class cmd_show_paths(BzrToolsCommand):
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
50
    """Show paths used by bzr itself and for current branch.
51
567 by Aaron Bentley
Hide show-paths command
52
    The standard "bzr info" command now includes this functionality.
53
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
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
557 by Aaron Bentley
Merge option help fixes from vila
64
    takes_options = [Option('system',
65
                            help='Show full bzr system information.'),
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
66
                    ]
528 by Aaron Bentley
Add branch parameter to show-paths
67
    takes_args = ['branch?']
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
68
567 by Aaron Bentley
Hide show-paths command
69
    hidden = True
70
71
    _see_also = ['info']
72
528 by Aaron Bentley
Add branch parameter to show-paths
73
    def run(self, system=False, branch=u'.'):
0.8.1 by Alexander Belchenko
first version
74
        import sys
75
76
        from bzrlib.branch import Branch
77
        from bzrlib.errors import NotBranchError, NoWorkingTree
0.8.4 by Alexander Belchenko
print local paths for branch without file:// prefix
78
        from bzrlib import urlutils
0.8.1 by Alexander Belchenko
first version
79
        from bzrlib.workingtree import WorkingTree
80
0.8.4 by Alexander Belchenko
print local paths for branch without file:// prefix
81
        def local_path(path):
82
            if path.startswith("file://"):
83
                return urlutils.local_path_from_url(path)
84
            else:
0.8.5 by Alexander Belchenko
show non-local URL unescaped
85
                return urlutils.unescape(path)
0.8.4 by Alexander Belchenko
print local paths for branch without file:// prefix
86
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
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)
0.8.1 by Alexander Belchenko
first version
92
93
        try:
528 by Aaron Bentley
Add branch parameter to show-paths
94
            branch = Branch.open_containing(branch)[0]
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
95
96
            if system:
97
                print >>to_file
98
            print >>to_file, "*** Current branch paths info ***"
0.8.3 by Alexander Belchenko
Show info about submit location (bundle mechanism)
99
100
            branch_root = branch.bzrdir.root_transport.base
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
101
            print >>to_file, FORMAT % ('branch root', local_path(branch_root))
0.8.2 by Alexander Belchenko
show bound info for branch
102
0.8.1 by Alexander Belchenko
first version
103
            pull_loc = branch.get_parent() or 'None'
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
104
            print >>to_file, FORMAT % ('branch pull from', local_path(pull_loc))
0.8.1 by Alexander Belchenko
first version
105
106
            push_loc = branch.get_push_location() or 'None'
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
107
            print >>to_file, FORMAT % ('branch push to', local_path(push_loc))
0.8.2 by Alexander Belchenko
show bound info for branch
108
109
            bound_loc = branch.get_bound_location() or 'None'
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
110
            print >>to_file, FORMAT % ('bound to branch', local_path(bound_loc))
0.8.2 by Alexander Belchenko
show bound info for branch
111
0.8.3 by Alexander Belchenko
Show info about submit location (bundle mechanism)
112
            if hasattr(branch, 'get_submit_branch'):
0.8.4 by Alexander Belchenko
print local paths for branch without file:// prefix
113
                submit_loc = branch.get_submit_branch() or 'None'
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
114
                print >>to_file, FORMAT % ('submit to branch', local_path(submit_loc))
0.8.3 by Alexander Belchenko
Show info about submit location (bundle mechanism)
115
0.8.1 by Alexander Belchenko
first version
116
        except NotBranchError:
0.8.6 by Alexander Belchenko
Added option '--system'; refactored a bit
117
            if not system:
118
                raise
119
#/class cmd_show_paths
0.8.1 by Alexander Belchenko
first version
120
121
122
register_command(cmd_show_paths)