~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to clean_tree.py

  • Committer: Aaron Bentley
  • Date: 2005-10-29 04:53:42 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051029045342-5b7a8ebf57e3f713
ReleaseĀ 0.6

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_detritus(subp):
 
23
def is_detrius(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, detritus=False):
 
27
def iter_deletables(tree, unknown=True, ignored=False, detrius=False):
28
28
    """Iterate through files that may be deleted"""
29
29
    for subp in tree.extras():
30
 
        if detritus and is_detritus(subp):
 
30
        if detrius and is_detrius(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, detritus=False, dry_run=False,
 
40
def clean_tree(directory, ignored=False, detrius=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, detritus=detritus)
 
44
    deletables = iter_deletables(tree, ignored=ignored, detrius=detrius)
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):
60
60
    if not has_deleted:
61
61
        print >> to_file, "No files deleted."
62
62
def test_suite():
63
 
    from bzrlib.tests import TestCaseInTempDir
 
63
    from bzrlib.selftest import TestCaseInTempDir
64
64
    from unittest import makeSuite
65
65
    import os.path
66
66
    from StringIO import StringIO
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, detritus=True)]
 
94
            dels = [r for a,r in iter_deletables(tree, detrius=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)]