Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
d9a464ee
Commit
d9a464ee
authored
Mar 27, 2012
by
Matthew Williams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added format_advanced jinja filter to template module
parent
e2deb94e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletions
+17
-1
library/template
+17
-1
No files found.
library/template
View file @
d9a464ee
...
...
@@ -19,6 +19,7 @@
import
sys
import
os
import
collections
import
jinja2
import
shlex
try
:
...
...
@@ -26,6 +27,21 @@ try:
except
ImportError
:
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
# to a dictionary
...
...
@@ -91,7 +107,7 @@ if os.path.exists(dest):
md5sum
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
.
split
()[
0
]
# call Jinja2 here and save the new template file
template
=
jinja2
.
Template
(
source
)
template
=
environment
.
from_string
(
source
)
data_out
=
template
.
render
(
data
)
f
=
open
(
dest
,
"w+"
)
f
.
write
(
data_out
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment