~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-07-18 13:38:13 UTC
  • Revision ID: mbp@sourcefrog.net-20050718133813-4343f0cde39537de
- refactor member names in Weave code

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
91
90
            
92
91
        p = self._path(fileid)
93
92
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
 
93
            from bzrlib.errors import bailout
94
94
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
95
95
 
96
96
        fn = p
110
110
            af.close()
111
111
 
112
112
 
113
 
    def copy_multi(self, other, ids, permit_failure=False):
 
113
    def copy_multi(self, other, ids):
114
114
        """Copy texts for ids from other into self.
115
115
 
116
 
        If an id is present in self, it is skipped.
117
 
 
118
 
        Returns (count_copied, failed), where failed is a collection of ids
119
 
        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).
120
118
        """
121
 
        pb = bzrlib.ui.ui_factory.progress_bar()
122
 
        
 
119
        from bzrlib.progress import ProgressBar
 
120
        pb = ProgressBar()
123
121
        pb.update('preparing to copy')
124
122
        to_copy = [id for id in ids if id not in self]
125
123
        if isinstance(other, ImmutableStore):
128
126
        for id in to_copy:
129
127
            count += 1
130
128
            pb.update('copy', count, len(to_copy))
131
 
            if not permit_failure:
132
 
                self.add(other[id], id)
133
 
            else:
134
 
                try:
135
 
                    entry = other[id]
136
 
                except IndexError:
137
 
                    failures.add(id)
138
 
                    continue
139
 
                self.add(entry, id)
140
 
                
 
129
            self.add(other[id], id)
141
130
        assert count == len(to_copy)
142
131
        pb.clear()
143
 
        return count, []
144
 
 
145
 
    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):
146
136
        from shutil import copyfile
147
137
        count = 0
148
 
        failed = set()
149
138
        for id in to_copy:
150
139
            p = self._path(id)
151
140
            other_p = other._path(id)
153
142
                copyfile(other_p, p)
154
143
            except IOError, e:
155
144
                if e.errno == errno.ENOENT:
156
 
                    if not permit_failure:
157
 
                        copyfile(other_p+".gz", p+".gz")
158
 
                    else:
159
 
                        try:
160
 
                            copyfile(other_p+".gz", p+".gz")
161
 
                        except IOError, e:
162
 
                            if e.errno == errno.ENOENT:
163
 
                                failed.add(id)
164
 
                            else:
165
 
                                raise
 
145
                    copyfile(other_p+".gz", p+".gz")
166
146
                else:
167
147
                    raise
168
148
            
170
150
            pb.update('copy', count, len(to_copy))
171
151
        assert count == len(to_copy)
172
152
        pb.clear()
173
 
        return count, failed
 
153
        return count
174
154
    
175
155
 
176
156
    def __contains__(self, fileid):
192
172
    def __len__(self):
193
173
        return len(os.listdir(self._basedir))
194
174
 
195
 
 
196
175
    def __getitem__(self, fileid):
197
176
        """Returns a file reading from a particular entry."""
198
177
        p = self._path(fileid)
199
178
        try:
200
179
            return gzip.GzipFile(p + '.gz', 'rb')
201
180
        except IOError, e:
202
 
            if e.errno != errno.ENOENT:
203
 
                raise
204
 
 
205
 
        try:
206
 
            return file(p, 'rb')
207
 
        except IOError, e:
208
 
            if e.errno != errno.ENOENT:
209
 
                raise
210
 
 
211
 
        raise IndexError(fileid)
212
 
 
 
181
            if e.errno == errno.ENOENT:
 
182
                return file(p, 'rb')
 
183
            else:
 
184
                raise e
213
185
 
214
186
    def total_size(self):
215
187
        """Return (count, bytes)