~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-19 21:39:05 UTC
  • Revision ID: mbp@sourcefrog.net-20050819213905-dcb792daf09efa84
prepare 0.0.6 release

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
93
94
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
94
95
 
95
96
        fn = p
171
172
    def __len__(self):
172
173
        return len(os.listdir(self._basedir))
173
174
 
 
175
 
174
176
    def __getitem__(self, fileid):
175
177
        """Returns a file reading from a particular entry."""
176
178
        p = self._path(fileid)
177
179
        try:
178
180
            return gzip.GzipFile(p + '.gz', 'rb')
179
181
        except IOError, e:
180
 
            if e.errno == errno.ENOENT:
181
 
                return file(p, 'rb')
182
 
            else:
183
 
                raise 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
 
184
193
 
185
194
    def total_size(self):
186
195
        """Return (count, bytes)