~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2005-11-29 16:19:01 UTC
  • Revision ID: abentley@panoramicfeedback.com-20051129161901-45074607ac3a37a6
Updated help

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