Has anybody used cx_bsdiff?

2005-10-25 Thread News Reader
Hello,

I am trying to use cx_bsdiff 
(http://starship.python.net/crew/atuining/cx_bsdiff/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.

NR.

=

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()
 datafile.close()
 fix_data = bsdiff.Patch(orig_data, *patch[fname])
 datafile = open('%s-fixed' % orig_fname, 'wb')
 datafile.write(fix_data)
 datafile.close()
 os.remove(orig_fname)
 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))
 compressed.close()


def load(filename):
 compressed = bz2.BZ2File(filename, 'rb')
 object = pickle.loads(compressed.read())
 compressed.close()
 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)

-- 
http://mail.python.org/mailman/listinfo/python-list


XML + Elementree + (ZODB or Durus) experiments?

2006-01-23 Thread News Reader
A year or so ago, there was a posting - I believe on someone's blog - 
which told of a unique experiment.  The experimenter tried loading and 
searching a large XML document based on three strategies:

1. (I think) elementree directly
2. Store entire XML document in ZODB (or Durus, can't remember)
3. Subclass Elementree.Element, store each XML node separately in the 
ZODB/Durus.

The experimenter then did timings on opening up and using the XML 
documents in each of these three ways.

Does anybody remember that post?  Does any body have a link, code, 
cache, anything?

Please reply to the list, as the email address is invalid.

Thanks,

E. List


-- 
http://mail.python.org/mailman/listinfo/python-list