Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PaNOSC
Data Analysis Services
packme
Commits
30c6e192
Commit
30c6e192
authored
Jan 28, 2020
by
eric pellegrini
Browse files
added functionality for printing missing templates when rendering manifest.yml files
parent
10f8e674
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/packme/PackerTemplate.py
View file @
30c6e192
import
collections
import
glob
import
jinja2
import
jinja2.meta
import
json
import
os
import
pprint
import
sys
import
yaml
from
typing
import
Dict
,
List
...
...
@@ -270,12 +272,24 @@ class PackerTemplate:
node
[
"provisioners"
]
=
self
.
_provisioners
node
[
"post-processors"
]
=
self
.
_postprocessors
# Render the jinja2 templates with the parameters dictionary provided in the template file and the available environment variables
jinja_template
=
jinja2
.
Template
(
repr
(
node
))
s
=
jinja_template
.
render
(
environment
=
self
.
_environment
)
env
=
jinja2
.
Environment
(
undefined
=
jinja2
.
DebugUndefined
)
template
=
env
.
from_string
(
repr
(
node
))
rendered
=
template
.
render
(
**
self
.
_environment
)
# Check if rendering was done correctly
ast
=
env
.
parse
(
rendered
)
undefined
=
jinja2
.
meta
.
find_undeclared_variables
(
ast
)
if
undefined
:
print
(
f
'The following variables are undefined:
{
undefined
!
r
}
'
)
sys
.
exit
(
1
)
# Replace back %< .* %> to {{ .* }}
rendered
=
rendered
.
replace
(
"%<"
,
"{{"
)
rendered
=
rendered
.
replace
(
">%"
,
"}}"
)
# Dump to the output file
with
open
(
output_file
,
"w"
)
as
fout
:
json
.
dump
(
yaml
.
safe_load
(
s
),
fout
,
**
kwargs
)
json
.
dump
(
yaml
.
safe_load
(
rendered
),
fout
,
**
kwargs
)
def
__str__
(
self
)
->
str
:
"""Returns the string representation for this :class:`PackerTemplate`.
...
...
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