1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

resetting template.. previous commit not needed

This commit is contained in:
Matthew Williams 2012-03-27 09:10:51 -07:00
parent d9a464ee9d
commit 9d9e3d8c56

View file

@ -19,7 +19,6 @@
import sys import sys
import os import os
import collections
import jinja2 import jinja2
import shlex import shlex
try: try:
@ -27,21 +26,6 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
environment = jinja2.Environment()
def format_advanced(fmt, data):
# jinja2 filter to use advanced python string formatting
# e.g, {{ "{0} {1} {2}"|format_advanced(['a', 'b', 'c']) }}
# see http://docs.python.org/library/string.html#formatstrings
if isinstance(data, collections.Mapping):
return fmt.format(**data)
elif isinstance(data, collections.Sequence):
return fmt.format(*data)
else:
return data
environment.filters['format_advanced'] = format_advanced
# =========================================== # ===========================================
# convert arguments of form a=b c=d # convert arguments of form a=b c=d
# to a dictionary # to a dictionary
@ -107,7 +91,7 @@ if os.path.exists(dest):
md5sum = os.popen("md5sum %s" % dest).read().split()[0] md5sum = os.popen("md5sum %s" % dest).read().split()[0]
# call Jinja2 here and save the new template file # call Jinja2 here and save the new template file
template = environment.from_string(source) template = jinja2.Template(source)
data_out = template.render(data) data_out = template.render(data)
f = open(dest, "w+") f = open(dest, "w+")
f.write(data_out) f.write(data_out)