1
# Copyright (C) 2005 Canonical Ltd
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
from bzrlib.osutils import has_symlinks, isdir
24
from bzrlib.trace import note
25
from bzrlib.workingtree import WorkingTree
28
def is_detritus(subp):
29
"""Return True if the supplied path is detritus, False otherwise"""
30
return subp.endswith('.THIS') or subp.endswith('.BASE') or\
31
subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
34
def iter_deletables(tree, unknown=False, ignored=False, detritus=False):
35
"""Iterate through files that may be deleted"""
36
for subp in tree.extras():
37
if detritus and is_detritus(subp):
38
yield tree.abspath(subp), subp
40
if tree.is_ignored(subp):
42
yield tree.abspath(subp), subp
45
yield tree.abspath(subp), subp
48
def clean_tree(directory, unknown=False, ignored=False, detritus=False,
49
dry_run=False, no_prompt=False):
50
"""Remove files in the specified classes from the tree"""
51
tree = WorkingTree.open_containing(directory)[0]
54
deletables = list(iter_deletables(tree, unknown=unknown,
55
ignored=ignored, detritus=detritus))
56
if len(deletables) == 0:
57
note('Nothing to delete.')
60
for path, subp in deletables:
62
val = raw_input('Are you sure you wish to delete these [y/N]?')
63
if val.lower() not in ('y', 'yes'):
66
delete_items(deletables, dry_run=dry_run)
71
def delete_items(deletables, dry_run=False):
72
"""Delete files in the deletables iterable"""
74
for path, subp in deletables:
76
note("deleting paths:")
85
note("No files deleted.")