diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2017-03-13 15:28:13 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2017-03-13 15:45:25 +0800 |
commit | cc72a258e683bfc98d557d6f1fb55e82febf8fae (patch) | |
tree | b43115cfce35e2a65df58feb78fcf78f41c6d6c8 | |
parent | e38bb3d8ee2cfb5cc9d26859346a823cb3363509 (diff) | |
download | adwaita-icon-theme-cc72a258e683bfc98d557d6f1fb55e82febf8fae.tar.gz |
win32/replace.py: Sync with GLib master
This enables us to generate the .pc files upon 'nmake install'.
-rw-r--r-- | win32/replace.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/win32/replace.py b/win32/replace.py index ea75dafa5..a81bab942 100644 --- a/win32/replace.py +++ b/win32/replace.py @@ -2,7 +2,11 @@ # # Simple utility script to manipulate # certain types of strings in a file -# + +# This can be used in various projects where +# there is the need to replace strings in files, +# and is copied from GLib's $(srcroot)/build/win32 + # Author: Fan, Chun-wei # Date: September 03, 2014 @@ -17,12 +21,19 @@ valid_actions = ['remove-prefix', 'replace-str', 'remove-str'] -def replace(src, dest, instring, outstring): +def replace_multi(src, dest, replace_items): with open(src, 'r') as s: with open(dest, 'w') as d: for line in s: - i = line.replace(instring, outstring) - d.write(i) + replace_dict = dict((re.escape(key), value) \ + for key, value in replace_items.items()) + replace_pattern = re.compile("|".join(replace_dict.keys())) + d.write(replace_pattern.sub(lambda m: \ + replace_dict[re.escape(m.group(0))], line)) + +def replace(src, dest, instring, outstring): + replace_item = {instring: outstring} + replace_multi(src, dest, replace_item) def check_required_args(args, params): for param in params: |