473,411 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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(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)

Oct 25 '05 #1
0 1469

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim J | last post by:
I have been trying to find some kind of authentication method or script (PHP/perl/javascript or other) to achieve the following, with no luck. Say there are 100 files at a site. A person can...
0
by: Christian Tismer | last post by:
Hi colleagues, this is my second attempt to get rid of the f_tstate field in frames. I need to find every user of this field. What am I talking about? Well, Python always has a thread state...
0
by: Christian Tismer | last post by:
Dear Python community, since I didn't get *any* reply to this request, either the request was bad or there is really nobody using f_tstate in a way that makes it urgent to keep. I will wait a...
4
by: siddurampure | last post by:
PLZ ANYBODY KNOWS WHY ICAP PROTOCOL IS USED?
1
by: Craig G | last post by:
we are looking at the possibility of using Aspose.Word in our asp.net application to produce a simple doc, which will be a batch of standardised letters with different names addresses etc just...
2
by: rocksoft | last post by:
Hi I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist in my application to populate the data from mysql database, i have got problem while...
1
by: JSievers | last post by:
Hallo. A good friend of me develops web suites, for example his own at: www.augenpunkte.de. As you can see there my friend is blind and also he uses a Braille-line to develop these projects. For...
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
6
by: raylopez99 | last post by:
Anybody use Strong Name Signing? I think this is used by default for Resource files, which is one reason perhaps I can't get my resource files to work (somehow the public key is messed up, perhaps...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.