summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuciana Fujii Pontello <fujii@cadence.com>2016-10-27 11:58:45 -0700
committerLuciana Fujii Pontello <fujii@cadence.com>2016-11-22 14:36:31 -0800
commitbc3237abd0742138b22b0d9e45719e6ca089302b (patch)
treebdab8be18ea0662ba22f6b5ef96e76c7d8b78188
parent7608485200f83787b6958278c5cbfe9faccb1d76 (diff)
downloadwsdiff-bc3237abd0742138b22b0d9e45719e6ca089302b.tar.gz
wsdiff-bc3237abd0742138b22b0d9e45719e6ca089302b.tar.bz2
wsdiff-bc3237abd0742138b22b0d9e45719e6ca089302b.zip
Handle exceptions when opening files and close them
-rw-r--r--diff2HtmlCompare.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/diff2HtmlCompare.py b/diff2HtmlCompare.py
index 266606a..63aa39b 100644
--- a/diff2HtmlCompare.py
+++ b/diff2HtmlCompare.py
@@ -204,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)