4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2006-2010 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
16 |
|
17 |
"""Implementation of Transport that decorates another transport.
|
|
18 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
19 |
This does not change the transport behaviour at all, but provides all the
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
20 |
stub functions to allow other decorators to be written easily.
|
21 |
"""
|
|
22 |
||
5273.1.7
by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through |
23 |
from bzrlib import transport |
24 |
||
25 |
||
26 |
class TransportDecorator(transport.Transport): |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
27 |
"""A no-change decorator for Transports.
|
1634.1.1
by Robert Collins
Merge NFS LockDir support (Aaron Bentley, Robert Collins). |
28 |
|
29 |
Subclasses of this are new transports that are based on an
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
30 |
underlying transport and can override or intercept some
|
31 |
behavior. For example ReadonlyTransportDecorator prevents
|
|
32 |
all write attempts, and FakeNFSTransportDecorator simulates
|
|
1634.1.1
by Robert Collins
Merge NFS LockDir support (Aaron Bentley, Robert Collins). |
33 |
some NFS quirks.
|
34 |
||
35 |
This decorator class is not directly usable as a decorator:
|
|
36 |
you must use a subclass which has overridden the _get_url_prefix() class
|
|
37 |
method to return the url prefix for the subclass.
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
38 |
"""
|
39 |
||
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
40 |
def __init__(self, url, _decorated=None, _from_transport=None): |
41 |
"""Set the 'base' path of the transport.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
42 |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
43 |
:param _decorated: A private parameter for cloning.
|
44 |
:param _from_transport: Is available for subclasses that
|
|
45 |
need to share state across clones.
|
|
46 |
"""
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
47 |
prefix = self._get_url_prefix() |
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
48 |
if not url.startswith(prefix): |
3878.4.1
by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when |
49 |
raise ValueError("url %r doesn't start with decorator prefix %r" % |
50 |
(url, prefix)) |
|
51 |
not_decorated_url = url[len(prefix):] |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
52 |
if _decorated is None: |
5273.1.7
by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through |
53 |
self._decorated = transport.get_transport(not_decorated_url) |
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
54 |
else: |
55 |
self._decorated = _decorated |
|
3878.4.1
by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when |
56 |
super(TransportDecorator, self).__init__(prefix + self._decorated.base) |
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
57 |
|
58 |
def abspath(self, relpath): |
|
59 |
"""See Transport.abspath()."""
|
|
60 |
return self._get_url_prefix() + self._decorated.abspath(relpath) |
|
61 |
||
1955.3.15
by John Arbash Meinel
Deprecate 'Transport.append' in favor of Transport.append_file or Transport.append_bytes |
62 |
def append_file(self, relpath, f, mode=None): |
63 |
"""See Transport.append_file()."""
|
|
64 |
return self._decorated.append_file(relpath, f, mode=mode) |
|
65 |
||
66 |
def append_bytes(self, relpath, bytes, mode=None): |
|
67 |
"""See Transport.append_bytes()."""
|
|
68 |
return self._decorated.append_bytes(relpath, bytes, mode=mode) |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
69 |
|
2671.3.3
by Robert Collins
Add mode parameter to Transport.open_file_stream. |
70 |
def _can_roundtrip_unix_modebits(self): |
71 |
"""See Transport._can_roundtrip_unix_modebits()."""
|
|
72 |
return self._decorated._can_roundtrip_unix_modebits() |
|
73 |
||
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
74 |
def clone(self, offset=None): |
75 |
"""See Transport.clone()."""
|
|
76 |
decorated_clone = self._decorated.clone(offset) |
|
77 |
return self.__class__( |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
78 |
self._get_url_prefix() + decorated_clone.base, decorated_clone, |
79 |
self) |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
80 |
|
81 |
def delete(self, relpath): |
|
82 |
"""See Transport.delete()."""
|
|
83 |
return self._decorated.delete(relpath) |
|
84 |
||
85 |
def delete_tree(self, relpath): |
|
86 |
"""See Transport.delete_tree()."""
|
|
87 |
return self._decorated.delete_tree(relpath) |
|
88 |
||
2634.1.1
by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch. |
89 |
def external_url(self): |
90 |
"""See bzrlib.transport.Transport.external_url."""
|
|
91 |
# while decorators are in-process only, they
|
|
92 |
# can be handed back into bzrlib safely, so
|
|
93 |
# its just the base.
|
|
94 |
return self.base |
|
95 |
||
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
96 |
@classmethod
|
97 |
def _get_url_prefix(self): |
|
98 |
"""Return the URL prefix of this decorator."""
|
|
99 |
raise NotImplementedError(self._get_url_prefix) |
|
100 |
||
2164.2.15
by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints |
101 |
def get(self, relpath): |
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
102 |
"""See Transport.get()."""
|
2164.2.15
by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints |
103 |
return self._decorated.get(relpath) |
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
104 |
|
1752.2.52
by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories. |
105 |
def get_smart_client(self): |
106 |
return self._decorated.get_smart_client() |
|
107 |
||
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
108 |
def has(self, relpath): |
109 |
"""See Transport.has()."""
|
|
110 |
return self._decorated.has(relpath) |
|
111 |
||
112 |
def is_readonly(self): |
|
113 |
"""See Transport.is_readonly."""
|
|
114 |
return self._decorated.is_readonly() |
|
115 |
||
116 |
def mkdir(self, relpath, mode=None): |
|
117 |
"""See Transport.mkdir()."""
|
|
118 |
return self._decorated.mkdir(relpath, mode) |
|
119 |
||
2671.3.9
by Robert Collins
Review feedback and fix VFat emulated transports to not claim to have unix permissions. |
120 |
def open_write_stream(self, relpath, mode=None): |
121 |
"""See Transport.open_write_stream."""
|
|
122 |
return self._decorated.open_write_stream(relpath, mode=mode) |
|
2671.3.2
by Robert Collins
Start open_file_stream logic. |
123 |
|
1955.3.6
by John Arbash Meinel
Lots of deprecation warnings, but no errors |
124 |
def put_file(self, relpath, f, mode=None): |
125 |
"""See Transport.put_file()."""
|
|
126 |
return self._decorated.put_file(relpath, f, mode) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
127 |
|
1955.3.6
by John Arbash Meinel
Lots of deprecation warnings, but no errors |
128 |
def put_bytes(self, relpath, bytes, mode=None): |
129 |
"""See Transport.put_bytes()."""
|
|
130 |
return self._decorated.put_bytes(relpath, bytes, mode) |
|
131 |
||
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
132 |
def listable(self): |
133 |
"""See Transport.listable."""
|
|
134 |
return self._decorated.listable() |
|
135 |
||
136 |
def iter_files_recursive(self): |
|
137 |
"""See Transport.iter_files_recursive()."""
|
|
138 |
return self._decorated.iter_files_recursive() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
139 |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
140 |
def list_dir(self, relpath): |
141 |
"""See Transport.list_dir()."""
|
|
142 |
return self._decorated.list_dir(relpath) |
|
1608.2.3
by Martin Pool
Add default Transport.rename() to TransportDecorator |
143 |
|
2745.5.1
by Robert Collins
* New parameter on ``bzrlib.transport.Transport.readv`` |
144 |
def _readv(self, relpath, offsets): |
145 |
"""See Transport._readv."""
|
|
146 |
return self._decorated._readv(relpath, offsets) |
|
147 |
||
2671.3.1
by Robert Collins
* New method ``bzrlib.transport.Transport.get_recommended_page_size``. |
148 |
def recommended_page_size(self): |
149 |
"""See Transport.recommended_page_size()."""
|
|
150 |
return self._decorated.recommended_page_size() |
|
151 |
||
1608.2.3
by Martin Pool
Add default Transport.rename() to TransportDecorator |
152 |
def rename(self, rel_from, rel_to): |
153 |
return self._decorated.rename(rel_from, rel_to) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
154 |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
155 |
def rmdir(self, relpath): |
156 |
"""See Transport.rmdir."""
|
|
157 |
return self._decorated.rmdir(relpath) |
|
158 |
||
159 |
def stat(self, relpath): |
|
160 |
"""See Transport.stat()."""
|
|
161 |
return self._decorated.stat(relpath) |
|
162 |
||
163 |
def lock_read(self, relpath): |
|
164 |
"""See Transport.lock_read."""
|
|
165 |
return self._decorated.lock_read(relpath) |
|
166 |
||
167 |
def lock_write(self, relpath): |
|
168 |
"""See Transport.lock_write."""
|
|
169 |
return self._decorated.lock_write(relpath) |
|
170 |
||
3878.4.5
by Vincent Ladeuil
Don't use the exception as a parameter for _redirected_to. |
171 |
def _redirected_to(self, source, target): |
172 |
redirected = self._decorated._redirected_to(source, target) |
|
3878.4.1
by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when |
173 |
if redirected is not None: |
174 |
return self.__class__(self._get_url_prefix() + redirected.base, |
|
175 |
redirected) |
|
3878.4.6
by Vincent Ladeuil
Fix bug #270863 by preserving 'bzr+http[s]' decorator. |
176 |
else: |
177 |
return None |
|
3878.4.1
by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when |
178 |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
179 |
|
180 |
def get_test_permutations(): |
|
181 |
"""Return the permutations to be used in testing.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
182 |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
183 |
The Decorator class is not directly usable, and testing it would not have
|
184 |
any benefit - its the concrete classes which need to be tested.
|
|
185 |
"""
|
|
186 |
return [] |