From db454bdf6d717c9775079b292ee1a70b65cb449c Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 3 Jul 2013 09:34:20 +1000 Subject: Restructured LexGen.py by moving discovery code into ScintillaData.py and SciTE regeneration into ../scite/scripts/RegenerateSource.py. FileGenerator.py adds ReplaceREInFile function. --- scripts/FileGenerator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'scripts/FileGenerator.py') 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) -- cgit v1.2.3