/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 brzlib/clean_tree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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
20
22
 
21
 
from . import (
 
23
from brzlib import (
22
24
    controldir,
23
25
    errors,
24
26
    ui,
25
27
    )
26
 
from .osutils import isdir
27
 
from .trace import note
28
 
from .workingtree import WorkingTree
29
 
from .i18n import gettext
30
 
 
 
28
from brzlib.osutils import isdir
 
29
from brzlib.trace import note
 
30
from brzlib.workingtree import WorkingTree
 
31
from brzlib.i18n import gettext
31
32
 
32
33
def is_detritus(subp):
33
34
    """Return True if the supplied path is detritus, False otherwise"""
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
 
113
117
                try:
114
118
                    os.unlink(path)
115
119
                    note('  ' + subp)
116
 
                except OSError as e:
 
120
                except OSError, e:
117
121
                    # We handle only permission error here
118
122
                    if e.errno != errno.EACCES:
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: