def sig_file_test_helper(self, blocksize, iterations, file_len=None):
        """Compare SigFile output to rdiff output at given blocksize"""
        for i in range(iterations):
            MakeRandomFile(self.basis.path, file_len)
            self._clean_file(self.sig)
            rdiff_help_text = subprocess.check_output(["rdiff", "--help"])
            if b'-R' in rdiff_help_text:
                assert not os.system(
                    b"rdiff -b %i -R rollup -H md4 signature %b %b" %
                    (blocksize, self.basis.path, self.sig.path))
            elif b'-H' in rdiff_help_text:
                assert not os.system(
                    b"rdiff -b %i -H md4 signature %b %b" %
                    (blocksize, self.basis.path, self.sig.path))
            else:
                assert not os.system(
                    b"rdiff -b %i signature %b %b" %
                    (blocksize, self.basis.path, self.sig.path))
            with self.sig.open("rb") as fp:
                rdiff_sig = fp.read()

            sf = librsync.SigFile(self.basis.open("rb"), blocksize)
            librsync_sig = sf.read()
            sf.close()

            assert rdiff_sig == librsync_sig, \
                (len(rdiff_sig), len(librsync_sig))
Esempio n. 2
0
def get_signature(rp, blocksize=None):
    """Take signature of rpin file and return in file object"""
    if not blocksize:
        blocksize = _find_blocksize(rp.getsize())
    log.Log("Getting signature of file {fi} with blocksize {bs}".format(
        fi=rp, bs=blocksize), log.DEBUG)
    return librsync.SigFile(rp.open("rb"), blocksize)
Esempio n. 3
0
def makesig(inpath, outpath):
    """Write a signature of inpath at outpath"""
    sf = librsync.SigFile(open(inpath, "rb"))
    fout = open(outpath, "wb")
    while 1:
        buf = sf.read(blocksize)
        if not buf: break
        fout.write(buf)
    assert not sf.close()
    assert not fout.close()
Esempio n. 4
0
	def sig_file_test_helper(self, blocksize, iterations, file_len = None):
		"""Compare SigFile output to rdiff output at given blocksize"""
		for i in range(iterations):
			MakeRandomFile(self.basis.path, file_len)
			if self.sig.lstat(): self.sig.delete()
			assert not os.system("rdiff -b %s -H md4 signature %s %s" %
								 (blocksize, self.basis.path, self.sig.path))
			with self.sig.open("rb") as fp:
				rdiff_sig = fp.read()

			sf = librsync.SigFile(self.basis.open("rb"), blocksize)
			librsync_sig = sf.read()
			sf.close()

			assert rdiff_sig == librsync_sig, \
				   (len(rdiff_sig), len(librsync_sig))
Esempio n. 5
0
    def testSigGenerator(self):
        """Test SigGenerator, make sure it's same as SigFile"""
        for i in range(5):
            MakeRandomFile(self.basis.path)

            sf = librsync.SigFile(self.basis.open("rb"))
            sigfile_string = sf.read()
            sf.close()

            sig_gen = librsync.SigGenerator()
            infile = self.basis.open("rb")
            while 1:
                buf = infile.read(1000)
                if not buf: break
                sig_gen.update(buf)
            siggen_string = sig_gen.getsig()

            assert sigfile_string == siggen_string, \
                (len(sigfile_string), len(siggen_string))