~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-10 23:18:27 UTC
  • mfrom: (1437)
  • mto: This revision was merged to the branch mainline in revision 1438.
  • Revision ID: robertc@robertcollins.net-20051010231827-f9e2dda2e92bf565
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
from cStringIO import StringIO
 
28
from stat import ST_MODE, S_ISDIR
 
29
from zlib import adler32
28
30
 
 
31
import bzrlib.errors as errors
29
32
from bzrlib.errors import BzrError, UnlistableStore, TransportNotPossible
30
33
from bzrlib.trace import mutter
31
34
import bzrlib.transport
191
194
 
192
195
    _max_buffered_requests = 10
193
196
 
 
197
    def __getitem__(self, fileid):
 
198
        """Returns a file reading from a particular entry."""
 
199
        fn = self._relpath(fileid)
 
200
        try:
 
201
            return self._transport.get(fn)
 
202
        except errors.NoSuchFile:
 
203
            raise KeyError(fileid)
 
204
 
194
205
    def __init__(self, transport):
195
206
        assert isinstance(transport, bzrlib.transport.Transport)
196
207
        super(TransportStore, self).__init__()
204
215
 
205
216
    __str__ = __repr__
206
217
 
 
218
    def _iter_relpaths(self):
 
219
        """Iter the relative paths of files in the transports sub-tree."""
 
220
        transport = self._transport
 
221
        queue = list(transport.list_dir('.'))
 
222
        while queue:
 
223
            relpath = queue.pop(0)
 
224
            st = transport.stat(relpath)
 
225
            if S_ISDIR(st[ST_MODE]):
 
226
                for i, basename in enumerate(transport.list_dir(relpath)):
 
227
                    queue.insert(i, relpath+'/'+basename)
 
228
            else:
 
229
                yield relpath, st
 
230
 
207
231
    def listable(self):
208
232
        """Return True if this store is able to be listed."""
209
233
        return self._transport.listable()
307
331
    ids = [f for f in store_from]
308
332
    store_to.copy_multi(store_from, ids)
309
333
 
 
334
def hash_prefix(file_id):
 
335
    return "%02x/" % (adler32(file_id) & 0xff)
 
336