Created
March 7, 2013 08:57
-
-
Save hallvors/5106584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys, json | |
from difflib import SequenceMatcher | |
from operator import itemgetter, attrgetter | |
path1 = sys.argv[1] | |
path2 = sys.argv[2] | |
ordered_differences_list=[] | |
if not (path1 and path2 ) : | |
print 'Usage dircomp.py path1 path2' | |
exit() | |
count=0 | |
for root, dirs, files in os.walk(path1): | |
for name in files: | |
print str(count)+' '+os.path.join(root, name) | |
if not os.path.isfile(path2+name): | |
continue | |
with open(os.path.join(root, name), 'r') as f1: | |
c1=f1.read() | |
with open(os.path.join(path2, name), 'r') as f2: | |
c2=f2.read() | |
s=SequenceMatcher(None, c1, c2) | |
if s.ratio()<1: | |
ordered_differences_list.append( [name, s.ratio() ] ) | |
count +=1 | |
ordered_differences_list.sort( key=itemgetter(1) ) | |
print ordered_differences_list | |
#with open('lastdircomp.txt', 'w') as outf: | |
# json.dump(ordered_differences_list, outf) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment