fimplate take input from file
This commit is contained in:
@@ -7,10 +7,11 @@ def setup_options():
|
||||
|
||||
=== Template example: ===
|
||||
Hello [[name]]!
|
||||
|
||||
[[letter]]
|
||||
|
||||
== Value file/Value pair example: ==
|
||||
[[name]]=John
|
||||
[[name]]=John
|
||||
[[letter]]=@letter.txt
|
||||
""",formatter_class=RawTextHelpFormatter)
|
||||
parser.add_argument("-e",action="store_true",dest="env",default=False,
|
||||
help="Use the environment to replace ${env} style variables.")
|
||||
@@ -58,7 +59,12 @@ else:
|
||||
in_reader=open(options.template,'rb')
|
||||
for l in in_reader:
|
||||
for p in pairs:
|
||||
l=l.replace(p[0],p[1])
|
||||
value=p[1]
|
||||
if value[0]=="@":
|
||||
value=open(value[1:],'rt').read()
|
||||
elif value[0:2]=="\\@":
|
||||
value=value[1:]
|
||||
l=l.replace(p[0],value)
|
||||
if options.env:
|
||||
var_list=[m.group(0) for m in re.finditer('\${[^ ]+}', l)]
|
||||
for v in var_list:
|
||||
|
||||
Reference in New Issue
Block a user