summaryrefslogtreecommitdiff
path: root/rdiff-backup/src/myrdiff.py
diff options
context:
space:
mode:
Diffstat (limited to 'rdiff-backup/src/myrdiff.py')
-rwxr-xr-xrdiff-backup/src/myrdiff.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/rdiff-backup/src/myrdiff.py b/rdiff-backup/src/myrdiff.py
new file mode 100755
index 0000000..48485f7
--- /dev/null
+++ b/rdiff-backup/src/myrdiff.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+"""Like rdiff, but written in python and uses librsync module.
+
+Useful for benchmarking and testing of librsync and _librsync.
+
+"""
+
+import librsync, sys
+blocksize = 32768
+
+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()
+
+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 makepatch(basis_path, delta_path, new_path):
+ """Write new given basis and delta"""
+ pf = librsync.PatchedFile(open(basis_path, "rb"), open(delta_path, "rb"))
+ fout = open(new_path, "wb")
+ while 1:
+ buf = pf.read(blocksize)
+ if not buf: break
+ fout.write(buf)
+ assert not pf.close()
+ assert not fout.close()
+
+if sys.argv[1] == "signature":
+ makesig(sys.argv[2], sys.argv[3])
+elif sys.argv[1] == "delta":
+ makedelta(sys.argv[2], sys.argv[3], sys.argv[4])
+elif sys.argv[1] == "patch":
+ makepatch(sys.argv[2], sys.argv[3], sys.argv[4])
+else: assert 0, "Bad mode argument %s" % (sys.argv[1],)