~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-06-22 07:57:56 UTC
  • Revision ID: mbp@sourcefrog.net-20050622075756-f4f98a7f2addddf5
- stubbed-out tests for python plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
            
91
91
        p = self._path(fileid)
92
92
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
93
 
            from bzrlib.errors import bailout
94
93
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
95
94
 
96
95
        fn = p
120
119
        pb = ProgressBar()
121
120
        pb.update('preparing to copy')
122
121
        to_copy = [id for id in ids if id not in self]
123
 
        if isinstance(other, ImmutableStore):
124
 
            return self.copy_multi_immutable(other, to_copy, pb)
125
122
        count = 0
126
123
        for id in to_copy:
127
124
            count += 1
130
127
        assert count == len(to_copy)
131
128
        pb.clear()
132
129
        return count
133
 
 
134
 
 
135
 
    def copy_multi_immutable(self, other, to_copy, pb):
136
 
        from shutil import copyfile
137
 
        count = 0
138
 
        for id in to_copy:
139
 
            p = self._path(id)
140
 
            other_p = other._path(id)
141
 
            try:
142
 
                copyfile(other_p, p)
143
 
            except IOError, e:
144
 
                if e.errno == errno.ENOENT:
145
 
                    copyfile(other_p+".gz", p+".gz")
146
 
                else:
147
 
                    raise
148
 
            
149
 
            count += 1
150
 
            pb.update('copy', count, len(to_copy))
151
 
        assert count == len(to_copy)
152
 
        pb.clear()
153
 
        return count
154
130
    
155
131
 
156
132
    def __contains__(self, fileid):
172
148
    def __len__(self):
173
149
        return len(os.listdir(self._basedir))
174
150
 
175
 
 
176
151
    def __getitem__(self, fileid):
177
152
        """Returns a file reading from a particular entry."""
178
153
        p = self._path(fileid)
179
154
        try:
180
155
            return gzip.GzipFile(p + '.gz', 'rb')
181
156
        except IOError, e:
182
 
            if e.errno != errno.ENOENT:
183
 
                raise
184
 
 
185
 
        try:
186
 
            return file(p, 'rb')
187
 
        except IOError, e:
188
 
            if e.errno != errno.ENOENT:
189
 
                raise
190
 
 
191
 
        raise IndexError(fileid)
192
 
 
 
157
            if e.errno == errno.ENOENT:
 
158
                return file(p, 'rb')
 
159
            else:
 
160
                raise e
193
161
 
194
162
    def total_size(self):
195
163
        """Return (count, bytes)