def testDelta(self): """Test delta generation by making sure rdiff can process output There appears to be some indeterminism so we can't just byte-compare the deltas produced by rdiff and DeltaFile. """ MakeRandomFile(self.basis.path) self._clean_file(self.sig) assert not os.system(b"rdiff signature %s %s" % (self.basis.path, self.sig.path)) for i in range(5): MakeRandomFile(self.new.path) df = librsync.DeltaFile(self.sig.open("rb"), self.new.open("rb")) librsync_delta = df.read() df.close() fp = self.delta.open("wb") fp.write(librsync_delta) fp.close() self._clean_file(self.new2) assert not os.system( b"rdiff patch %s %s %s" % (self.basis.path, self.delta.path, self.new2.path)) new_fp = self.new.open("rb") new = new_fp.read() new_fp.close() new2_fp = self.new2.open("rb") new2 = new2_fp.read() new2_fp.close() assert new == new2, (len(new), len(new2))
def makedelta(sigpath, newpath, deltapath): """Write delta at deltapath using signature at sigpath""" df = librsync.DeltaFile(open(sigpath, "rb"), open(newpath, "rb")) fout = open(deltapath, "wb") while 1: buf = df.read(blocksize) if not buf: break fout.write(buf) assert not df.close() assert not fout.close()
def OldtestDelta(self): """Test delta generation against Rdiff""" MakeRandomFile(self.basis.path) assert not os.system("rdiff signature %s %s" % (self.basis.path, self.sig.path)) for i in range(5): MakeRandomFile(self.new.path) assert not os.system("rdiff delta %s %s %s" % (self.sig.path, self.new.path, self.delta.path)) fp = self.delta.open("rb") rdiff_delta = fp.read() fp.close() df = librsync.DeltaFile(self.sig.open("rb"), self.new.open("rb")) librsync_delta = df.read() df.close() print(len(rdiff_delta), len(librsync_delta)) print(repr(rdiff_delta[:100])) print(repr(librsync_delta[:100])) assert rdiff_delta == librsync_delta
def write_delta(basis, new, delta, compress=None): """Write rdiff delta which brings basis to new""" log.Log("Writing delta {de} from basis {ba} to new {ne}".format( ba=basis, ne=new, de=delta), log.DEBUG) deltafile = librsync.DeltaFile(get_signature(basis), new.open("rb")) delta.write_from_fileobj(deltafile, compress)
def get_delta_sigrp_hash(rp_signature, rp_new): """Like above but also calculate hash of new as close() value""" log.Log("Getting delta (with hash) of file {fi} with signature {si}".format( fi=rp_new, si=rp_signature), log.DEBUG) return librsync.DeltaFile( rp_signature.open("rb"), hash.FileWrapper(rp_new.open("rb")))