19
from bzrlib.branch import Branch
21
def clean_tree(unknowns=True, ignored=False):
23
for subp in tree.extras():
24
if tree.is_ignored(subp):
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"""
28
return subp.endswith('.THIS') or subp.endswith('.BASE') or\
29
subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
32
def iter_deletables(tree, unknown=False, ignored=False, detritus=False):
33
"""Iterate through files that may be deleted"""
34
for subp in tree.extras():
35
if detritus and is_detritus(subp):
36
yield tree.abspath(subp), subp
38
if tree.is_ignored(subp):
40
yield tree.abspath(subp), subp
43
yield tree.abspath(subp), subp
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]
52
deletables = iter_deletables(tree, unknown=unknown, ignored=ignored,
54
delete_items(deletables, dry_run=dry_run)
59
def delete_items(deletables, dry_run=False):
60
"""Delete files in the deletables iterable"""
62
for path, subp in deletables:
64
note("deleting paths:")
30
yield tree.abspath(subp), subp
32
tree = br.working_tree()
34
for path, subp in deletables(tree):
36
print "deletings paths:"
42
if e.errno != errno.EISDIR:
73
note("No files deleted.")