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.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,
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.")