3 from __future__ import print_function
5 # file ReplaceValues.py
7 # This file is part of LyX, the document processor.
8 # Licence details can be found in the file COPYING.
10 # author: Kornel Benko, kornel@lyx.org
12 # Syntax: ReplaceValues.py [<var1>=<Subst1> [<var2>=<Subst> ...]] <Inputfile> [<Inputfile> ...]
18 Subst = {} # map of desired substitutions
22 matchingS = "\\b|\\b".join(Subst.keys())
23 pattern = "".join(["(.*)(\\b", matchingS, "\\b)(.*)"])
24 return re.compile(pattern)
26 def SubstituteDataInLine(line):
28 m = prog.match(result)
30 return "".join([SubstituteDataInLine(m.group(1)),
32 SubstituteDataInLine(m.group(3))])
36 def SubstituteDataInFile(InFile):
37 for line in codecs.open(InFile, 'r', 'utf-8'):
38 print(SubstituteDataInLine(line[:-1]).encode("utf-8"))
40 ##########################################
45 del args[0] # we don't need the name ot this script
48 entry = args[0].split("=",1)
56 SubstituteDataInFile(args[0])