~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2005-12-03 20:42:25 UTC
  • mfrom: (147.4.25 trunk)
  • mto: (147.4.27 trunk)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: aaron.bentley@utoronto.ca-20051203204225-25678bc921de4fc1
MergeĀ fromĀ lifeless

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
"""\
 
3
Various useful plugins for working with bzr.
 
4
"""
 
5
import bzrlib.commands
 
6
import push
 
7
import annotate
 
8
from shelf import Shelf
 
9
import sys
 
10
import os.path
 
11
from bzrlib.option import Option
 
12
import bzrlib.branch
 
13
from bzrlib.errors import BzrCommandError
 
14
from reweave_inventory import cmd_fix
 
15
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), 
 
16
                                                 "external")))
 
17
 
 
18
Option.OPTIONS['ignored'] = Option('ignored',
 
19
        help='delete all ignored files.')
 
20
Option.OPTIONS['detritus'] = Option('detritus',
 
21
        help='delete conflict files merge backups, and failed selftest dirs.' +
 
22
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
 
23
Option.OPTIONS['dry-run'] = Option('dry-run',
 
24
        help='show files to delete instead of deleting them.')
 
25
 
 
26
class cmd_clean_tree(bzrlib.commands.Command):
 
27
    """Remove unwanted files from working tree.
 
28
    Normally, ignored files are left alone.
 
29
    """
 
30
    takes_options = ['ignored', 'detritus', 'dry-run']
 
31
    def run(self, ignored=False, detritus=False, dry_run=False):
 
32
        from clean_tree import clean_tree
 
33
        clean_tree('.', ignored=ignored, detritus=detritus, dry_run=dry_run)
 
34
 
 
35
Option.OPTIONS['no-collapse'] = Option('no-collapse')
 
36
Option.OPTIONS['no-antialias'] = Option('no-antialias')
 
37
Option.OPTIONS['cluster'] = Option('cluster')
 
38
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
 
39
 
 
40
class cmd_graph_ancestry(bzrlib.commands.Command):
 
41
    """Produce ancestry graphs using dot.
 
42
    
 
43
    Output format is detected according to file extension.  Some of the more
 
44
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
 
45
    cause a dot graph file to be produced.
 
46
 
 
47
    Branches are labeled r?, where ? is the revno.  If they have no revno,
 
48
    with the last 5 characters of their revision identifier are used instead.
 
49
    
 
50
    If --merge-branch is specified, the two branches are compared and a merge
 
51
    base is selected.
 
52
    
 
53
    Legend:
 
54
    white    normal revision
 
55
    yellow   THIS  history
 
56
    red      OTHER history
 
57
    orange   COMMON history
 
58
    blue     COMMON non-history ancestor
 
59
    dotted   Missing from branch storage
 
60
 
 
61
    Ancestry is usually collapsed by removing revisions with a single parent
 
62
    and descendant.  The number of skipped revisions is shown on the arrow.
 
63
    This feature can be disabled with --no-collapse.
 
64
 
 
65
    By default, revisions are ordered by distance from root, but they can be
 
66
    clustered instead using --cluster.
 
67
 
 
68
    If available, rsvg is used to antialias PNG and JPEG output, but this can
 
69
    be disabled with --no-antialias.
 
70
    """
 
71
    takes_args = ['branch', 'file']
 
72
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
 
73
    def run(self, branch, file, no_collapse=False, no_antialias=False,
 
74
        merge_branch=None, cluster=False):
 
75
        import graph
 
76
        if cluster:
 
77
            ranking = "cluster"
 
78
        else:
 
79
            ranking = "forced"
 
80
        graph.write_ancestry_file(branch, file, not no_collapse, 
 
81
                                  not no_antialias, merge_branch, ranking)
 
82
 
 
83
class cmd_fetch_ghosts(bzrlib.commands.Command):
 
84
    """Attempt to retrieve ghosts from another branch.
 
85
    If the other branch is not supplied, the last-pulled branch is used.
 
86
    """
 
87
    aliases = ['fetch-missing']
 
88
    takes_args = ['branch?']
 
89
    takes_options = [Option('no-fix')]
 
90
    def run(self, branch=None, no_fix=False):
 
91
        from fetch_ghosts import fetch_ghosts
 
92
        fetch_ghosts(branch, no_fix)
 
93
 
 
94
strip_help="""Strip the smallest prefix containing num leading slashes  from \
 
95
each file name found in the patch file."""
 
96
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
 
97
class cmd_patch(bzrlib.commands.Command):
 
98
    """Apply a named patch to the current tree.
 
99
    """
 
100
    takes_args = ['filename?']
 
101
    takes_options = ['strip']
 
102
    def run(self, filename=None, strip=0):
 
103
        from patch import patch
 
104
        from bzrlib.branch import Branch
 
105
        b = Branch.open_containing('.')[0]
 
106
        return patch(b, filename, strip)
 
107
 
 
108
 
 
109
class cmd_shelve(bzrlib.commands.Command):
 
110
    """Temporarily remove some changes from the current tree.
 
111
    Use 'unshelve' to restore these changes.
 
112
 
 
113
    If filenames are specified, only changes to those files will be unshelved.
 
114
    If a revision is specified, all changes since that revision will may be
 
115
    unshelved.
 
116
    """
 
117
    takes_args = ['file*']
 
118
    takes_options = ['all', 'message', 'revision']
 
119
    def run(self, all=False, file_list=None, message=None, revision=None):
 
120
        if file_list is not None and len(file_list) > 0:
 
121
            branchdir = file_list[0]
 
122
        else:
 
123
            branchdir = '.'
 
124
 
 
125
        if revision is not None and revision:
 
126
            if len(revision) == 1:
 
127
                revision = revision[0]
 
128
            else:
 
129
                raise BzrCommandError("shelve only accepts a single revision "
 
130
                                  "parameter.")
 
131
 
 
132
        s = Shelf(branchdir)
 
133
        return s.shelve(all, message, revision, file_list)
 
134
 
 
135
 
 
136
class cmd_unshelve(bzrlib.commands.Command):
 
137
    """Restore previously-shelved changes to the current tree.
 
138
    See also 'shelve'.
 
139
    """
 
140
    def run(self):
 
141
        s = Shelf('.')
 
142
        return s.unshelve()
 
143
 
 
144
class cmd_shell(bzrlib.commands.Command):
 
145
    """Begin an interactive shell tailored for bzr.
 
146
    Bzr commands can be used without typing bzr first, and will be run natively
 
147
    when possible.  Tab completion is tailored for bzr.  The shell prompt shows
 
148
    the branch nick, revno, and path.
 
149
 
 
150
    If it encounters any moderately complicated shell command, it will punt to
 
151
    the system shell.
 
152
 
 
153
    Example:
 
154
    $ bzr shell
 
155
    bzr bzrtools:287/> status
 
156
    modified:
 
157
      __init__.py
 
158
    bzr bzrtools:287/> status --[TAB][TAB]
 
159
    --all        --help       --revision   --show-ids
 
160
    bzr bzrtools:287/> status --
 
161
    """
 
162
    def run(self):
 
163
        import shell
 
164
        return shell.run_shell()
 
165
 
 
166
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
 
167
            cmd_fetch_ghosts, cmd_patch, cmd_shell, cmd_fix]
 
