/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/store/__init__.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

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