summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@users.noreply.github.com>2016-11-22 21:17:55 -0500
committerGitHub <noreply@github.com>2016-11-22 21:17:55 -0500
commit3e34e7b53bed1ead89f7071d1ff07bdcb1a055ca (patch)
treebdab8be18ea0662ba22f6b5ef96e76c7d8b78188
parent6eebf9ba2629ee66ed4bdc588ede18daf97aafb6 (diff)
parentbc3237abd0742138b22b0d9e45719e6ca089302b (diff)
downloadwsdiff-3e34e7b53bed1ead89f7071d1ff07bdcb1a055ca.tar.gz
wsdiff-3e34e7b53bed1ead89f7071d1ff07bdcb1a055ca.tar.bz2
wsdiff-3e34e7b53bed1ead89f7071d1ff07bdcb1a055ca.zip
Merge pull request #3 from luciana-fujii/master
Small improvements.
-rw-r--r--diff2HtmlCompare.py47
-rw-r--r--requirements.txt2
-rw-r--r--templates/diff_template.html4
3 files changed, 41 insertions, 12 deletions
diff --git a/diff2HtmlCompare.py b/diff2HtmlCompare.py
index 9efc859..63aa39b 100644
--- a/diff2HtmlCompare.py
+++ b/diff2HtmlCompare.py
@@ -1,3 +1,26 @@
+# MIT License
+#
+# Copyright (c) 2016 Alex Goodman
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+# of the Software, and to permit persons to whom the Software is furnished to do
+# so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
import sys
import difflib
import argparse
@@ -173,10 +196,7 @@ class CodeDiff(object):
diffCssFile="./deps/diff.css"
diffJsFile="./deps/diff.js"
resetCssFile="./deps/reset.css"
- semanticCssFile="./deps/semantic.min.css"
- semanticJsFile="./deps/semantic.min.js"
jqueryJsFile="./deps/jquery.min.js"
- commentJsFile="./deps/comment.js"
def __init__(self, fromfile, tofile, fromtxt=None, totxt=None, name=None):
@@ -184,14 +204,26 @@ class CodeDiff(object):
self.filename = name
self.fromfile = fromfile
if fromtxt == None:
- self.fromlines = open(fromfile, 'U').readlines()
+ try:
+ with open(fromfile) as f:
+ self.fromlines = f.readlines()
+ except Exception as e:
+ print "Problem reading file %s" % fromfile
+ print e
+ sys.exit(1)
else:
self.fromlines = [n + "\n" for n in fromtxt.split("\n")]
self.leftcode = "".join(self.fromlines)
self.tofile = tofile
if totxt == None:
- self.tolines = open(tofile, 'U').readlines()
+ try:
+ with open(tofile) as f:
+ self.tolines = f.readlines()
+ except Exception as e:
+ print "Problem reading file %s" % tofile
+ print e
+ sys.exit(1)
else:
self.tolines = [n + "\n" for n in totxt.split("\n")]
self.rightcode = "".join(self.tolines)
@@ -259,17 +291,14 @@ class CodeDiff(object):
answers = {
"html_title": self.filename,
- "reset_css": self.resetCssFile,
+ "reset_css": self.resetCssFile,
"pygments_css": self.pygmentsCssFile,
"diff_css": self.diffCssFile,
- "semantic_css": self.semanticCssFile,
"page_title": self.filename,
"original_code": codeContents[0],
"modified_code": codeContents[1],
"jquery_js": self.jqueryJsFile,
- "semantic_js": self.semanticJsFile,
"diff_js": self.diffJsFile,
- "comment_js": self.commentJsFile,
}
self.htmlContents = diffTemplate % answers
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..459d6d5
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+mistune
+pygments
diff --git a/templates/diff_template.html b/templates/diff_template.html
index 2f8f90b..df86e70 100644
--- a/templates/diff_template.html
+++ b/templates/diff_template.html
@@ -11,7 +11,6 @@
modified_code: full html contents of modified file
jquery_js: path to jquery.min.js
diff_js: path to diff.js
- comment_js: path to comment.js
-->
<meta charset="utf-8">
<title>
@@ -74,6 +73,5 @@
</div>
<script src="%(jquery_js)s" type="text/javascript"></script>
<script src="%(diff_js)s" type="text/javascript"></script>
-<!--<script src="%(comment_js)s"></script>-->
</body>
-</html> \ No newline at end of file
+</html>