Created
September 3, 2014 09:37
-
-
Save bellisk/5f29c0415c3950e12a53 to your computer and use it in GitHub Desktop.
A script to make an HTML diff of two files.
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
#coding: utf-8 | |
import difflib | |
import sys | |
def make_html_diff(file1, file2, context): | |
diff_filename = 'diff_' + file1 + '_' + file2 + '.html' | |
with open(file1) as f1: | |
with open(file2) as f2: | |
with open(diff_filename, 'w') as diff: | |
d = difflib.HtmlDiff(wrapcolumn=60) | |
html = d.make_file(f1, f2, context=context, numlines=2) | |
print context | |
diff.write(html) | |
if __name__ == '__main__': | |
if len(sys.argv) < 4: | |
print "Usage: diff.py file1 file2 context(=True/False)" | |
else: | |
file1 = sys.argv[1] | |
file2 = sys.argv[2] | |
context = sys.argv[3] == 'True' | |
make_html_diff(file1, file2, context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment