mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-23 21:35:28 +00:00
27 lines
631 B
Python
27 lines
631 B
Python
|
|
||
|
import sys
|
||
|
import re
|
||
|
import json
|
||
|
|
||
|
in_filename = sys.argv[1]
|
||
|
out_filename = sys.argv[2]
|
||
|
vars = json.loads(sys.argv[3])
|
||
|
|
||
|
with open(in_filename, "r") as f:
|
||
|
content = f.read()
|
||
|
|
||
|
content = content.replace("\\\"", "\"")
|
||
|
|
||
|
varname_pattern = re.compile("[A-Za-z0-9_]+")
|
||
|
for name, value in vars.items():
|
||
|
if varname_pattern.fullmatch(name) is None:
|
||
|
print("Name \"{}\" is not a valid variable name.".format(name))
|
||
|
continue
|
||
|
|
||
|
pattern = "\\$\\$({}|\\{{{}\\}})".format(name, name)
|
||
|
print(pattern)
|
||
|
content = re.sub(pattern, re.escape(str(value)), content)
|
||
|
|
||
|
with open(out_filename, "w") as f:
|
||
|
f.write(content)
|