~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to show_paths.py

  • Committer: Aaron Bentley
  • Date: 2008-05-12 18:06:07 UTC
  • Revision ID: aaron@aaronbentley.com-20080512180607-dn6a55if3pk4zdju
Update to avoid deprecated API

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, trace
 
79
        from bzrlib.workingtree import WorkingTree
 
80
        trace.warning('This command is obsolete.  Use "bzr info" instead.')
 
81
 
 
82
        def local_path(path):
 
83
            if path.startswith("file://"):
 
84
                return urlutils.local_path_from_url(path)
 
85
            else:
 
86
                return urlutils.unescape(path)
 
87
 
 
88
        to_file = getattr(self, 'outf', sys.stdout)
 
89
 
 
90
        if system:
 
91
            print >>to_file, "*** Main bzr paths info ***"
 
92
            _bzr_system_info(to_file)
 
93
 
 
94
        try:
 
95
            branch = Branch.open_containing(branch)[0]
 
96
 
 
97
            if system:
 
98
                print >>to_file
 
99
            print >>to_file, "*** Current branch paths info ***"
 
100
 
 
101
            branch_root = branch.bzrdir.root_transport.base
 
102
            print >>to_file, FORMAT % ('branch root', local_path(branch_root))
 
103
 
 
104
            pull_loc = branch.get_parent() or 'None'
 
105
            print >>to_file, FORMAT % ('branch pull from', local_path(pull_loc))
 
106
 
 
107
            push_loc = branch.get_push_location() or 'None'
 
108
            print >>to_file, FORMAT % ('branch push to', local_path(push_loc))
 
109
 
 
110
            bound_loc = branch.get_bound_location() or 'None'
 
111
            print >>to_file, FORMAT % ('bound to branch', local_path(bound_loc))
 
112
 
 
113
            if hasattr(branch, 'get_submit_branch'):
 
114
                submit_loc = branch.get_submit_branch() or 'None'
 
115
                print >>to_file, FORMAT % ('submit to branch', local_path(submit_loc))
 
116
 
 
117
        except NotBranchError:
 
118
            if not system:
 
119
                raise
 
120
#/class cmd_show_paths
 
121
 
 
122
 
 
123
register_command(cmd_show_paths)