3
An implementation of the Transport object for local
7
from bzrlib.transport import Transport, protocol_handlers
10
class LocalTransport(Transport):
11
"""This is the transport agent for local filesystem access."""
13
def __init__(self, base):
14
"""Set the base path where files will be stored."""
15
from os.path import realpath
16
super(LocalTransport, self).__init__(realpath(base))
18
def _join(self, relpath):
19
return os.path.join(self.base, relpath)
21
def has(self, relpath):
22
return os.access(self._join(relpath), os.F_OK)
24
def get(self, relpath):
25
"""Get the file at the given relative path.
27
return open(self._join(relpath), 'rb')
29
def put(self, relpath, f):
30
"""Copy the file-like object into the location.
32
from bzrlib.atomicfile import AtomicFile
34
fp = AtomicFile(self._join(relpath), 'wb')
38
def append(self, relpath, f):
39
"""Append the text in the file-like object into the final
42
fp = open(self._join(relpath), 'a+b')
45
def copy(self, rel_from, rel_to):
46
"""Copy the item at rel_from to the location at rel_to"""
48
path_from = self._join(rel_from)
49
path_to = self._join(rel_to)
50
shutil.copy(path_from, path_to)
52
def move(self, rel_from, rel_to):
53
"""Move the item at rel_from to the location at rel_to"""
54
path_from = self._join(rel_from)
55
path_to = self._join(rel_to)
57
os.rename(path_from, path_to)
59
def delete(self, relpath):
60
"""Delete the item at relpath"""
61
os.remove(self._join(relpath))
63
def async_get(self, relpath):
64
"""Make a request for an file at the given location, but
65
don't worry about actually getting it yet.
69
raise NotImplementedError
71
# If nothing else matches, try the LocalTransport
72
protocol_handlers[None] = LocalTransport