"Fossies" - the Fresh Open Source Software Archive

Member "cutter-1.8.2/scripts/meson_configure_qmake_in.py" (20 May 2019, 620 Bytes) of package /linux/privat/cutter-1.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "meson_configure_qmake_in.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.7.4_vs_1.8.0.

    1 
    2 import sys
    3 import re
    4 import json
    5 
    6 in_filename = sys.argv[1]
    7 out_filename = sys.argv[2]
    8 vars = json.loads(sys.argv[3])
    9 
   10 with open(in_filename, "r") as f:
   11     content = f.read()
   12 
   13 content = content.replace("\\\"", "\"")
   14 
   15 varname_pattern = re.compile("[A-Za-z0-9_]+")
   16 for name, value in vars.items():
   17     if varname_pattern.fullmatch(name) is None:
   18         print("Name \"{}\" is not a valid variable name.".format(name))
   19         continue
   20 
   21     pattern = "\\$\\$({}|\\{{{}\\}})".format(name, name)
   22     print(pattern)
   23     content = re.sub(pattern, str(value), content)
   24 
   25 with open(out_filename, "w") as f:
   26     f.write(content)