Esempio n. 1
0
def common_rsync(patched_file, unpatched_file, resulting_file, blocksize):
	with open(unpatched_file, "rb") as unpatched, \
			open(patched_file, "rb") as patched, \
			open(resulting_file, "wb") as result:
		start = datetime.now()
		hashes = pyrsync2.blockchecksums(unpatched, blocksize)
		delta = pyrsync2.rsyncdelta(patched, hashes, blocksize)
		pyrsync2.patchstream(unpatched, result, delta, blocksize)
		duration = datetime.now() - start
	return duration
Esempio n. 2
0
    def test_patchstream_with_reorders(self):
        delta = self.get_delta(self.TEST_FILE_REORDERS)

        old_file = BytesIO(self.TEST_FILE)
        out_file = BytesIO()
        pyrsync2.patchstream(old_file,
                             out_file,
                             delta,
                             blocksize=self.TEST_BLOCK_SIZE)

        self.assertEqual(out_file.getvalue(), self.TEST_FILE_REORDERS)
Esempio n. 3
0
    def test_patchstream_with_additions(self):
        delta = self.get_delta(self.TEST_FILE_ADDITIONS)

        old_file = BytesIO(self.TEST_FILE)
        out_file = BytesIO()
        pyrsync2.patchstream(old_file,
                             out_file,
                             delta,
                             blocksize=self.TEST_BLOCK_SIZE)

        self.assertEqual(out_file.getvalue(), self.TEST_FILE_ADDITIONS)
Esempio n. 4
0
def syncFile(srcFile, dstFile):
    unpatched = open(dstFile, 'rb')
    hashes = pyrsync2.blockchecksums(unpatched)
    patchedFile = open(srcFile, 'rb')
    delta = pyrsync2.rsyncdelta(patchedFile, hashes)
    unpatched.seek(0)
    save_to = open(dstFile, 'wb')
    pyrsync2.patchstream(unpatched, save_to, delta)


# linkData('test', "D:/Clement Research/Test", "")
Esempio n. 5
0
	def testCopying(self):
		with open("file1", "r+b") as file1, open("file2", "r+b") as file2:
			hashes2 = rsync.blockchecksums(file2)
			delta = rsync.rsyncdelta(file1, hashes2)
			print(hashes2)
			print(dir(hashes2))
			print(dir(delta))
			rsync.patchstream(file2, file2, delta)
		with open("file2", "r") as file2:
			line = file2.readline()
			self.assertEqual(TEXT, line)
			print(line)
Esempio n. 6
0
    def test_patchstream_with_reorders(self):
        delta = self.get_delta(self.TEST_FILE_REORDERS)

        old_file = BytesIO(self.TEST_FILE)
        out_file = BytesIO()
        pyrsync2.patchstream(
            old_file,
            out_file,
            delta,
            blocksize=self.TEST_BLOCK_SIZE
        )

        self.assertEqual(out_file.getvalue(), self.TEST_FILE_REORDERS)
Esempio n. 7
0
    def test_patchstream_with_additions(self):
        delta = self.get_delta(self.TEST_FILE_ADDITIONS)

        old_file = BytesIO(self.TEST_FILE)
        out_file = BytesIO()
        pyrsync2.patchstream(
            old_file,
            out_file,
            delta,
            blocksize=self.TEST_BLOCK_SIZE
        )

        self.assertEqual(out_file.getvalue(), self.TEST_FILE_ADDITIONS)
Esempio n. 8
0
	def testSingleDeltaForBigFile(self):
		# Create output file
		with open(BIG_OUT, "wb"):
			pass
		start = time.time()
		with open(BIG_OUT, "r+b") as outstream, open(BIG_IN, "rb") as instream:
			hashes = rsync.blockchecksums(outstream)
			deltas = rsync.rsyncdelta(instream, hashes)
			rsync.patchstream(outstream, outstream, deltas)
		finish = time.time()
		elapsed = finish - start
		print("Took " + str(elapsed) + " seconds")
		self.assertTrue(filecmp.cmp(BIG_IN, BIG_OUT, shallow=False))
Esempio n. 9
0
	def testMultipleDeltasForBigFile(self):
		# Create output file
		with open(BIG_OUT, "wb"):
			pass
		num_deltas = 0
		start = time.time()
		with open(BIG_OUT, "r+b") as outstream, open(BIG_IN, "rb") as instream:
			hashes = rsync.blockchecksums(outstream)
			deltas = rsync.rsyncdelta(instream, hashes)
			for delta in deltas:
				num_deltas += 1
				#print("delta: "+str(delta))
				rsync.patchstream(outstream, outstream, [delta])
		finish = time.time()
		elapsed = finish - start
		print("Took " + str(elapsed) + " seconds and "+str(num_deltas)+" individual deltas")
		self.assertTrue(filecmp.cmp(BIG_IN, BIG_OUT, shallow=False))