/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/transport/fakenfs.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-02-04 17:41:12 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070204174112-iv6gxzinnjddlaxj
Add tests for redirection. Preserve transport decorations.

* bzrlib/tests/test_http.py:
(TestRedirections): new tests.

* bzrlib/tests/HttpServer.py:
(HttpServer): Make server host and port public once the socket
have been established.

* bzrlib/tests/HTTPTestUtil.py:
(RedirectRequestHandler, HTTPServerRedirecting): New http test
server for redirections. Only a whole host can be redirected, so
far.

* bzrlib/errors.py:
(RedirectRequested.__init__): Add a 'qual_proto' oso that
transport decorations can be transmitted to redirected transport.
(RedirectRequested._requalify_url,
RedirectRequested.get_source_url,
RedirectRequested.get_target_url): New methods providing fully
decorated urls.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): The redirection should preserve
transport decorations.
(BzrDirMetaFormat1): To be able to specialize bzr branches from
foreign branches, we need to register BzrDirMetaFormat1 as the
default control format (instead of BzrDirMetaFormat which is
abstract and can still be used by foreign branches).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Transport implementation that adapts another transport to look like NFS.
 
18
 
 
19
Currently this means that the rename() call will raise ResourceBusy when a
 
20
target path is a directory.
 
21
 
 
22
To get a fake nfs transport use get_transport('fakenfs+' + real_url)
 
23
"""
 
24
 
 
25
from stat import S_ISDIR
 
26
 
 
27
import bzrlib.errors as errors
 
28
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
 
29
 
 
30
 
 
31
class FakeNFSTransportDecorator(TransportDecorator):
 
32
    """A transport that behaves like NFS, for testing"""
 
33
 
 
34
    @classmethod
 
35
    def _get_url_prefix(self):
 
36
        """FakeNFS transports are identified by 'fakenfs+'"""
 
37
        return 'fakenfs+'
 
38
 
 
39
    def rename(self, rel_from, rel_to):
 
40
        """See Transport.rename().
 
41
 
 
42
        This variation on rename converts DirectoryNotEmpty and FileExists
 
43
        errors into ResourceBusy if the target is a directory.
 
44
        """
 
45
        try:
 
46
            self._decorated.rename(rel_from, rel_to)
 
47
        except (errors.DirectoryNotEmpty, errors.FileExists), e:
 
48
            # if this is a directory rename, raise
 
49
            # resourcebusy rather than DirectoryNotEmpty
 
50
            stat = self._decorated.stat(rel_to)
 
51
            if S_ISDIR(stat.st_mode):
 
52
                raise errors.ResourceBusy(rel_to)
 
53
            else:
 
54
                raise
 
55
 
 
56
 
 
57
class FakeNFSServer(DecoratorServer):
 
58
    """Server for the FakeNFSTransportDecorator for testing with."""
 
59
 
 
60
    def get_decorator_class(self):
 
61
        return FakeNFSTransportDecorator
 
62
 
 
63
 
 
64
def get_test_permutations():
 
65
    """Return the permutations to be used in testing."""
 
66
    return [(FakeNFSTransportDecorator, FakeNFSServer),
 
67
            ]