~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-01 15:06:29 UTC
  • mto: (2172.3.1 bzr.73948)
  • mto: This revision was merged to the branch mainline in revision 2181.
  • Revision ID: v.ladeuil+lp@free.fr-20061201150629-zjd2an87u0r7nhhw
The tests that would have help avoid bug #73948 and all that mess :)

* bzrlib/transport/http/response.py:
(handle_response): Translate a 416 http error code into a bzr
exception.

* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPDefaultErrorHandler.http_error_default): Translate a 416 http
error code into a bzr exception.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): It could happen that pycrul
itself detect a short read.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._retry_get): New method, factorizing the retry
logic.
(HttpTransportBase.readv): We can have exception during the
initial GET worth degrading the range requirements (i.e. retrying
the GET request with either single or not ranges).

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_readv_short_read): InvalidRange can also be
raised.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer.test_readv_invalid_ranges): Was named
test_readv_short_read, the new name make the intent
clearer. Depending of the code path used (urllib or pycurl), both
exceptions can be raised.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.do_GET): If invalid ranges are
specified, returns a 416 instead of the whole file (both are valid
according to the RFC).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
import os
19
 
import shutil
20
 
 
21
 
from bzrlib.osutils import isdir
22
 
from bzrlib.trace import note
23
 
from bzrlib.workingtree import WorkingTree
24
 
 
25
 
 
26
 
def is_detritus(subp):
27
 
    """Return True if the supplied path is detritus, False otherwise"""
28
 
    return subp.endswith('.THIS') or subp.endswith('.BASE') or\
29
 
        subp.endswith('.OTHER') or subp.endswith('~') or subp.endswith('.tmp')
30
 
 
31
 
 
32
 
def iter_deletables(tree, unknown=False, ignored=False, detritus=False):
33
 
    """Iterate through files that may be deleted"""
34
 
    for subp in tree.extras():
35
 
        if detritus and is_detritus(subp):
36
 
            yield tree.abspath(subp), subp
37
 
            continue
38
 
        if tree.is_ignored(subp):
39
 
            if ignored:
40
 
                yield tree.abspath(subp), subp
41
 
        else:
42
 
            if unknown:
43
 
                yield tree.abspath(subp), subp
44
 
 
45
 
 
46
 
def clean_tree(directory, unknown=False, ignored=False, detritus=False,
47
 
               dry_run=False, no_prompt=False):
48
 
    """Remove files in the specified classes from the tree"""
49
 
    tree = WorkingTree.open_containing(directory)[0]
50
 
    tree.lock_read()
51
 
    try:
52
 
        deletables = list(iter_deletables(tree, unknown=unknown,
53
 
            ignored=ignored, detritus=detritus))
54
 
        if len(deletables) == 0:
55
 
            note('Nothing to delete.')
56
 
            return 0
57
 
        if not no_prompt:
58
 
            for path, subp in deletables:
59
 
                print subp
60
 
            val = raw_input('Are you sure you wish to delete these [y/N]?')
61
 
            if val.lower() not in ('y', 'yes'):
62
 
                print 'Canceled'
63
 
                return 0
64
 
        delete_items(deletables, dry_run=dry_run)
65
 
    finally:
66
 
        tree.unlock()
67
 
 
68
 
 
69
 
def delete_items(deletables, dry_run=False):
70
 
    """Delete files in the deletables iterable"""
71
 
    has_deleted = False
72
 
    for path, subp in deletables:
73
 
        if not has_deleted:
74
 
            note("deleting paths:")
75
 
            has_deleted = True
76
 
        note('  ' + subp)
77
 
        if not dry_run:
78
 
            if isdir(path):
79
 
                shutil.rmtree(path)
80
 
            else:
81
 
                os.unlink(path)
82
 
    if not has_deleted:
83
 
        note("No files deleted.")