~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-07-13 00:30:30 UTC
  • Revision ID: mbp@sourcefrog.net-20050713003030-2e89871a9ce24c7b
- typo in testsweet

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os, tempfile, types, osutils, gzip, errno
25
25
from stat import ST_SIZE
26
26
from StringIO import StringIO
27
 
from bzrlib.trace import mutter
28
 
import bzrlib.ui
 
27
from trace import mutter
29
28
 
30
29
######################################################################
31
30
# stores
111
110
            af.close()
112
111
 
113
112
 
114
 
    def copy_multi(self, other, ids, permit_failure=False):
 
113
    def copy_multi(self, other, ids):
115
114
        """Copy texts for ids from other into self.
116
115
 
117
 
        If an id is present in self, it is skipped.
118
 
 
119
 
        Returns (count_copied, failed), where failed is a collection of ids
120
 
        that could not be copied.
 
116
        If an id is present in self, it is skipped.  A count of copied
 
117
        ids is returned, which may be less than len(ids).
121
118
        """
122
 
        pb = bzrlib.ui.ui_factory.progress_bar()
123
 
        
 
119
        from bzrlib.progress import ProgressBar
 
120
        pb = ProgressBar()
124
121
        pb.update('preparing to copy')
125
122
        to_copy = [id for id in ids if id not in self]
126
123
        if isinstance(other, ImmutableStore):
129
126
        for id in to_copy:
130
127
            count += 1
131
128
            pb.update('copy', count, len(to_copy))
132
 
            if not permit_failure:
133
 
                self.add(other[id], id)
134
 
            else:
135
 
                try:
136
 
                    entry = other[id]
137
 
                except IndexError:
138
 
                    failures.add(id)
139
 
                    continue
140
 
                self.add(entry, id)
141
 
                
 
129
            self.add(other[id], id)
142
130
        assert count == len(to_copy)
143
131
        pb.clear()
144
 
        return count, []
145
 
 
146
 
 
147
 
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
 
132
        return count
 
133
 
 
134
 
 
135
    def copy_multi_immutable(self, other, to_copy, pb):
148
136
        from shutil import copyfile
149
137
        count = 0
150
 
        failed = set()
151
138
        for id in to_copy:
152
139
            p = self._path(id)
153
140
            other_p = other._path(id)
155
142
                copyfile(other_p, p)
156
143
            except IOError, e:
157
144
                if e.errno == errno.ENOENT:
158
 
                    if not permit_failure:
159
 
                        copyfile(other_p+".gz", p+".gz")
160
 
                    else:
161
 
                        try:
162
 
                            copyfile(other_p+".gz", p+".gz")
163
 
                        except IOError, e:
164
 
                            if e.errno == errno.ENOENT:
165
 
                                failed.add(id)
166
 
                            else:
167
 
                                raise
 
145
                    copyfile(other_p+".gz", p+".gz")
168
146
                else:
169
147
                    raise
170
148
            
172
150
            pb.update('copy', count, len(to_copy))
173
151
        assert count == len(to_copy)
174
152
        pb.clear()
175
 
        return count, failed
 
153
        return count
176
154
    
177
155
 
178
156
    def __contains__(self, fileid):
194
172
    def __len__(self):
195
173
        return len(os.listdir(self._basedir))
196
174
 
197
 
 
198
175
    def __getitem__(self, fileid):
199
176
        """Returns a file reading from a particular entry."""
200
177
        p = self._path(fileid)
201
178
        try:
202
179
            return gzip.GzipFile(p + '.gz', 'rb')
203
180
        except IOError, e:
204
 
            if e.errno != errno.ENOENT:
205
 
                raise
206
 
 
207
 
        try:
208
 
            return file(p, 'rb')
209
 
        except IOError, e:
210
 
            if e.errno != errno.ENOENT:
211
 
                raise
212
 
 
213
 
        raise IndexError(fileid)
214
 
 
 
181
            if e.errno == errno.ENOENT:
 
182
                return file(p, 'rb')
 
183
            else:
 
184
                raise e
215
185
 
216
186
    def total_size(self):
217
187
        """Return (count, bytes)