Has anybody used cx_bsdiff?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • News Reader

    #1

    Has anybody used cx_bsdiff?

    Hello,

    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.

    NR.

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

    import bsdiff, bz2
    import cPickle as pickle
    from filecmp import dircmp


    def diffdir(compara tor, basepath=''):
    return [os.path.join(ba sepath, fname)
    for fname in comparator.diff _files]


    def descend(compara tor, basepath=''):
    print 'Examining "%s"...' % basepath
    yield diffdir(compara tor, basepath)
    for subdir in comparator.subd irs:
    subname = os.path.join(ba sepath, subdir)
    subcmp = comparator.subd irs[subdir]
    for subresult in descend(subcmp, subname):
    yield subresult


    def compare_all(ori g_dir, fix_dir):
    patch = {}
    comparator = dircmp(orig_dir , fix_dir, [])
    for diff_list in descend(compara tor):
    for diff_file in diff_list:
    orig_fname = os.path.join(or ig_dir, diff_file)
    fix_fname = os.path.join(fi x_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(ori g_data, fix_data)
    patch[diff_file] = (dl, ctrl, dblock, xblock)
    print 'Done.'
    return patch


    def fix_all(tofix_d ir, patch):
    for fname in patch:
    orig_fname = os.path.join(to fix_dir, fname)
    print 'Fixing %s...' % orig_fname
    datafile = open(orig_fname , 'rb')
    orig_data = datafile.read()
    datafile.close( )
    fix_data = bsdiff.Patch(or ig_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(fil ename, 'wb')
    compressed.writ e(pickle.dumps( object, protocol))
    compressed.clos e()


    def load(filename):
    compressed = bz2.BZ2File(fil ename, 'rb')
    object = pickle.loads(co mpressed.read() )
    compressed.clos e()
    return object


    def make_patch():
    orig_dir = raw_input('Orig inal Directory: ')
    fix_dir = raw_input('Fixe d Directory: ')
    savepatch = raw_input('Save result? (y/n): ')
    if savepatch == 'y':
    patchname = raw_input('Patc h file name: ')
    else: savepatch = ''
    patch = compare_all(ori g_dir, fix_dir)
    if savepatch:
    save(patch, patchname)

Working...