Lines Matching refs:self

74   def ReadRangeSet(self, ranges):  argument
77 def TotalSha1(self, include_clobbered_blocks=False): argument
89 def ReadRangeSet(self, ranges): argument
91 def TotalSha1(self, include_clobbered_blocks=False): argument
94 assert self.clobbered_blocks.size() == 0
101 def __init__(self, data, trim=False, pad=False): argument
102 self.data = data
103 self.blocksize = 4096
107 partial = len(self.data) % self.blocksize
110 self.data = self.data[:-partial]
112 self.data += '\0' * (self.blocksize - partial)
116 (self.blocksize,))
118 assert len(self.data) % self.blocksize == 0
120 self.total_blocks = len(self.data) / self.blocksize
121 self.care_map = RangeSet(data=(0, self.total_blocks))
122 self.clobbered_blocks = RangeSet()
123 self.extended = RangeSet()
127 reference = '\0' * self.blocksize
129 for i in range(self.total_blocks):
130 d = self.data[i*self.blocksize : (i+1)*self.blocksize]
138 self.file_map = {"__ZERO": RangeSet(zero_blocks),
141 def ReadRangeSet(self, ranges): argument
142 return [self.data[s*self.blocksize:e*self.blocksize] for (s, e) in ranges]
144 def TotalSha1(self, include_clobbered_blocks=False): argument
147 assert self.clobbered_blocks.size() == 0
148 return sha1(self.data).hexdigest()
152 def __init__(self, tgt_name, src_name, tgt_ranges, src_ranges, style, by_id): argument
153 self.tgt_name = tgt_name
154 self.src_name = src_name
155 self.tgt_ranges = tgt_ranges
156 self.src_ranges = src_ranges
157 self.style = style
158 self.intact = (getattr(tgt_ranges, "monotonic", False) and
163 self.goes_before = OrderedDict()
164 self.goes_after = OrderedDict()
166 self.stash_before = []
167 self.use_stash = []
169 self.id = len(by_id)
170 by_id.append(self)
172 def NetStashChange(self): argument
173 return (sum(sr.size() for (_, sr) in self.stash_before) -
174 sum(sr.size() for (_, sr) in self.use_stash))
176 def __str__(self): argument
177 return (str(self.id) + ": <" + str(self.src_ranges) + " " + self.style +
178 " to " + str(self.tgt_ranges) + ">")
218 def __init__(self, tgt, src=None, threads=None, version=3): argument
223 self.threads = threads
224 self.version = version
225 self.transfers = []
226 self.src_basenames = {}
227 self.src_numpatterns = {}
231 self.tgt = tgt
234 self.src = src
242 self.AssertPartition(src.care_map, src.file_map.values())
243 self.AssertPartition(tgt.care_map, tgt.file_map.values())
245 def Compute(self, prefix): argument
253 self.AbbreviateSourceNames()
254 self.FindTransfers()
258 self.GenerateDigraph()
261 self.FindVertexSequence()
264 if self.version == 1:
265 self.RemoveBackwardEdges()
267 self.ReverseBackwardEdges()
268 self.ImproveVertexSequence()
271 self.AssertSequenceGood()
273 self.ComputePatches(prefix)
274 self.WriteTransfers(prefix)
276 def HashBlocks(self, source, ranges): # pylint: disable=no-self-use argument
285 def WriteTransfers(self, prefix): argument
298 for xf in self.transfers:
300 if self.version < 2:
313 if self.version == 2:
316 sh = self.HashBlocks(self.src, sr)
328 if self.version == 1:
330 elif self.version >= 2:
347 sh = self.HashBlocks(self.src, sr)
350 if self.version == 2:
367 self.AssertPartition(RangeSet(data=(0, size)), mapped_stashes)
370 self.AssertPartition(RangeSet(data=(0, size)), mapped_stashes)
405 if self.version == 1:
409 elif self.version == 2:
413 elif self.version >= 3:
422 self.HashBlocks(self.tgt, xf.tgt_ranges),
429 if self.version == 1:
433 elif self.version == 2:
437 elif self.version >= 3:
447 self.HashBlocks(self.src, xf.src_ranges),
448 self.HashBlocks(self.tgt, xf.tgt_ranges),
465 assert max_stashed_blocks * self.tgt.blocksize < (512 << 20)
468 if self.tgt.extended:
469 out.append("zero %s\n" % (self.tgt.extended.to_string_raw(),))
473 all_tgt = RangeSet(data=(0, self.tgt.total_blocks))
474 all_tgt_minus_extended = all_tgt.subtract(self.tgt.extended)
475 new_dontcare = all_tgt_minus_extended.subtract(self.tgt.care_map)
479 out.insert(0, "%d\n" % (self.version,)) # format version number
481 if self.version >= 2:
491 if self.version >= 2:
493 max_stashed_blocks, max_stashed_blocks * self.tgt.blocksize))
495 def ComputePatches(self, prefix): argument
500 for xf in self.transfers:
504 for piece in self.tgt.ReadRangeSet(xf.tgt_ranges):
507 src = self.src.ReadRangeSet(xf.src_ranges)
508 tgt = self.tgt.ReadRangeSet(xf.tgt_ranges)
558 if self.threads > 1:
559 print("Computing patches (using %d threads)..." % (self.threads,))
584 for _ in range(self.threads)]
600 def AssertSequenceGood(self): argument
609 for xf in self.transfers:
613 if self.version >= 2:
624 assert touched == self.tgt.care_map
626 def ImproveVertexSequence(self): argument
639 for xf in self.transfers:
648 S = [(u.NetStashChange(), u.order, u) for u in self.transfers
661 assert len(L) == len(self.transfers)
663 self.transfers = L
667 def RemoveBackwardEdges(self): argument
673 for xf in self.transfers:
703 def ReverseBackwardEdges(self): argument
710 for xf in self.transfers:
743 def FindVertexSequence(self): argument
758 for xf in self.transfers:
766 for xf in self.transfers:
828 self.transfers = new_transfers
830 def GenerateDigraph(self): argument
832 for a in self.transfers:
833 for b in self.transfers:
849 def FindTransfers(self): argument
851 for tgt_fn, tgt_ranges in self.tgt.file_map.items():
856 src_ranges = self.src.file_map.get("__ZERO", empty)
858 "zero", self.transfers)
864 Transfer(tgt_fn, None, tgt_ranges, empty, "new", self.transfers)
867 elif tgt_fn in self.src.file_map:
869 Transfer(tgt_fn, tgt_fn, tgt_ranges, self.src.file_map[tgt_fn],
870 "diff", self.transfers)
874 if b in self.src_basenames:
876 src_fn = self.src_basenames[b]
877 Transfer(tgt_fn, src_fn, tgt_ranges, self.src.file_map[src_fn],
878 "diff", self.transfers)
882 if b in self.src_numpatterns:
887 src_fn = self.src_numpatterns[b]
888 Transfer(tgt_fn, src_fn, tgt_ranges, self.src.file_map[src_fn],
889 "diff", self.transfers)
892 Transfer(tgt_fn, None, tgt_ranges, empty, "new", self.transfers)
894 def AbbreviateSourceNames(self): argument
895 for k in self.src.file_map.keys():
897 self.src_basenames[b] = k
899 self.src_numpatterns[b] = k