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
commitdb454bdf6d717c9775079b292ee1a70b65cb449c (patch)
tree213019c30b4f9847c92c7ab2dba85b029977c0a7 /scripts/FileGenerator.py
parent69ece67efa4b4e99836f76ad8678d431ae1e316a (diff)
downloadscintilla-mirror-db454bdf6d717c9775079b292ee1a70b65cb449c.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)