~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Robert Collins
  • Date: 2005-09-26 08:56:15 UTC
  • mto: (1092.3.4)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: robertc@robertcollins.net-20050926085615-99b8fb35f41b541d
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
unique ID.
22
22
"""
23
23
 
24
 
import os, tempfile, types, osutils, gzip, errno
 
24
import errno
 
25
import gzip
 
26
import os
 
27
import tempfile
 
28
import types
25
29
from stat import ST_SIZE
26
30
from StringIO import StringIO
 
31
 
 
32
from bzrlib.errors import BzrError
27
33
from bzrlib.trace import mutter
28
34
import bzrlib.ui
 
35
import bzrlib.osutils as osutils
 
36
 
29
37
 
30
38
######################################################################
31
39
# stores
67
75
    def __init__(self, basedir):
68
76
        self._basedir = basedir
69
77
 
70
 
    def _path(self, id):
71
 
        if '\\' in id or '/' in id:
72
 
            raise ValueError("invalid store id %r" % id)
73
 
        return os.path.join(self._basedir, id)
 
78
    def _path(self, entry_id):
 
79
        if not isinstance(entry_id, basestring):
 
80
            raise TypeError(type(entry_id))
 
81
        if '\\' in entry_id or '/' in entry_id:
 
82
            raise ValueError("invalid store id %r" % entry_id)
 
83
        return os.path.join(self._basedir, entry_id)
74
84
 
75
85
    def __repr__(self):
76
86
        return "%s(%r)" % (self.__class__.__name__, self._basedir)
123
133
        pb.update('preparing to copy')
124
134
        to_copy = [id for id in ids if id not in self]
125
135
        if isinstance(other, ImmutableStore):
126
 
            return self.copy_multi_immutable(other, to_copy, pb)
 
136
            return self.copy_multi_immutable(other, to_copy, pb, 
 
137
                                             permit_failure=permit_failure)
127
138
        count = 0
 
139
        failed = set()
128
140
        for id in to_copy:
129
141
            count += 1
130
142
            pb.update('copy', count, len(to_copy))
133
145
            else:
134
146
                try:
135
147
                    entry = other[id]
136
 
                except IndexError:
137
 
                    failures.add(id)
 
148
                except KeyError:
 
149
                    failed.add(id)
138
150
                    continue
139
151
                self.add(entry, id)
140
152
                
141
 
        assert count == len(to_copy)
 
153
        if not permit_failure:
 
154
            assert count == len(to_copy)
142
155
        pb.clear()
143
 
        return count, []
 
156
        return count, failed
144
157
 
145
158
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
146
159
        from shutil import copyfile
208
221
            if e.errno != errno.ENOENT:
209
222
                raise
210
223
 
211
 
        raise IndexError(fileid)
 
224
        raise KeyError(fileid)
212
225
 
213
226
 
214
227
    def total_size(self):