~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jeff Bailey
  • Date: 2005-06-08 22:30:34 UTC
  • Revision ID: jbailey@ppc64-20050608223034-3cbc9567103c4810
Add Debian directory

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
 
 
16
 
Option.OPTIONS['ignored'] = Option('ignored',
17
 
        help='delete all ignored files.')
18
 
Option.OPTIONS['detrius'] = Option('detrius',
19
 
        help='delete conflict files merge backups, and failed selftest dirs.' +
20
 
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
21
 
Option.OPTIONS['dry-run'] = Option('dry-run',
22
 
        help='show files to delete instead of deleting them.')
23
 
 
24
 
class cmd_clean_tree(bzrlib.commands.Command):
25
 
    """Remove unwanted files from working tree.
26
 
    Normally, ignored files are left alone.
27
 
    """
28
 
    takes_options = ['ignored', 'detrius', 'dry-run']
29
 
    def run(self, ignored=False, detrius=False, dry_run=False):
30
 
        from clean_tree import clean_tree
31
 
        clean_tree('.', ignored=ignored, detrius=detrius, dry_run=dry_run)
32
 
 
33
 
Option.OPTIONS['no-collapse'] = Option('no-collapse')
34
 
Option.OPTIONS['no-antialias'] = Option('no-antialias')
35
 
Option.OPTIONS['cluster'] = Option('cluster')
36
 
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
37
 
 
38
 
class cmd_graph_ancestry(bzrlib.commands.Command):
39
 
    """Produce ancestry graphs using dot.
40
 
    
41
 
    Output format is detected according to file extension.  Some of the more
42
 
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
43
 
    cause a dot graph file to be produced.
44
 
 
45
 
    Branches are labeled r?, where ? is the revno.  If they have no revno,
46
 
    with the last 5 characters of their revision identifier are used instead.
47
 
    
48
 
    If --merge-branch is specified, the two branches are compared and a merge
49
 
    base is selected.
50
 
    
51
 
    Legend:
52
 
    white    normal revision
53
 
    yellow   THIS  history
54
 
    red      OTHER history
55
 
    orange   COMMON history
56
 
    blue     COMMON non-history ancestor
57
 
    dotted   Missing from branch storage
58
 
 
59
 
    Ancestry is usually collapsed by removing revisions with a single parent
60
 
    and descendant.  The number of skipped revisions is shown on the arrow.
61
 
    This feature can be disabled with --no-collapse.
62
 
 
63
 
    By default, revisions are ordered by distance from root, but they can be
64
 
    clustered instead using --cluster.
65
 
 
66
 
    If available, rsvg is used to antialias PNG and JPEG output, but this can
67
 
    be disabled with --no-antialias.
68
 
    """
69
 
    takes_args = ['branch', 'file']
70
 
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
71
 
    def run(self, branch, file, no_collapse=False, no_antialias=False,
72
 
        merge_branch=None, cluster=False):
73
 
        import graph
74
 
        if cluster:
75
 
            ranking = "cluster"
76
 
        else:
77
 
            ranking = "forced"
78
 
        graph.write_ancestry_file(branch, file, not no_collapse, 
79
 
                                  not no_antialias, merge_branch, ranking)
80
 
 
81
 
class cmd_fetch_ghosts(bzrlib.commands.Command):
82
 
    """Attempt to retrieve ghosts from another branch.
83
 
    If the other branch is not supplied, the last-pulled branch is used.
84
 
    """
85
 
    aliases = ['fetch-missing']
86
 
    takes_args = ['branch?']
87
 
    def run(self, branch=None):
88
 
        from fetch_ghosts import fetch_ghosts
89
 
        fetch_ghosts(branch)
90
 
 
91
 
strip_help="""Strip the smallest prefix containing num leading slashes  from \
92
 
each file name found in the patch file."""
93
 
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
94
 
class cmd_patch(bzrlib.commands.Command):
95
 
    """Apply a named patch to the current tree.
96
 
    """
97
 
    takes_args = ['filename?']
98
 
    takes_options = ['strip']
99
 
    def run(self, filename=None, strip=0):
100
 
        from patch import patch
101
 
        from bzrlib.branch import Branch
102
 
        b = Branch.open_containing('.')[0]
103
 
        return patch(b, filename, strip)
104
 
 
105
 
 
106
 
class cmd_shelve(bzrlib.commands.Command):
107
 
    """Temporarily remove some changes from the current tree.
108
 
    Use 'unshelve' to restore these changes.
109
 
 
110
 
    If filenames are specified, only changes to those files will be unshelved.
111
 
    If a revision is specified, all changes since that revision will may be
112
 
    unshelved.
113
 
    """
114
 
    takes_args = ['file*']
115
 
    takes_options = ['all', 'message', 'revision']
116
 
    def run(self, all=False, file_list=None, message=None, revision=None):
117
 
        if file_list is not None and len(file_list) > 0:
118
 
            branchdir = file_list[0]
119
 
        else:
120
 
            branchdir = '.'
121
 
 
122
 
        if revision is not None and revision:
123
 
            if len(revision) == 1:
124
 
                revision = revision[0]
125
 
            else:
126
 
                raise BzrCommandError("shelve only accepts a single revision "
127
 
                                  "parameter.")
128
 
 
129
 
        s = Shelf(branchdir)
130
 
        return s.shelve(all, message, revision, file_list)
131
 
 
132
 
 
133
 
class cmd_unshelve(bzrlib.commands.Command):
134
 
    """Restore previously-shelved changes to the current tree.
135
 
    See also 'shelve'.
136
 
    """
137
 
    def run(self):
138
 
        s = Shelf('.')
139
 
        return s.unshelve()
140
 
 
141
 
class cmd_shell(bzrlib.commands.Command):
142
 
    def run(self):
143
 
        import shell
144
 
        shell.run_shell()
145
 
 
146
 
commands = [cmd_shelve, cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
147
 
            cmd_fetch_ghosts, cmd_patch, cmd_shell]
148
 
 
149
 
import bzrlib.builtins
150
 
if not hasattr(bzrlib.builtins, "cmd_annotate"):
151
 
    commands.append(annotate.cmd_annotate)
152
 
if not hasattr(bzrlib.builtins, "cmd_push"):
153
 
    commands.append(push.cmd_push)
154
 
 
155
 
from errors import NoPyBaz
156
 
try:
157
 
    import baz_import
158
 
    commands.append(baz_import.cmd_baz_import)
159
 
 
160
 
except NoPyBaz:
161
 
    class cmd_baz_import(bzrlib.commands.Command):
162
 
        """Disabled. (Requires PyBaz)"""
163
 
        takes_args = ['to_root_dir?', 'from_archive?']
164
 
        takes_options = ['verbose']
165
 
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
166
 
            print "This command is disabled.  Please install PyBaz."
167
 
    commands.append(cmd_baz_import)
168
 
 
169
 
if hasattr(bzrlib.commands, 'register_command'):
170
 
    for command in commands:
171
 
        bzrlib.commands.register_command(command)
172
 
 
173
 
def test_suite():
174
 
    from doctest import DocTestSuite
175
 
    from unittest import TestSuite, TestLoader
176
 
    import clean_tree
177
 
    import blackbox
178
 
    import shelf_tests
179
 
    result = TestSuite()
180
 
    result.addTest(DocTestSuite(bzrtools))
181
 
    result.addTest(clean_tree.test_suite())
182
 
    result.addTest(TestLoader().loadTestsFromModule(shelf_tests))
183
 
    result.addTest(blackbox.test_suite())
184
 
    return result