diff options
Diffstat (limited to 'scripts/FileGenerator.py')
-rw-r--r-- | scripts/FileGenerator.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/FileGenerator.py b/scripts/FileGenerator.py index 601030cbb..01a79bf99 100644 --- a/scripts/FileGenerator.py +++ b/scripts/FileGenerator.py @@ -4,14 +4,16 @@ # Generate or regenerate source files based on comments in those files. # May be modified in-place or a template may be generated into a complete file. -# Requires Python 2.4 or later +# Requires Python 2.5 or later # The files are copied to a string apart from sections between a # ++Autogenerated comment and a --Autogenerated comment which is # generated by the CopyWithInsertion function. After the whole string is # instantiated, it is compared with the target file and if different the file # is rewritten. -import codecs, os, string, sys +from __future__ import with_statement + +import codecs, os, re, string, sys lineEnd = "\r\n" if sys.platform == "win32" else "\n" @@ -148,3 +150,9 @@ def UpdateLineInFile(path, linePrefix, lineReplace): lines.append(l) contents = lineEnd.join(lines) + lineEnd UpdateFile(path, contents) + +def ReplaceREInFile(path, match, replace): + with codecs.open(path, "r", "utf-8") as f: + contents = f.read() + contents = re.sub(match, replace, contents) + UpdateFile(path, contents) |