~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

  • Committer: Martin Pool
  • Date: 2010-01-29 14:09:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129140905-2uiarb6p8di1ywsr
Correction to url

from review: https://code.edge.launchpad.net/~mbp/bzr/doc/+merge/18250

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
 
18
import errno
18
19
import os
19
20
import shutil
 
21
import sys
20
22
 
21
 
from bzrlib import bzrdir, errors
22
 
from bzrlib.osutils import isdir
 
23
from bzrlib.osutils import has_symlinks, isdir
23
24
from bzrlib.trace import note
24
25
from bzrlib.workingtree import WorkingTree
25
26
 
52
53
    try:
53
54
        deletables = list(iter_deletables(tree, unknown=unknown,
54
55
            ignored=ignored, detritus=detritus))
55
 
        deletables = _filter_out_nested_bzrdirs(deletables)
56
56
        if len(deletables) == 0:
57
57
            note('Nothing to delete.')
58
58
            return 0
59
59
        if not no_prompt:
60
60
            for path, subp in deletables:
61
 
                # FIXME using print is very bad idea
62
 
                # clean_tree should accept to_file argument to write the output
63
61
                print subp
64
62
            val = raw_input('Are you sure you wish to delete these [y/N]?')
65
63
            if val.lower() not in ('y', 'yes'):
70
68
        tree.unlock()
71
69
 
72
70
 
73
 
def _filter_out_nested_bzrdirs(deletables):
74
 
    result = []
75
 
    for path, subp in deletables:
76
 
        # bzr won't recurse into unknowns/ignored directories by default
77
 
        # so we don't pay a penalty for checking subdirs of path for nested
78
 
        # bzrdir.
79
 
        # That said we won't detect the branch in the subdir of non-branch
80
 
        # directory and therefore delete it. (worth to FIXME?)
81
 
        if isdir(path):
82
 
            try:
83
 
                bzrdir.BzrDir.open(path)
84
 
            except errors.NotBranchError:
85
 
                result.append((path,subp))
86
 
            else:
87
 
                # TODO may be we need to notify user about skipped directories?
88
 
                pass
89
 
        else:
90
 
            result.append((path,subp))
91
 
    return result
92
 
 
93
 
 
94
71
def delete_items(deletables, dry_run=False):
95
72
    """Delete files in the deletables iterable"""
96
73
    has_deleted = False