From 79e4be4ca6eefaba2b707861bbd3f484acf1b3b5 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 31 Oct 2014 12:14:49 +1100 Subject: [PATCH] Speed up compare by not use difflib if we dont need to (and fix type found by syntastic) --- site_ansto/instrument/compareSICS.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/site_ansto/instrument/compareSICS.py b/site_ansto/instrument/compareSICS.py index fe565bcf..d9fd0bac 100755 --- a/site_ansto/instrument/compareSICS.py +++ b/site_ansto/instrument/compareSICS.py @@ -219,7 +219,8 @@ if __name__ == "__main__": if not os.path.exists(destin): print " ", destin, "does not exist" continue - delta = list(difflib.unified_diff(\ + if args.show: + delta = list(difflib.unified_diff(\ open(source).read().splitlines(),\ open(destin).read().splitlines(),\ fromfile=source,\ @@ -227,6 +228,10 @@ if __name__ == "__main__": fromfiledate=datetime.datetime.fromtimestamp(os.path.getmtime(source)),\ tofiledate=datetime.datetime.fromtimestamp(os.path.getmtime(destin)),\ lineterm="")) + elif open(source).read() == open(destin).read(): + delta = [] + else: + delta = [""] delta_len = len(delta) if delta_len > 0: print_list[destin] = (source, list(delta)) @@ -240,7 +245,7 @@ if __name__ == "__main__": else: print args.command, source, destin else: - print source, destin, "#%d" % len(delta) + print source, destin if args.show: for line in delta: print line @@ -286,7 +291,7 @@ if __name__ == "__main__": if len(lines) > 0: tgt = "/tmp/link_%s" % str(os.getpid()) 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: os.remove(os.path.join(root, name)) for name in dirs: