19
from bzrlib.branch import Branch
21
from bzrlib.osutils import has_symlinks, isdir
22
from bzrlib.trace import note
23
from bzrlib.workingtree import WorkingTree
26
def is_detritus(subp):
27
"""Return True if the supplied path is detritus, False otherwise"""
22
28
return subp.endswith('.THIS') or subp.endswith('.BASE') or\
23
subp.endswith('.OTHER') or subp.endswith('~')
25
def iter_deletables(tree, unknowns=True, ignored=False, detrius=False):
29
subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
32
def iter_deletables(tree, unknown=False, ignored=False, detritus=False):
26
33
"""Iterate through files that may be deleted"""
27
34
for subp in tree.extras():
35
if detritus and is_detritus(subp):
29
36
yield tree.abspath(subp), subp
30
38
if tree.is_ignored(subp):
32
40
yield tree.abspath(subp), subp
35
43
yield tree.abspath(subp), subp
38
def clean_tree(deletables, dry_run=False):
46
def clean_tree(directory, unknown=False, ignored=False, detritus=False,
48
"""Remove files in the specified classes from the tree"""
49
tree = WorkingTree.open_containing(directory)[0]
50
deletables = iter_deletables(tree, unknown=unknown, ignored=ignored,
52
delete_items(deletables, dry_run=dry_run)
55
def delete_items(deletables, dry_run=False):
39
56
"""Delete files in the deletables iterable"""
41
58
for path, subp in deletables:
43
print "deleting paths:"
60
note("deleting paths:")
47
if os.path.isdir(path):
48
65
shutil.rmtree(path)
69
note("No files deleted.")