168
 
 
169
command_decorators = []
 
170
 
 
171
command_decorators = []
 
172
 
 
173
import bzrlib.builtins
 
174
if not hasattr(bzrlib.builtins, "cmd_annotate"):
 
175
    commands.append(annotate.cmd_annotate)
 
176
if not hasattr(bzrlib.builtins, "cmd_push"):
 
177
    commands.append(push.cmd_push)
 
178
else:
 
179
    command_decorators.append(push.cmd_push)
 
180
 
 
181
from errors import NoPyBaz
 
182
try:
 
183
    import baz_import
 
184
    commands.append(baz_import.cmd_baz_import_branch)
 
185
    commands.append(baz_import.cmd_baz_import)
 
186
 
 
187
except NoPyBaz:
 
188
    class cmd_baz_import(bzrlib.commands.Command):
 
189
        """Disabled. (Requires PyBaz)"""
 
190
        takes_args = ['to_root_dir?', 'from_archive?']
 
191
        takes_options = ['verbose']
 
192
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
 
193
            print "This command is disabled.  Please install PyBaz."
 
194
    commands.append(cmd_baz_import)
 
195
 
 
196
 
 
197
if hasattr(bzrlib.commands, 'register_command'):
 
198
    for command in commands:
 
199
        bzrlib.commands.register_command(command)
 
200
    for command in command_decorators:
 
201
        command._original_command = bzrlib.commands.register_command(
 
202
            command, True)
 
203
 
 
204
 
 
205
def test_suite():
 
206
    import baz_import
 
207
    import tests
 
208
    from doctest import DocTestSuite
 
209
    from unittest import TestSuite, TestLoader
 
210
    import clean_tree
 
211
    import blackbox
 
212
    import shelf_tests
 
213
    result = TestSuite()
 
214
    result.addTest(DocTestSuite(bzrtools))
 
215
    result.addTest(clean_tree.test_suite())
 
216
    result.addTest(DocTestSuite(baz_import))
 
217
    result.addTest(tests.test_suite())
 
218
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
 
219
    result.addTest(blackbox.test_suite())
 
220
    return result