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
bf0f3eac
Commit
bf0f3eac
authored
Mar 27, 2012
by
Matthew Williams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catch jinja template errors in template module
parent
9d9e3d8c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
library/template
+20
-6
No files found.
library/template
View file @
bf0f3eac
...
...
@@ -26,6 +26,8 @@ try:
except
ImportError
:
import
simplejson
as
json
environment
=
jinja2
.
Environment
()
# ===========================================
# convert arguments of form a=b c=d
# to a dictionary
...
...
@@ -57,9 +59,17 @@ if not os.path.exists(metadata):
sys
.
exit
(
1
)
# raise an error if we can't parse the template metadata
#data = {}
try
:
f
=
open
(
metadata
)
data
=
json
.
loads
(
f
.
read
())
# Hack by mgw to get nested variables -- use at your own risk
# data_in = json.loads(f.read())
# for k, v in data_in.items():
# try:
# data[k] = eval(v)
# except:
# data[k] = v
f
.
close
()
except
:
print
json
.
dumps
({
...
...
@@ -90,16 +100,20 @@ md5sum = None
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
)
data_out
=
template
.
render
(
data
)
try
:
# call Jinja2 here and save the new template file
template
=
environment
.
from_string
(
source
)
data_out
=
template
.
render
(
data
)
except
jinja2
.
TemplateError
as
e
:
print
json
.
dumps
({
"failed"
:
True
,
"msg"
:
e
.
message
})
sys
.
exit
(
1
)
f
=
open
(
dest
,
"w+"
)
f
.
write
(
data_out
)
f
.
close
()
# TODO: catch templating errors and do not clobber the file on the
# other end unless things were successful
# record m5sum and return success and whether things have changed
md5sum2
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
.
split
()[
0
]
...
...
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