~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/__init__.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
# TODO: Could remember a bias towards whether a particular store is typically
18
18
# compressed or not.
24
24
unique ID.
25
25
"""
26
26
 
27
 
from __future__ import absolute_import
28
 
 
29
27
import os
 
28
from cStringIO import StringIO
 
29
import urllib
 
30
from zlib import adler32
30
31
 
 
32
import bzrlib
31
33
from bzrlib import (
32
34
    errors,
 
35
    osutils,
 
36
    symbol_versioning,
 
37
    urlutils,
33
38
    versionedfile,
34
39
    )
35
 
from bzrlib.errors import BzrError, UnlistableStore
 
40
from bzrlib.errors import BzrError, UnlistableStore, TransportNotPossible
 
41
from bzrlib.symbol_versioning import (
 
42
    deprecated_function,
 
43
    )
36
44
from bzrlib.trace import mutter
 
45
from bzrlib.transport import Transport
 
46
from bzrlib.transport.local import LocalTransport
37
47
 
38
48
######################################################################
39
49
# stores
44
54
 
45
55
class Store(object):
46
56
    """This class represents the abstract storage layout for saving information.
47
 
 
 
57
    
48
58
    Files can be added, but not modified once they are in.  Typically
49
59
    the hash is used as the name, or something else known to be unique,
50
60
    such as a UUID.
55
65
 
56
66
    def get(self, fileid, suffix=None):
57
67
        """Returns a file reading from a particular entry.
58
 
 
 
68
        
59
69
        If suffix is present, retrieve the named suffix for fileid.
60
70
        """
61
71
        raise NotImplementedError
73
83
 
74
84
    def has_id(self, fileid, suffix=None):
75
85
        """Return True or false for the presence of fileid in the store.
76
 
 
77
 
        suffix, if present, is a per file suffix, i.e. for digital signature
 
86
        
 
87
        suffix, if present, is a per file suffix, i.e. for digital signature 
78
88
        data."""
79
89
        raise NotImplementedError
80
90
 
104
114
 
105
115
        :param other: Another Store object
106
116
        :param ids: A list of entry ids to be copied
107
 
        :param pb: A ProgressTask object, if none is given, the default will be created.
 
117
        :param pb: A ProgressBar object, if none is given, the default will be created.
108
118
        :param permit_failure: Allow missing entries to be ignored
109
119
        :return: (n_copied, [failed]) The number of entries copied successfully,
110
120
            followed by a list of entries which could not be copied (because they
138
148
 
139
149
    def _copy_one(self, fileid, suffix, other, pb):
140
150
        """Most generic copy-one object routine.
141
 
 
 
151
        
142
152
        Subclasses can override this to provide an optimised
143
153
        copy between their own instances. Such overriden routines
144
 
        should call this if they have no optimised facility for a
 
154
        should call this if they have no optimised facility for a 
145
155
        specific 'other'.
146
156
        """
147
157
        mutter('Store._copy_one: %r', fileid)
160
170
        mutter("add store entry %r", fileid)
161
171
        names = self._id_to_names(fileid, suffix)
162
172
        if self._transport.has_any(names):
163
 
            raise BzrError("store %r already contains id %r"
 
173
            raise BzrError("store %r already contains id %r" 
164
174
                           % (self._transport.base, fileid))
165
175
 
166
176
        # Most of the time, just adding the file will work
201
211
 
202
212
    def _get_name(self, fileid, suffix=None):
203
213
        """A special check, which returns the name of an existing file.
204
 
 
 
214
        
205
215
        This is similar in spirit to 'has_id', but it is designed
206
216
        to return information about which file the store has.
207
217
        """
213
223
    def _get(self, filename):
214
224
        """Return an vanilla file stream for clients to read from.
215
225
 
216
 
        This is the body of a template method on 'get', and should be
 
226
        This is the body of a template method on 'get', and should be 
217
227
        implemented by subclasses.
218
228
        """
219
229
        raise NotImplementedError
319
329
        for relpath in self._transport.iter_files_recursive():
320
330
            count += 1
321
331
            total += self._transport.stat(relpath).st_size
322
 
 
 
332
                
323
333
        return count, total