~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Robert Collins
  • Date: 2005-09-29 02:55:34 UTC
  • mfrom: (1185.1.47)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050929025534-1782933743abbfd5
update with integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from stat import ST_SIZE
30
30
from StringIO import StringIO
31
31
 
32
 
from bzrlib.errors import BzrError
 
32
from bzrlib.errors import BzrError, UnlistableStore
33
33
from bzrlib.trace import mutter
34
34
import bzrlib.ui
35
35
import bzrlib.osutils as osutils
36
 
from bzrlib.remotebranch import get_url
 
36
#circular import
 
37
#from bzrlib.remotebranch import get_url
37
38
import urllib2
38
39
 
39
40
 
180
181
        return count, failed
181
182
 
182
183
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
183
 
        from shutil import copyfile
184
184
        count = 0
185
185
        failed = set()
186
186
        for id in to_copy:
187
187
            p = self._path(id)
188
188
            other_p = other._path(id)
189
189
            try:
190
 
                copyfile(other_p, p)
191
 
            except IOError, e:
 
190
                osutils.link_or_copy(other_p, p)
 
191
            except (IOError, OSError), e:
192
192
                if e.errno == errno.ENOENT:
193
193
                    if not permit_failure:
194
 
                        copyfile(other_p+".gz", p+".gz")
 
194
                        osutils.link_or_copy(other_p+".gz", p+".gz")
195
195
                    else:
196
196
                        try:
197
 
                            copyfile(other_p+".gz", p+".gz")
 
197
                            osutils.link_or_copy(other_p+".gz", p+".gz")
198
198
                        except IOError, e:
199
199
                            if e.errno == errno.ENOENT:
200
200
                                failed.add(id)
306
306
        return self._baseurl + '/' + name
307
307
        
308
308
    def __getitem__(self, fileid):
 
309
        # circular import.
 
310
        from bzrlib.remotebranch import get_url
309
311
        p = self._path(fileid)
310
312
        try:
311
313
            return get_url(p, compressed=True)
316
318
        except urllib2.URLError:
317
319
            raise KeyError(fileid)
318
320
 
 
321
 
319
322
class CachedStore:
320
323
    """A store that caches data locally, to avoid repeated downloads.
321
324
    The precacache method should be used to avoid server round-trips for
341
344
        mutter("Prefetch of ids %s" % ",".join(ids))
342
345
        self.cache_store.copy_multi(self.source_store, ids,
343
346
                                    permit_failure=True)
 
347
 
 
348
 
 
349
def copy_all(store_from, store_to):
 
350
    """Copy all ids from one store to another."""
 
351
    if not hasattr(store_from, "__iter__"):
 
352
        raise UnlistableStore(store_from)
 
353
    ids = [f for f in store_from]
 
354
    store_to.copy_multi(store_from, ids)