diff options
author | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-15 22:08:56 +0000 |
---|---|---|
committer | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-15 22:08:56 +0000 |
commit | 5b497ed43fe89fefb0bc456a5f324bdd56f61867 (patch) | |
tree | d64d528880eddbb803edf46687ecd393e5ad93c1 /ppapi/generators/idl_outfile.py | |
parent | 52c6760bbf8ac02513dc686c5b461767fbbf31a5 (diff) | |
download | chromium_src-5b497ed43fe89fefb0bc456a5f324bdd56f61867.zip chromium_src-5b497ed43fe89fefb0bc456a5f324bdd56f61867.tar.gz chromium_src-5b497ed43fe89fefb0bc456a5f324bdd56f61867.tar.bz2 |
Add idl_option
Cleanup IDL parser by unifying option processing code.
BUG=77551
TEST= python idl_parser.py --test
Review URL: http://codereview.chromium.org/6993005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/generators/idl_outfile.py')
-rw-r--r-- | ppapi/generators/idl_outfile.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/ppapi/generators/idl_outfile.py b/ppapi/generators/idl_outfile.py index a9e4506..76262d7 100644 --- a/ppapi/generators/idl_outfile.py +++ b/ppapi/generators/idl_outfile.py @@ -22,9 +22,10 @@ from stat import * # the output files are used by a timestamp dependent build system # class IDLOutFile(object): - def __init__(self, filename, always_write = False): + def __init__(self, filename, always_write = False, create_dir = True): self.filename = filename self.always_write = always_write + self.create_dir = create_dir self.outlist = [] self.open = True @@ -36,15 +37,27 @@ class IDLOutFile(object): # Close the file def Close(self): + filename = os.path.realpath(self.filename) self.open = False outtext = ''.join(self.outlist) if not self.always_write: - intext = open(filename, 'r').read() + if os.path.isfile(filename): + intext = open(filename, 'r').read() + else: + intext = None + if intext == outtext: InfoOut.Log('Output %s unchanged.' % self.filename) return False try: + # If the directory does not exit, try to create it, if we fail, we + # still get the exception when the file is openned. + basepath, leafname = os.path.split(filename) + if basepath and not os.path.isdir(basepath) and self.create_dir: + 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) |