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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import shutil
22
22
 
23
 
from . import (
 
23
from bzrlib import (
24
24
    controldir,
25
25
    errors,
26
26
    ui,
27
27
    )
28
 
from .osutils import isdir
29
 
from .trace import note
30
 
from .workingtree import WorkingTree
31
 
from .i18n import gettext
 
28
from bzrlib.osutils import isdir
 
29
from bzrlib.trace import note
 
30
from bzrlib.workingtree import WorkingTree
 
31
from bzrlib.i18n import gettext
32
32
 
33
33
def is_detritus(subp):
34
34
    """Return True if the supplied path is detritus, False otherwise"""
54
54
               dry_run=False, no_prompt=False):
55
55
    """Remove files in the specified classes from the tree"""
56
56
    tree = WorkingTree.open_containing(directory)[0]
57
 
    with tree.lock_read():
 
57
    tree.lock_read()
 
58
    try:
58
59
        deletables = list(iter_deletables(tree, unknown=unknown,
59
60
            ignored=ignored, detritus=detritus))
60
 
        deletables = _filter_out_nested_controldirs(deletables)
 
61
        deletables = _filter_out_nested_bzrdirs(deletables)
61
62
        if len(deletables) == 0:
62
63
            note(gettext('Nothing to delete.'))
63
64
            return 0
69
70
                ui.ui_factory.note(gettext('Canceled'))
70
71
                return 0
71
72
        delete_items(deletables, dry_run=dry_run)
72
 
 
73
 
 
74
 
def _filter_out_nested_controldirs(deletables):
 
73
    finally:
 
74
        tree.unlock()
 
75
 
 
76
 
 
77
def _filter_out_nested_bzrdirs(deletables):
75
78
    result = []
76
79
    for path, subp in deletables:
77
80
        # bzr won't recurse into unknowns/ignored directories by default
78
81
        # so we don't pay a penalty for checking subdirs of path for nested
79
 
        # control dir.
 
82
        # bzrdir.
80
83
        # That said we won't detect the branch in the subdir of non-branch
81
84
        # directory and therefore delete it. (worth to FIXME?)
82
85
        if isdir(path):
83
86
            try:
84
87
                controldir.ControlDir.open(path)
85
88
            except errors.NotBranchError:
86
 
                result.append((path, subp))
 
89
                result.append((path,subp))
87
90
            else:
88
91
                # TODO may be we need to notify user about skipped directories?
89
92
                pass
90
93
        else:
91
 
            result.append((path, subp))
 
94
            result.append((path,subp))
92
95
    return result
93
96
 
94
97
 
114
117
                try:
115
118
                    os.unlink(path)
116
119
                    note('  ' + subp)
117
 
                except OSError as e:
 
120
                except OSError, e:
118
121
                    # We handle only permission error here
119
122
                    if e.errno != errno.EACCES:
120
123
                        raise e