Formatting, typo, and speedup from RELEASE-3_2 compareSICS.py

This commit is contained in:
Douglas Clowes
2014-11-03 11:46:51 +11:00
parent 13d3772078
commit 71475199d9

View File

@ -119,7 +119,7 @@ def load_dir(theDir):
if file.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")): if file.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")):
continue continue
if file.startswith(("core.", "SICServer")): if file.startswith(("core.", "SICServer")):
continue continue
if not file in myDirs: if not file in myDirs:
myDirs[file] = {} myDirs[file] = {}
myDirs[file][root[theLen:]] = {} myDirs[file][root[theLen:]] = {}
@ -184,7 +184,7 @@ if __name__ == "__main__":
if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")): if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")):
continue continue
if key.startswith(("core.", "SICServer")): if key.startswith(("core.", "SICServer")):
continue continue
for entry in sorted(gmap[key]): for entry in sorted(gmap[key]):
if entry.endswith(("/data", "/log")): if entry.endswith(("/data", "/log")):
continue continue
@ -202,7 +202,7 @@ if __name__ == "__main__":
if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")): if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")):
continue continue
if key.startswith(("core.", "SICServer")): if key.startswith(("core.", "SICServer")):
continue continue
for entry in sorted(gmap[key]): for entry in sorted(gmap[key]):
target = os.path.join(entry, key) target = os.path.join(entry, key)
#print "Looking in fmap for", os.path.join(entry, key) #print "Looking in fmap for", os.path.join(entry, key)
@ -219,7 +219,8 @@ if __name__ == "__main__":
if not os.path.exists(destin): if not os.path.exists(destin):
print " ", destin, "does not exist" print " ", destin, "does not exist"
continue continue
delta = list(difflib.unified_diff(\ if args.show:
delta = list(difflib.unified_diff(\
open(source).read().splitlines(),\ open(source).read().splitlines(),\
open(destin).read().splitlines(),\ open(destin).read().splitlines(),\
fromfile=source,\ fromfile=source,\
@ -227,6 +228,10 @@ if __name__ == "__main__":
fromfiledate=datetime.datetime.fromtimestamp(os.path.getmtime(source)),\ fromfiledate=datetime.datetime.fromtimestamp(os.path.getmtime(source)),\
tofiledate=datetime.datetime.fromtimestamp(os.path.getmtime(destin)),\ tofiledate=datetime.datetime.fromtimestamp(os.path.getmtime(destin)),\
lineterm="")) lineterm=""))
elif open(source).read() == open(destin).read():
delta = []
else:
delta = [""]
delta_len = len(delta) delta_len = len(delta)
if delta_len > 0: if delta_len > 0:
print_list[destin] = (source, list(delta)) print_list[destin] = (source, list(delta))
@ -240,7 +245,7 @@ if __name__ == "__main__":
else: else:
print args.command, source, destin print args.command, source, destin
else: else:
print source, destin, "#%d" % len(delta) print source, destin
if args.show: if args.show:
for line in delta: for line in delta:
print line print line
@ -267,7 +272,7 @@ if __name__ == "__main__":
if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")): if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")):
continue continue
if key.startswith(("core.", "SICServer")): if key.startswith(("core.", "SICServer")):
continue continue
for entry in sorted(gmap[key]): for entry in sorted(gmap[key]):
target = os.path.join(entry, key) target = os.path.join(entry, key)
#print "Looking in fmap for", os.path.join(entry, key) #print "Looking in fmap for", os.path.join(entry, key)
@ -286,7 +291,7 @@ if __name__ == "__main__":
if len(lines) > 0: if len(lines) > 0:
tgt = "/tmp/link_%s" % str(os.getpid()) tgt = "/tmp/link_%s" % str(os.getpid())
if (os.path.exists(tgt)): if (os.path.exists(tgt)):
for root, disr, files in os.walk(tgt, topdown=False): for root, dirs, files in os.walk(tgt, topdown=False):
for name in files: for name in files:
os.remove(os.path.join(root, name)) os.remove(os.path.join(root, name))
for name in dirs: for name in dirs:
@ -327,7 +332,7 @@ if __name__ == "__main__":
if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")): if key.endswith((".swp", ".swo", ".hdf", "~", ".bck", ".pyc")):
continue continue
if key.startswith(("core.", "SICServer")): if key.startswith(("core.", "SICServer")):
continue continue
for entry in sorted(gmap[key]): for entry in sorted(gmap[key]):
target = os.path.join(entry, key) target = os.path.join(entry, key)
#print "Looking in fmap for", os.path.join(entry, key) #print "Looking in fmap for", os.path.join(entry, key)
@ -378,5 +383,3 @@ if __name__ == "__main__":
except: except:
pass pass
print "Copies (%d) in: %s" % (count, tgt) print "Copies (%d) in: %s" % (count, tgt)