~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Aaron Bentley
  • Date: 2005-10-24 04:39:58 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051024043958-1930eb2010b70a00
Added tests for patch and fetch-ghosts

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 = [push.cmd_push, shelf.cmd_shelve, 
 
105
            shelf.cmd_unshelve, cmd_clean_tree, cmd_graph_ancestry,
 
106
            cmd_fetch_ghosts, cmd_patch]
 
107
 
 
108
import bzrlib.builtins
 
109
if not hasattr(bzrlib.builtins, "cmd_annotate"):
 
110
    commands.append(annotate.cmd_annotate)
 
111
 
 
112
from errors import NoPyBaz
 
113
try:
 
114
    import baz_import
 
115
    commands.append(baz_import.cmd_baz_import)
 
116
 
 
117
except NoPyBaz:
 
118
    class cmd_baz_import(bzrlib.commands.Command):
 
119
        """Disabled. (Requires PyBaz)"""
 
120
        takes_args = ['to_root_dir?', 'from_archive?']
 
121
        takes_options = ['verbose']
 
122
        def run(self, to_root_dir=None, from_archive=None, verbose=False):
 
123
            print "This command is disabled.  Please install PyBaz."
 
124
    commands.append(cmd_baz_import)
 
125
 
 
126
if hasattr(bzrlib.commands, 'register_command'):
 
127
    for command in commands:
 
128
        bzrlib.commands.register_command(command)
 
129
 
 
130
def test_suite():
 
131
    from doctest import DocTestSuite
 
132
    from unittest import TestSuite
 
133
    import clean_tree
 
134
    import blackbox
 
135
    result = TestSuite()
 
136
    result.addTest(DocTestSuite(bzrtools))
 
137
    result.addTest(clean_tree.test_suite())
 
138
    result.addTest(blackbox.test_suite())
 
139
    return result