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,
47
dry_run=False, no_prompt=False):
48
"""Remove files in the specified classes from the tree"""
49
tree = WorkingTree.open_containing(directory)[0]
52
deletables = list(iter_deletables(tree, unknown=unknown,
53
ignored=ignored, detritus=detritus))
54
if len(deletables) == 0:
55
note('Nothing to delete.')
58
for path, subp in deletables:
60
val = raw_input('Are you sure you wish to delete these [y/N]?')
61
if val.lower() not in ('y', 'yes'):
64
delete_items(deletables, dry_run=dry_run)
69
def delete_items(deletables, dry_run=False):
70
"""Delete files in the deletables iterable"""
72
for path, subp in deletables:
74
note("deleting paths:")
83
note("No files deleted.")
32
tree = br.working_tree()
34
for path, subp in deletables(tree):
36
print "deleting paths:"
42
if e.errno != errno.EISDIR: