~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""\
Various useful plugins for working with bzr.
"""
import bzrlib.commands
import push
import annotate
import shelf
import conflicts
import sys
import os.path
sys.path.append(os.path.dirname(__file__))

bzrlib.commands.OPTIONS['ignored'] = None

class cmd_clean_tree(bzrlib.commands.Command):
    """Remove unwanted files from working tree.
    Normally, ignored files are left alone.  The --ignored flag will cause them
    to be deleted as well.
    """
    takes_options = ['ignored']
    def run(self, ignored=False):
        import clean_tree
        clean_tree.clean_tree(ignored=ignored)

class cmd_conflicted(bzrlib.commands.Command):
    """List files that have conflicts
    """
    takes_options = ['ignored']
    def run(self, ignored=False):
        import clean_tree
        clean_tree.clean_tree(ignored=ignored)

bzrlib.commands.OPTIONS['no-collapse'] = None
bzrlib.commands.OPTIONS['no-antialias'] = None

class cmd_graph_ancestry(bzrlib.commands.Command):
    """Produce ancestry graphs using dot.
    
    Output format is detected according to file extension.  Some of the more
    common output formats are png, gif, svg, ps.  An extension of '.dot' will
    cause a dot graph file to be produced.

    Ancestry is usually collapsed by removing nodes with a single parent
    and descendant, but this can be disabled with --no-collapse.

    The current branch's revisions are yellow and labeled R?, where ? is
    the revno.  Other revisions are labeled with essentially random numbers.

    Revisions that are not in branch storage have dotted outlines.

    rsvg is used to antialias PNG and JPEG output, but this can be disabled
    with --no-antialias.
    """
    takes_args = ['branch', 'file']
    takes_options = ['no-collapse', 'no-antialias']
    def run(self, branch, file, no_collapse=False, no_antialias=False):
        import graph
        graph.write_ancestry_file(branch, file, not no_collapse, 
                                  not no_antialias)

class cmd_fetch_missing(bzrlib.commands.Command):
    """Attempt to retrieve missing ancestors from another branch.
    If the other branch is not supplied, the last-pulled branch is used.
    """
    takes_args = ['branch?']
    def run(self, branch=None):
        from fetch_missing import fetch_missing
        fetch_missing(branch)

class cmd_patch(bzrlib.commands.Command):
    """Apply a named patch to the current tree.
    """
    takes_args = ['filename?']
    takes_options = ['strip']
    def run(self, filename=None, strip=0):
        from patch import patch
        from bzrlib.branch import Branch
        b = Branch('.', find_root=True)
        return patch(b, filename, strip)



commands = [push.cmd_push, annotate.cmd_annotate, shelf.cmd_shelve, 
            shelf.cmd_unshelve, cmd_clean_tree, conflicts.cmd_conflicts,
            conflicts.cmd_resolve, cmd_graph_ancestry, cmd_fetch_missing,
            cmd_patch]
from errors import NoPyBaz
try:
    import baz_import
    commands.append(baz_import.cmd_baz_import_branch)
    commands.append(baz_import.cmd_baz_import)

except NoPyBaz:
    class cmd_baz_import(bzrlib.commands.Command):
        """Disabled. (Requires PyBaz)"""
    commands.append(cmd_baz_import)

if hasattr(bzrlib.commands, 'register_command'):
    for command in commands:
        bzrlib.commands.register_command(command)

def test_suite():
    import baz_import
    import tests
    from doctest import DocTestSuite
    from unittest import TestSuite
    result = TestSuite()
    result.addTest(DocTestSuite(bzrtools))
    result.addTest(DocTestSuite(baz_import))
    result.addTest(tests.test_suite())
    return result