~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-30 03:10:32 UTC
  • Revision ID: mbp@sourcefrog.net-20050830031032-92ae5f0abb866ab8
- remove dead code and remove some small errors (pychecker)

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 trace import mutter
 
27
from bzrlib.trace import mutter
 
28
import bzrlib.ui
28
29
 
29
30
######################################################################
30
31
# stores
90
91
            
91
92
        p = self._path(fileid)
92
93
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
93
 
            from bzrlib.errors import bailout
94
94
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
95
95
 
96
96
        fn = p
110
110
            af.close()
111
111
 
112
112
 
113
 
    def copy_multi(self, other, ids):
 
113
    def copy_multi(self, other, ids, permit_failure=False):
114
114
        """Copy texts for ids from other into self.
115
115
 
116
 
        If an id is present in self, it is skipped.  A count of copied
117
 
        ids is returned, which may be less than len(ids).
 
116
        If an id is present in self, it is skipped.
 
117
 
 
118
        Returns (count_copied, failed), where failed is a collection of ids
 
119
        that could not be copied.
118
120
        """
119
 
        from bzrlib.progress import ProgressBar
120
 
        pb = ProgressBar()
 
121
        pb = bzrlib.ui.ui_factory.progress_bar()
 
122
        
121
123
        pb.update('preparing to copy')
122
124
        to_copy = [id for id in ids if id not in self]
123
125
        if isinstance(other, ImmutableStore):
126
128
        for id in to_copy:
127
129
            count += 1
128
130
            pb.update('copy', count, len(to_copy))
129
 
            self.add(other[id], id)
 
131
            if not permit_failure:
 
132
                self.add(other[id], id)
 
133
            else:
 
134
                try:
 
135
                    entry = other[id]
 
136
                except IndexError:
 
137
                    failures.add(id)
 
138
                    continue
 
139
                self.add(entry, id)
 
140
                
130
141
        assert count == len(to_copy)
131
142
        pb.clear()
132
 
        return count
133
 
 
134
 
 
135
 
    def copy_multi_immutable(self, other, to_copy, pb):
 
143
        return count, []
 
144
 
 
145
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
136
146
        from shutil import copyfile
137
147
        count = 0
 
148
        failed = set()
138
149
        for id in to_copy:
139
150
            p = self._path(id)
140
151
            other_p = other._path(id)
142
153
                copyfile(other_p, p)
143
154
            except IOError, e:
144
155
                if e.errno == errno.ENOENT:
145
 
                    copyfile(other_p+".gz", p+".gz")
 
156
                    if not permit_failure:
 
157
                        copyfile(other_p+".gz", p+".gz")
 
158
                    else:
 
159
                        try:
 
160
                            copyfile(other_p+".gz", p+".gz")
 
161
                        except IOError, e:
 
162
                            if e.errno == errno.ENOENT:
 
163
                                failed.add(id)
 
164
                            else:
 
165
                                raise
146
166
                else:
147
167
                    raise
148
168
            
150
170
            pb.update('copy', count, len(to_copy))
151
171
        assert count == len(to_copy)
152
172
        pb.clear()
153
 
        return count
 
173
        return count, failed
154
174
    
155
175
 
156
176
    def __contains__(self, fileid):