~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
17
 
19
18
import errno
20
19
import os
21
20
import shutil
22
21
 
23
22
from bzrlib import (
24
 
    controldir,
 
23
    bzrdir,
25
24
    errors,
26
25
    ui,
27
26
    )
28
27
from bzrlib.osutils import isdir
29
28
from bzrlib.trace import note
30
29
from bzrlib.workingtree import WorkingTree
31
 
from bzrlib.i18n import gettext
 
30
 
32
31
 
33
32
def is_detritus(subp):
34
33
    """Return True if the supplied path is detritus, False otherwise"""
60
59
            ignored=ignored, detritus=detritus))
61
60
        deletables = _filter_out_nested_bzrdirs(deletables)
62
61
        if len(deletables) == 0:
63
 
            note(gettext('Nothing to delete.'))
 
62
            note('Nothing to delete.')
64
63
            return 0
65
64
        if not no_prompt:
66
65
            for path, subp in deletables:
67
 
                ui.ui_factory.note(subp)
68
 
            prompt = gettext('Are you sure you wish to delete these')
69
 
            if not ui.ui_factory.get_boolean(prompt):
70
 
                ui.ui_factory.note(gettext('Canceled'))
 
66
                # FIXME using print is very bad idea
 
67
                # clean_tree should accept to_file argument to write the output
 
68
                print subp
 
69
            val = raw_input('Are you sure you wish to delete these [y/N]?')
 
70
            if val.lower() not in ('y', 'yes'):
 
71
                print 'Canceled'
71
72
                return 0
72
73
        delete_items(deletables, dry_run=dry_run)
73
74
    finally:
84
85
        # directory and therefore delete it. (worth to FIXME?)
85
86
        if isdir(path):
86
87
            try:
87
 
                controldir.ControlDir.open(path)
 
88
                bzrdir.BzrDir.open(path)
88
89
            except errors.NotBranchError:
89
90
                result.append((path,subp))
90
91
            else:
104
105
        # Other errors are re-raised.
105
106
        if function is not os.remove or excinfo[1].errno != errno.EACCES:
106
107
            raise
107
 
        ui.ui_factory.show_warning(gettext('unable to remove %s') % path)
 
108
        ui.ui_factory.show_warning('unable to remove %s' % path)
108
109
    has_deleted = False
109
110
    for path, subp in deletables:
110
111
        if not has_deleted:
111
 
            note(gettext("deleting paths:"))
 
112
            note("deleting paths:")
112
113
            has_deleted = True
113
114
        if not dry_run:
114
115
            if isdir(path):
121
122
                    # We handle only permission error here
122
123
                    if e.errno != errno.EACCES:
123
124
                        raise e
124
 
                    ui.ui_factory.show_warning(gettext(
125
 
                        'unable to remove "{0}": {1}.').format(
126
 
                                                    path, e.strerror))
 
125
                    ui.ui_factory.show_warning(
 
126
                        'unable to remove "%s": %s.' % (path, e.strerror))
127
127
        else:
128
128
            note('  ' + subp)
129
129
    if not has_deleted:
130
 
        note(gettext("No files deleted."))
 
130
        note("No files deleted.")