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
85a0709d
Commit
85a0709d
authored
Mar 27, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78 from mgwilliams/master
Catch jinja errors in template module
parents
3f9f8de0
3046f743
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
library/template
+13
-6
No files found.
library/template
View file @
85a0709d
...
...
@@ -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,6 +59,7 @@ 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
())
...
...
@@ -90,16 +93,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