~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-29 00:43:48 UTC
  • Revision ID: mbp@sourcefrog.net-20050329004348-78dc7451fd0cbc5f
- store support for retrieving compressed files

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
24
24
__author__ = "Martin Pool <mbp@canonical.com>"
25
25
 
26
 
import os, tempfile, types, osutils
 
26
import os, tempfile, types, osutils, gzip, errno
27
27
from stat import ST_SIZE
28
28
from StringIO import StringIO
29
29
from trace import mutter
30
30
 
31
 
 
32
31
######################################################################
33
32
# stores
34
33
 
116
115
 
117
116
    def __getitem__(self, fileid):
118
117
        """Returns a file reading from a particular entry."""
119
 
        return file(self._path(fileid), 'rb')
 
118
        p = self._path(fileid)
 
119
        try:
 
120
            return gzip.GzipFile(p + '.gz', 'rb')
 
121
        except IOError, e:
 
122
            if e.errno == errno.ENOENT:
 
123
                return file(p, 'rb')
 
124
            else:
 
125
                raise e
120
126
 
121
127
    def total_size(self):
122
 
        """Return (count, bytes)"""
 
128
        """Return (count, bytes)
 
129
 
 
130
        This is the (compressed) size stored on disk, not the size of
 
131
        the content."""
123
132
        total = 0
124
133
        count = 0
125
134
        for fid in self: