User:Tardis/regdiff.py: Difference between revisions

Content deleted Content added
version 0.2: improved safety
version 0.3: check on and report progress
Line 4:
#Created November 9 2008
#Updated November 9 2008
#Version 0.23
 
#This program is free software; you can redistribute it and/or modify it under
Line 19:
#applying it transforms a registry represented by the first into a registry
#represented by the second. Usually you should redirect the output to a file.
 
#Set displayProgress to a positive value n to report with a # every n lines.
 
#Warnings:
Line 42 ⟶ 44:
# - support deletion disabling
# - detect misorderings
#Version 0.3, November 9 2008:
# - make allowKeyDelete apply to the last keys to delete
# - verify continuous progress
# - support displaying progress
 
#Bugs:
Line 157 ⟶ 163:
allowKeyDelete=True
allowValueDelete=True
displayProgress=0
ci=codecs.lookup("utf_16")
fo=ci.streamreader(open(sys.argv[1],'rb'))
Line 170 ⟶ 177:
o.old=True
killing=False # the tree being deleted, if any
iters=0
while True:
iters+=1
if displayProgress and iters%displayProgress==0:
sys.stderr.write('#')
 
if o.old: o=line(nextLogical(fo),o)
if n.old: n=line(nextLogical(fn),n)
Line 184 ⟶ 196:
o.old=c<=0
n.old=c>=0
assert o.old or n.old,"not advancing in the file"
 
if killing and (o.eof or not isunder(o.lastkey,killing)): killing=False
Line 192 ⟶ 205:
# Delete a whole key if the new file is past all its subkeys.
# Note that n.lastkey!=o.name, because n must be a key.
if (n.eof or not isunder(n.lastkey,o.name)) and allowKeyDelete:
killing=o.name
out.write("\r\n[-"+o.name+"]\r\n")
Line 203 ⟶ 216:
 
out.write("\r\n")
if displayProgress: sys.stderr.write('\n')
</source>