~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/readonly.py

  • Committer: Robert Collins
  • Date: 2006-03-28 14:29:13 UTC
  • mto: (1626.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1628.
  • Revision ID: robertc@robertcollins.net-20060328142913-ac5afb37075719c6
Convert log to use the new tsort.merge_sort routine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Implementation of Transport that adapts another transport to be readonly."""
18
18
 
19
19
from bzrlib.errors import TransportNotPossible
20
 
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
21
 
 
22
 
 
23
 
class ReadonlyTransportDecorator(TransportDecorator):
 
20
from bzrlib.transport import get_transport, Transport, Server
 
21
 
 
22
 
 
23
class ReadonlyTransportDecorator(Transport):
24
24
    """A decorator that can convert any transport to be readonly.
25
 
 
26
 
    This is requested via the 'readonly+' prefix to get_transport().
 
25
    
 
26
    This does not use __getattr__ hacks as we need to ensure that
 
27
    new writable methods are overridden correctly.
27
28
    """
28
29
 
 
30
    def __init__(self, url, _decorated=None):
 
31
        """Set the 'base' path where files will be stored.
 
32
        
 
33
        _decorated is a private parameter for cloning."""
 
34
        assert url.startswith('readonly+')
 
35
        decorated_url = url[len('readonly+'):]
 
36
        if _decorated is None:
 
37
            self._decorated = get_transport(decorated_url)
 
38
        else:
 
39
            self._decorated = _decorated
 
40
        super(ReadonlyTransportDecorator, self).__init__(
 
41
            "readonly+" + self._decorated.base)
 
42
 
 
43
    def clone(self, offset=None):
 
44
        """See Transport.clone()."""
 
45
        decorated_clone = self._decorated.clone(offset)
 
46
        return ReadonlyTransportDecorator("readonly+" + decorated_clone.base,
 
47
                                          decorated_clone)
 
48
 
 
49
    def abspath(self, relpath):
 
50
        """See Transport.abspath()."""
 
51
        return "readonly+" + self._decorated.abspath(relpath)
 
52
 
29
53
    def append(self, relpath, f):
30
54
        """See Transport.append()."""
31
55
        raise TransportNotPossible('readonly transport')
32
 
    
33
 
    @classmethod
34
 
    def _get_url_prefix(self):
35
 
        """Readonly transport decorators are invoked via 'readonly+'"""
36
 
        return 'readonly+'
 
56
 
 
57
    def has(self, relpath):
 
58
        """See Transport.has()."""
 
59
        return self._decorated.has(relpath)
37
60
 
38
61
    def delete(self, relpath):
39
62
        """See Transport.delete()."""
43
66
        """See Transport.delete_tree()."""
44
67
        raise TransportNotPossible('readonly transport')
45
68
 
 
69
    def get(self, relpath):
 
70
        """See Transport.get()."""
 
71
        return self._decorated.get(relpath)
 
72
 
46
73
    def put(self, relpath, f, mode=None):
47
74
        """See Transport.put()."""
48
75
        raise TransportNotPossible('readonly transport')
55
82
        """See Transport.is_readonly."""
56
83
        return True
57
84
 
 
85
    def listable(self):
 
86
        """See Transport.listable."""
 
87
        return self._decorated.listable()
 
88
 
 
89
    def iter_files_recursive(self):
 
90
        """See Transport.iter_files_recursive()."""
 
91
        return self._decorated.iter_files_recursive()
 
92
    
 
93
    def list_dir(self, relpath):
 
94
        """See Transport.list_dir()."""
 
95
        return self._decorated.list_dir(relpath)
 
96
    
58
97
    def rmdir(self, relpath):
59
98
        """See Transport.rmdir."""
60
99
        raise TransportNotPossible('readonly transport')
61
100
 
 
101
    def should_cache(self):
 
102
        """See Transport.should_cache()."""
 
103
        return self._decorated.should_cache()
 
104
 
 
105
    def stat(self, relpath):
 
106
        """See Transport.stat()."""
 
107
        return self._decorated.stat(relpath)
 
108
 
 
109
    def lock_read(self, relpath):
 
110
        """See Transport.lock_read."""
 
111
        return self._decorated.lock_read(relpath)
 
112
 
62
113
    def lock_write(self, relpath):
63
114
        """See Transport.lock_write."""
64
115
        raise TransportNotPossible('readonly transport')
65
116
 
66
117
 
67
 
class ReadonlyServer(DecoratorServer):
 
118
class ReadonlyServer(Server):
68
119
    """Server for the ReadonlyTransportDecorator for testing with."""
69
120
 
70
 
    def get_decorator_class(self):
71
 
        return ReadonlyTransportDecorator
 
121
    def setUp(self, server=None):
 
122
        """See bzrlib.transport.Server.setUp.
 
123
 
 
124
        :server: decorate the urls given by server. If not provided a
 
125
        LocalServer is created.
 
126
        """
 
127
        if server is not None:
 
128
            self._made_server = False
 
129
            self._server = server
 
130
        else:
 
131
            from bzrlib.transport.local import LocalRelpathServer
 
132
            self._made_server = True
 
133
            self._server = LocalRelpathServer()
 
134
            self._server.setUp()
 
135
 
 
136
    def tearDown(self):
 
137
        """See bzrlib.transport.Server.tearDown."""
 
138
        if self._made_server:
 
139
            self._server.tearDown()
 
140
 
 
141
    def get_bogus_url(self):
 
142
        """See bzrlib.transport.Server.get_bogus_url."""
 
143
        return "readonly+" + self._server.get_bogus_url()
 
144
 
 
145
    def get_url(self):
 
146
        """See bzrlib.transport.Server.get_url."""
 
147
        return "readonly+" + self._server.get_url()
72
148
 
73
149
 
74
150
def get_test_permutations():