~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Lalo Martins
  • Date: 2005-09-08 00:40:15 UTC
  • mto: (1185.1.22)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050908004014-bb63b3378ac8ff58
turned get_revision_info into a RevisionSpec class

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os, tempfile, types, osutils, gzip, errno
25
25
from stat import ST_SIZE
26
26
from StringIO import StringIO
 
27
from bzrlib.errors import BzrError
27
28
from bzrlib.trace import mutter
28
29
import bzrlib.ui
29
30
 
67
68
    def __init__(self, basedir):
68
69
        self._basedir = basedir
69
70
 
70
 
    def _path(self, id):
71
 
        if '\\' in id or '/' in id:
72
 
            raise ValueError("invalid store id %r" % id)
73
 
        return os.path.join(self._basedir, id)
 
71
    def _path(self, entry_id):
 
72
        if not isinstance(entry_id, basestring):
 
73
            raise TypeError(type(entry_id))
 
74
        if '\\' in entry_id or '/' in entry_id:
 
75
            raise ValueError("invalid store id %r" % entry_id)
 
76
        return os.path.join(self._basedir, entry_id)
74
77
 
75
78
    def __repr__(self):
76
79
        return "%s(%r)" % (self.__class__.__name__, self._basedir)
91
94
            
92
95
        p = self._path(fileid)
93
96
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
94
 
            from bzrlib.errors import bailout
95
97
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
96
98
 
97
99
        fn = p
114
116
    def copy_multi(self, other, ids, permit_failure=False):
115
117
        """Copy texts for ids from other into self.
116
118
 
117
 
        If an id is present in self, it is skipped.  A count of copied
118
 
        ids is returned, which may be less than len(ids).
 
119
        If an id is present in self, it is skipped.
 
120
 
 
121
        Returns (count_copied, failed), where failed is a collection of ids
 
122
        that could not be copied.
119
123
        """
120
124
        pb = bzrlib.ui.ui_factory.progress_bar()
121
125
        
124
128
        if isinstance(other, ImmutableStore):
125
129
            return self.copy_multi_immutable(other, to_copy, pb)
126
130
        count = 0
 
131
        failed = set()
127
132
        for id in to_copy:
128
133
            count += 1
129
134
            pb.update('copy', count, len(to_copy))
133
138
                try:
134
139
                    entry = other[id]
135
140
                except IndexError:
136
 
                    failures.add(id)
 
141
                    failed.add(id)
137
142
                    continue
138
143
                self.add(entry, id)
139
144
                
140
 
        assert count == len(to_copy)
 
145
        if not permit_failure:
 
146
            assert count == len(to_copy)
141
147
        pb.clear()
142
 
        return count
143
 
 
 
148
        return count, failed
144
149
 
145
150
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
146
151
        from shutil import copyfile