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):
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):
36
30
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]
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):
56
"""Delete files in the deletables iterable"""
58
for path, subp in deletables:
60
note("deleting paths:")
69
note("No files deleted.")
31
br = Branch.open_containing('.')
32
tree = br.working_tree()
34
for path, subp in deletables(tree):
36
print "deleting paths:"
42
if e.errno != errno.EISDIR: