~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to clean_tree.py

Merge from Aaron.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.branch import Branch
21
21
import sys
22
22
 
23
 
def is_detrius(subp):
 
23
def is_detritus(subp):
24
24
    return subp.endswith('.THIS') or subp.endswith('.BASE') or\
25
25
        subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
26
26
 
27
 
def iter_deletables(tree, unknown=True, ignored=False, detrius=False):
 
27
def iter_deletables(tree, unknown=True, ignored=False, detritus=False):
28
28
    """Iterate through files that may be deleted"""
29
29
    for subp in tree.extras():
30
 
        if detrius and is_detrius(subp):
 
30
        if detritus and is_detritus(subp):
31
31
            yield tree.abspath(subp), subp
32
32
            continue
33
33
        if tree.is_ignored(subp):
37
37
            if unknown:
38
38
                yield tree.abspath(subp), subp
39
39
 
40
 
def clean_tree(directory, ignored=False, detrius=False, dry_run=False,
 
40
def clean_tree(directory, ignored=False, detritus=False, dry_run=False,
41
41
               to_file=sys.stdout):
42
42
    br = Branch.open_containing(directory)[0]
43
43
    tree = br.working_tree()
44
 
    deletables = iter_deletables(tree, ignored=ignored, detrius=detrius)
 
44
    deletables = iter_deletables(tree, ignored=ignored, detritus=detritus)
45
45
    delete_items(deletables, dry_run=dry_run, to_file=to_file)
46
46
 
47
47
def delete_items(deletables, dry_run=False, to_file=sys.stdout):
91
91
            dels = [r for a,r in iter_deletables(tree)]
92
92
            assert 'file~' not in dels
93
93
            assert 'file.pyc' not in dels
94
 
            dels = [r for a,r in iter_deletables(tree, detrius=True)]
 
94
            dels = [r for a,r in iter_deletables(tree, detritus=True)]
95
95
            assert 'file~' in dels
96
96
            assert 'file.pyc' not in dels
97
97
            dels = [r for a,r in iter_deletables(tree, ignored=True)]