55b67213 by Marcos Cano

fix engine to template only if matches

1 parent b9c9fb17
......@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME}]]
Term: [[{TERM}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
......
......@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME}]]
Term: [[{TERM}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
......
......@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME}]]
Term: [[{TERM}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
......
......@@ -4,8 +4,12 @@ var = [[{variable}]]
otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME}]]
Term: [[{TERM}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
[[{}]]
......
......@@ -21,7 +21,7 @@ class MyTemplate(string.Template):
(?P<escaped>\[\[\{)|
(?P<named>[_A-Z][_A-Z0-9]*)\}\]\]|
(?P<braced>[_A-Z][_A-Z0-9]*)\}\]\]|
(?P<invalid>)
(?P<invalid>^$)
)
'''
......@@ -59,18 +59,23 @@ def engine(ifile,ofile,vars):
template= MyTemplate(template_content)
#print 'MATCHES:', t.pattern.findall(t.template)
outputText = template.safe_substitute(vars)
print 'MATCHES:', template.pattern.findall(template.template)
if printit:
print "AFTER TEMPLATE:"
#print outputText
print outputText.encode('ascii', 'ignore')
else:
f = open(ofile,'w')
f.write(outputText.encode('ascii', 'ignore'))
f.close()
matches = template.pattern.findall(template.template)
print vars
if len(matches):
print '[ MATCHES ] - ', matches
outputText = template.safe_substitute(vars)
print "[ TEMPLATING ] - %s "%ifile
if printit:
print "AFTER TEMPLATE:"
#print outputText
print outputText.encode('ascii', 'ignore')
else:
f = open(ofile,'w')
f.write(outputText.encode('ascii', 'ignore'))
f.close()
......@@ -144,6 +149,7 @@ def main(argv):
for filename in files:
fullpath = os.path.join(path, filename)
if os.path.isfile(fullpath):
engine(fullpath, fullpath, vars)
count+=1
else:
......