/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/clean_tree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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
import errno
18
20
import os
19
21
import shutil
28
30
from .workingtree import WorkingTree
29
31
from .i18n import gettext
30
32
 
31
 
 
32
33
def is_detritus(subp):
33
34
    """Return True if the supplied path is detritus, False otherwise"""
34
35
    return subp.endswith('.THIS') or subp.endswith('.BASE') or\
53
54
               dry_run=False, no_prompt=False):
54
55
    """Remove files in the specified classes from the tree"""
55
56
    tree = WorkingTree.open_containing(directory)[0]
56
 
    with tree.lock_read():
 
57
    tree.lock_read()
 
58
    try:
57
59
        deletables = list(iter_deletables(tree, unknown=unknown,
58
 
                                          ignored=ignored, detritus=detritus))
59
 
        deletables = _filter_out_nested_controldirs(deletables)
 
60
            ignored=ignored, detritus=detritus))
 
61
        deletables = _filter_out_nested_bzrdirs(deletables)
60
62
        if len(deletables) == 0:
61
63
            note(gettext('Nothing to delete.'))
62
64
            return 0
68
70
                ui.ui_factory.note(gettext('Canceled'))
69
71
                return 0
70
72
        delete_items(deletables, dry_run=dry_run)
71
 
 
72
 
 
73
 
def _filter_out_nested_controldirs(deletables):
 
73
    finally:
 
74
        tree.unlock()
 
75
 
 
76
 
 
77
def _filter_out_nested_bzrdirs(deletables):
74
78
    result = []
75
79
    for path, subp in deletables:
76
80
        # bzr won't recurse into unknowns/ignored directories by default
77
81
        # so we don't pay a penalty for checking subdirs of path for nested
78
 
        # control dir.
 
82
        # bzrdir.
79
83
        # That said we won't detect the branch in the subdir of non-branch
80
84
        # directory and therefore delete it. (worth to FIXME?)
81
85
        if isdir(path):
82
86
            try:
83
87
                controldir.ControlDir.open(path)
84
88
            except errors.NotBranchError:
85
 
                result.append((path, subp))
 
89
                result.append((path,subp))
86
90
            else:
87
91
                # TODO may be we need to notify user about skipped directories?
88
92
                pass
89
93
        else:
90
 
            result.append((path, subp))
 
94
            result.append((path,subp))
91
95
    return result
92
96
 
93
97
 
119
123
                        raise e
120
124
                    ui.ui_factory.show_warning(gettext(
121
125
                        'unable to remove "{0}": {1}.').format(
122
 
                        path, e.strerror))
 
126
                                                    path, e.strerror))
123
127
        else:
124
128
            note('  ' + subp)
125
129
    if not has_deleted: