~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2005-10-24 04:59:56 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051024045956-a6b714339c805e75
Made push self-disable when bzr has a builtin push

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""\
 
2
Various useful plugins for working with bzr.
 
3
"""
 
4
import bzrlib.commands
 
5
import push
 
6
import annotate
 
7
import shelf
 
8
import sys
 
9
import os.path
 
10
from bzrlib.option import Option
 
11
sys.path.append(os.path.dirname(__file__))
 
12
 
 
13
Option.OPTIONS['ignored'] = Option('ignored',
 
14
        help='delete all ignored files.')
 
15
Option.OPTIONS['detrius'] = Option('detrius',
 
16
        help='delete conflict files merge backups, and failed selftest dirs.' +
 
17
              '(*.THIS, *.BASE, *.OTHER, *~, *.tmp')
 
18
Option.OPTIONS['dry-run'] = Option('dry-run',
 
19
        help='show files to delete instead of deleting them.')
 
20
 
 
21
class cmd_clean_tree(bzrlib.commands.Command):
 
22
    """Remove unwanted files from working tree.
 
23
    Normally, ignored files are left alone.
 
24
    """
 
25
    takes_options = ['ignored', 'detrius', 'dry-run']
 
26
    def run(self, ignored=False, detrius=False, dry_run=False):
 
27
        from clean_tree import clean_tree
 
28
        clean_tree('.', ignored=ignored, detrius=detrius, dry_run=dry_run)
 
29
 
 
30
Option.OPTIONS['no-collapse'] = Option('no-collapse')
 
31
Option.OPTIONS['no-antialias'] = Option('no-antialias')
 
32
Option.OPTIONS['cluster'] = Option('cluster')
 
33
Option.OPTIONS['merge-branch'] = Option('merge-branch',type=str)
 
34
 
 
35
class cmd_graph_ancestry(bzrlib.commands.Command):
 
36
    """Produce ancestry graphs using dot.
 
37
    
 
38
    Output format is detected according to file extension.  Some of the more
 
39
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
 
40
    cause a dot graph file to be produced.
 
41
 
 
42
    Branches are labeled r?, where ? is the revno.  If they have no revno,
 
43
    with the last 5 characters of their revision identifier are used instead.
 
44
    
 
45
    If --merge-branch is specified, the two branches are compared and a merge
 
46
    base is selected.
 
47
    
 
48
    Legend:
 
49
    white    normal revision
 
50
    yellow   THIS  history
 
51
    red      OTHER history
 
52
    orange   COMMON history
 
53
    blue     COMMON non-history ancestor
 
54
    dotted   Missing from branch storage
 
55
 
 
56
    Ancestry is usually collapsed by removing revisions with a single parent
 
57
    and descendant.  The number of skipped revisions is shown on the arrow.
 
58
    This feature can be disabled with --no-collapse.
 
59
 
 
60
    By default, revisions are ordered by distance from root, but they can be
 
61
    clustered instead using --cluster.
 
62
 
 
63
    If available, rsvg is used to antialias PNG and JPEG output, but this can
 
64
    be disabled with --no-antialias.
 
65
    """
 
66
    takes_args = ['branch', 'file']
 
67
    takes_options = ['no-collapse', 'no-antialias', 'merge-branch', 'cluster']
 
68
    def run(self, branch, file, no_collapse=False, no_antialias=False,
 
69
        merge_branch=None, cluster=False):
 
70
        import graph
 
71
        if cluster:
 
72
            ranking = "cluster"
 
73
        else:
 
74
            ranking = "forced"
 
75
        graph.write_ancestry_file(branch, file, not no_collapse, 
 
76
                                  not no_antialias, merge_branch, ranking)
 
77
 
 
78
class cmd_fetch_ghosts(bzrlib.commands.Command):
 
79
    """Attempt to retrieve ghosts from another branch.
 
80
    If the other branch is not supplied, the last-pulled branch is used.
 
81
    """
 
82
    aliases = ['fetch-missing']
 
83
    takes_args = ['branch?']
 
84
    def run(self, branch=None):
 
85
        from fetch_ghosts import fetch_ghosts
 
86
        fetch_ghosts(branch)
 
87
 
 
88
strip_help="""Strip the smallest prefix containing num leading slashes  from \
 
89
each file name found in the patch file."""
 
90
Option.OPTIONS['strip'] = Option('strip', type=int, help=strip_help)
 
91
class cmd_patch(bzrlib.commands.Command):
 
92
    """Apply a named patch to the current tree.
 
93
    """
 
94
    takes_args = ['filename?']
 
95
    takes_options = ['strip']
 
96
    def run(self, filename=None, strip=0):
 
97
        from patch import patch
 
98
        from bzrlib.branch import Branch
 
99
        b = Branch.open_containing('.')[0]
 
100
        return patch(b, filename, strip)
 
101
 
 
102
 
 
103
 
 
104
commands = [shelf.cmd_shelve, shelf.cmd_unshelve, cmd_clean_tree,
 
105
            cmd_graph_ancestry, cmd_fetch_ghosts, cmd_patch]
 
106
 
 
107
import bzrlib.builtins
 
108
if not hasattr(bzrlib.builtins, "cmd_annotate"):
 
109
    commands.append(annotate.cmd_annotate)
 
110
if not hasattr(bzrlib.builtins, "cmd_push"):
 
111
    commands.append(push.cmd_push)
 
112
 
 
113
from errors import NoPyBaz
 
114
try:
 
115
    import baz_import
 
116
    commands.append(baz_import.cmd_baz_import)
 
117
 
 
118
except NoPyBaz:
 
119
    class cmd_baz_import(bzrlib.commands.Command):
 
120
        """Disabled. (Requires PyBaz)"""
 
121
        takes_args = ['to_root_dir?', 'from_archive?']
 
122
        takes_options = ['verbose']
 
123
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
 
124
            print "This command is disabled.  Please install PyBaz."
 
125
    commands.append(cmd_baz_import)
 
126
 
 
127
if hasattr(bzrlib.commands, 'register_command'):
 
128
    for command in commands:
 
129
        bzrlib.commands.register_command(command)
 
130
 
 
131
def test_suite():
 
132
    from doctest import DocTestSuite
 
133
    from unittest import TestSuite
 
134
    import clean_tree
 
135
    import blackbox
 
136
    result = TestSuite()
 
137
    result.addTest(DocTestSuite(bzrtools))
 
138
    result.addTest(clean_tree.test_suite())
 
139
    result.addTest(blackbox.test_suite())
 
140
    return result