27
27
from cStringIO import StringIO
28
from stat import ST_MODE, S_ISDIR, ST_SIZE
29
28
from zlib import adler32
31
31
import bzrlib.errors as errors
32
32
from bzrlib.errors import BzrError, UnlistableStore, TransportNotPossible
33
33
from bzrlib.trace import mutter
34
import bzrlib.transport
34
import bzrlib.transport as transport
35
35
from bzrlib.transport.local import LocalTransport
37
37
######################################################################
238
238
relpaths = (self._relpath(fid) for fid in fileids)
239
239
return self._transport.has_multi(relpaths, pb=pb)
241
def __init__(self, transport, prefixed=False):
242
assert isinstance(transport, bzrlib.transport.Transport)
241
def __init__(self, a_transport, prefixed=False):
242
assert isinstance(a_transport, transport.Transport)
243
243
super(TransportStore, self).__init__()
244
self._transport = transport
244
self._transport = a_transport
245
245
self._prefixed = prefixed
246
246
self._suffixes = set()
270
270
__str__ = __repr__
272
def _iter_relpaths(self):
273
"""Iter the relative paths of files in the transports sub-tree."""
274
transport = self._transport
275
queue = list(transport.list_dir('.'))
277
relpath = queue.pop(0)
278
st = transport.stat(relpath)
279
if S_ISDIR(st[ST_MODE]):
280
for i, basename in enumerate(transport.list_dir(relpath)):
281
queue.insert(i, relpath+'/'+basename)
285
272
def listable(self):
286
273
"""Return True if this store is able to be listed."""
287
274
return self._transport.listable()
301
for relpath, st in self._iter_relpaths():
288
for relpath in self._transport.iter_files_recursive():
290
total += self._transport.stat(relpath).st_size
305
292
return count, total
308
class ImmutableMemoryStore(Store):
309
"""A memory only store."""
311
def __contains__(self, fileid):
312
return self._contents.has_key(fileid)
315
super(ImmutableMemoryStore, self).__init__()
318
def add(self, stream, fileid, compressed=True):
319
if self._contents.has_key(fileid):
320
raise StoreError("fileid %s already in the store" % fileid)
321
self._contents[fileid] = stream.read()
323
def get(self, fileid):
324
"""Returns a file reading from a particular entry."""
325
if not self._contents.has_key(fileid):
327
return StringIO(self._contents[fileid])
329
def _item_size(self, fileid):
330
return len(self._contents[fileid])
333
return iter(self._contents.keys())
335
def total_size(self):
340
result += self._item_size(fileid)
295
def ImmutableMemoryStore():
296
return bzrlib.store.text.TextStore(transport.memory.MemoryTransport())
344
299
class CachedStore(Store):