IDLOutFile throws execption
Invalid index on diff check causes exception. This CL is
a trival check to ensure the line is not empty before
checking the first index for a 'comment'.
BUG= http://code.google.com/p/chromium/issues/detail?id=93436
TEST= python idl_c_header.py
R= [email protected]
Review URL: http://codereview.chromium.org/7677035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97775 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/generators/idl_outfile.py b/ppapi/generators/idl_outfile.py
index 100a49e..d643b2f 100644
--- a/ppapi/generators/idl_outfile.py
+++ b/ppapi/generators/idl_outfile.py
@@ -6,6 +6,7 @@
""" Output file objects for generator. """
+import difflib
import os
import time
import sys
@@ -14,6 +15,8 @@
from idl_option import GetOption, Option, ParseOptions
from stat import *
+Option('diff', 'Generate a DIFF when saving the file.')
+
def IsEquivelent(intext, outtext):
if not intext: return False
inlines = intext.split('\n')
@@ -32,6 +35,7 @@
inwords = inline.split()
outwords = outline.split()
+ if not inwords or not outwords: return False
if inwords[0] != outwords[0] or inwords[0] != '/*': return False
# Neither the year, nor the modified date need an exact match
@@ -86,6 +90,11 @@
InfoOut.Log('Output %s unchanged.' % self.filename)
return False
+ if GetOption('diff'):
+ for line in difflib.unified_diff(intext.split('\n'), outtext.split('\n'),
+ self.filename, 'NEW', n=1, lineterm=''):
+ ErrOut.Log(line)
+
try:
# If the directory does not exit, try to create it, if we fail, we
# still get the exception when the file is openned.
@@ -94,9 +103,10 @@
InfoOut.Log('Creating directory: %s\n' % basepath)
os.makedirs(basepath)
- outfile = open(filename, 'w')
- outfile.write(''.join(self.outlist))
- InfoOut.Log('Output %s written.' % self.filename)
+ if not GetOption('test'):
+ outfile = open(filename, 'w')
+ outfile.write(outtext)
+ InfoOut.Log('Output %s written.' % self.filename)
return True
except IOError as (errno, strerror):