1
# Copyright (C) 2005 by Aaron Bentley
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from bzrlib.osutils import has_symlinks, isdir
22
from bzrlib.workingtree import WorkingTree
25
def is_detritus(subp):
26
"""Return True if the supplied path is detritus, False otherwise"""
27
return subp.endswith('.THIS') or subp.endswith('.BASE') or\
28
subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
31
def iter_deletables(tree, unknown=False, ignored=False, detritus=False):
32
"""Iterate through files that may be deleted"""
33
for subp in tree.extras():
34
if detritus and is_detritus(subp):
35
yield tree.abspath(subp), subp
37
if tree.is_ignored(subp):
39
yield tree.abspath(subp), subp
42
yield tree.abspath(subp), subp
45
def clean_tree(directory, out=sys.stdout, unknown=False, ignored=False,
46
detritus=False, dry_run=False):
47
"""Remove files in the specified classes from the tree"""
48
tree = WorkingTree.open_containing(directory)[0]
51
deletables = iter_deletables(tree, unknown=unknown, ignored=ignored,
53
delete_items(deletables, dry_run=dry_run)
58
def delete_items(deletables, out=sys.stdout, dry_run=False):
59
"""Delete files in the deletables iterable"""
61
for path, subp in deletables:
63
print >>out, "deleting paths:"
65
print >>out, ' ' + subp
72
print >>out, "No files deleted."