summaryrefslogtreecommitdiff
path: root/rdiff-backup/misc/librsync-many-files.py
blob: 239d2fb6ea62083d3b88d97b4d902b8cdaa20953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

"""Use librsync to transform everything in one dir to another"""

import sys, os, librsync

dir1, dir2 = sys.argv[1:3]
for i in xrange(1000):
	dir1fn = "%s/%s" % (dir1, i)
	dir2fn = "%s/%s" % (dir2, i)

	# Write signature file
	f1 = open(dir1fn, "rb")
	sigfile = open("sig", "wb")
	librsync.filesig(f1, sigfile, 2048)
	f1.close()
	sigfile.close()

	# Write delta file
	f2 = open(dir2fn, "r")
	sigfile = open("sig", "rb")
	deltafile = open("delta", "wb")
	librsync.filerdelta(sigfile, f2, deltafile)
	f2.close()
	sigfile.close()
	deltafile.close()

	# Write patched file
	f1 = open(dir1fn, "rb")
	newfile = open("%s/%s.out" % (dir1, i), "wb")
	deltafile = open("delta", "rb")
	librsync.filepatch(f1, deltafile, newfile)
	f1.close()
	deltafile.close()
	newfile.close()