aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/FileGenerator.py
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2013-07-03 09:34:20 +1000
committerNeil <nyamatongwe@gmail.com>2013-07-03 09:34:20 +1000
commitf18e3210bee6e4c3888ffd9f09f5242028317295 (patch)
treec6054ad4ce4908cb772ef4b69fb5d3efa79a365b /scripts/FileGenerator.py
parent6a57601bb9eb65c373e32ac4dfd26d4b21b3b66e (diff)
downloadscintilla-mirror-f18e3210bee6e4c3888ffd9f09f5242028317295.tar.gz
Restructured LexGen.py by moving discovery code into ScintillaData.py and
SciTE regeneration into ../scite/scripts/RegenerateSource.py. FileGenerator.py adds ReplaceREInFile function.
Diffstat (limited to 'scripts/FileGenerator.py')
-rw-r--r--scripts/FileGenerator.py12
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)