468,284 Members | 1,603 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

Has anybody used cx_bsdiff?


I am trying to use cx_bsdiff
(http://starship.python.net/crew/atui...iff/index.html) to to
make a diff and patch some files. It appears that I can make the diff,
but when I apply the patch, the result is not the same.

As far as I understand the documentation, I am using this correctly.
Can anyone help me find what is wrong in the code below?

Thanks. Please reply to the list.


================================================== =======

import bsdiff, bz2
import cPickle as pickle
from filecmp import dircmp
def diffdir(comparator, basepath=''):
return [os.path.join(basepath, fname)
for fname in comparator.diff_files]
def descend(comparator, basepath=''):
print 'Examining "%s"...' % basepath
yield diffdir(comparator, basepath)
for subdir in comparator.subdirs:
subname = os.path.join(basepath, subdir)
subcmp = comparator.subdirs[subdir]
for subresult in descend(subcmp, subname):
yield subresult
def compare_all(orig_dir, fix_dir):
patch = {}
comparator = dircmp(orig_dir, fix_dir, [])
for diff_list in descend(comparator):
for diff_file in diff_list:
orig_fname = os.path.join(orig_dir, diff_file)
fix_fname = os.path.join(fix_dir, diff_file)
print 'Making diff of %s...' % diff_file
orig_data = open(orig_fname, 'rb').read()
fix_data = open(fix_fname, 'rb').read()
dl = len(fix_data)
ctrl, dblock, xblock = bsdiff.Diff(orig_data, fix_data)
patch[diff_file] = (dl, ctrl, dblock, xblock)
print 'Done.'
return patch
def fix_all(tofix_dir, patch):
for fname in patch:
orig_fname = os.path.join(tofix_dir, fname)
print 'Fixing %s...' % orig_fname
datafile = open(orig_fname, 'rb')
orig_data = datafile.read()
fix_data = bsdiff.Patch(orig_data, *patch[fname])
datafile = open('%s-fixed' % orig_fname, 'wb')
os.rename('%s-fixed' % orig_fname, orig_fname)
def save(object, filename, protocol=-1):
compressed = bz2.BZ2File(filename, 'wb')
compressed.write(pickle.dumps(object, protocol))
def load(filename):
compressed = bz2.BZ2File(filename, 'rb')
object = pickle.loads(compressed.read())
return object
def make_patch():
orig_dir = raw_input('Original Directory: ')
fix_dir = raw_input('Fixed Directory: ')
savepatch = raw_input('Save result? (y/n): ')
if savepatch == 'y':
patchname = raw_input('Patch file name: ')
else: savepatch = ''
patch = compare_all(orig_dir, fix_dir)
if savepatch:
save(patch, patchname)

Oct 25 '05 #1
0 1346

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Christian Tismer | last post: by
reply views Thread by Christian Tismer | last post: by
4 posts views Thread by siddurampure | last post: by
1 post views Thread by Craig G | last post: by
17 posts views Thread by raylopez99 | last post: by
6 posts views Thread by raylopez99 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.