Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.template
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
slapos.recipe.template
Commits
7fa2695a
Commit
7fa2695a
authored
Feb 01, 2022
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jinja2: rendered -> output, template -> url/inline
parent
70da5e82
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
17 deletions
+34
-17
slapos/recipe/template/README.jinja2.txt
slapos/recipe/template/README.jinja2.txt
+6
-4
slapos/recipe/template/__init__.py
slapos/recipe/template/__init__.py
+14
-7
slapos/recipe/template/jinja2_template.py
slapos/recipe/template/jinja2_template.py
+14
-6
No files found.
slapos/recipe/template/README.jinja2.txt
View file @
7fa2695a
...
@@ -5,15 +5,17 @@
...
@@ -5,15 +5,17 @@
Similar to the default recipe but the template syntax is Jinja2 instead of
Similar to the default recipe but the template syntax is Jinja2 instead of
buildout. Other significant differences are:
buildout. Other significant differences are:
- For historical reasons, the generated file is specified with ``rendered``
instead of ``output``.
- For historical reasons, the template is specified with ``template`` only
and an inline template is prefixed with ``inline:`` + an optional newline.
- Rendering, and download if requested, is done during the install phase.
- Rendering, and download if requested, is done during the install phase.
- Dependencies are explicit (see ``context`` option) instead of deduced from
- Dependencies are explicit (see ``context`` option) instead of deduced from
the template.
the template.
- Some extra features (options detailed below).
- Some extra features (options detailed below).
For backward compatibility, the following old options are still supported:
- The generated file can be specified with ``rendered`` instead of ``output``.
- The template can be specified with ``template`` instead of ``url``/``inline``.
An inline template is prefixed with ``inline:`` + an optional newline.
Example demonstrating some types::
Example demonstrating some types::
>>> write('buildout.cfg',
>>> write('buildout.cfg',
...
...
slapos/recipe/template/__init__.py
View file @
7fa2695a
...
@@ -71,24 +71,31 @@ class Recipe(object):
...
@@ -71,24 +71,31 @@ class Recipe(object):
self
.
mode
=
int
(
mode
,
8
)
if
mode
else
None
self
.
mode
=
int
(
mode
,
8
)
if
mode
else
None
self
.
_init
(
name
,
options
)
self
.
_init
(
name
,
options
)
def
_init
(
self
,
name
,
options
):
def
_template
(
self
,
options
):
self
.
output
=
options
[
'output'
]
inline
=
options
.
get
(
'inline'
)
rendered
=
options
.
get
(
'inline'
)
try
:
try
:
url
=
options
[
'url'
]
url
=
options
[
'url'
]
except
KeyError
:
except
KeyError
:
if
rendered
is
None
:
if
inline
is
None
:
raise
raise
if
self
.
md5sum
:
if
self
.
md5sum
:
raise
UserError
(
"options 'inline' & 'md5sum' conflict"
)
raise
UserError
(
"options 'inline' & 'md5sum' conflict"
)
self
.
md5sum
=
True
# tell update() to do nothing
self
.
md5sum
=
True
# tell update() to do nothing
self
.
rendered
=
rendered
return
True
,
inline
else
:
else
:
if
rendered
:
if
inline
:
raise
UserError
(
"options 'inline' & 'url' conflict"
)
raise
UserError
(
"options 'inline' & 'url' conflict"
)
return
False
,
url
def
_init
(
self
,
name
,
options
):
self
.
output
=
options
[
'output'
]
inline
,
template
=
self
.
_template
(
options
)
if
inline
:
self
.
rendered
=
template
else
:
options_sub
=
options
.
_sub
options_sub
=
options
.
_sub
self
.
rendered
=
'$'
.
join
(
options_sub
(
s
,
None
)
self
.
rendered
=
'$'
.
join
(
options_sub
(
s
,
None
)
for
s
in
self
.
_read
(
url
).
split
(
'$$'
))
for
s
in
self
.
_read
(
template
).
split
(
'$$'
))
def
_read
(
self
,
url
,
*
args
):
def
_read
(
self
,
url
,
*
args
):
path
,
is_temp
=
zc
.
buildout
.
download
.
Download
(
path
,
is_temp
=
zc
.
buildout
.
download
.
Download
(
...
...
slapos/recipe/template/jinja2_template.py
View file @
7fa2695a
...
@@ -165,8 +165,17 @@ class Recipe(Recipe):
...
@@ -165,8 +165,17 @@ class Recipe(Recipe):
delimiter
=
import_delimiter
)
delimiter
=
import_delimiter
)
else
:
else
:
loader
=
None
loader
=
None
try
:
self
.
output
=
options
[
'output'
]
except
KeyError
:
# BBB
self
.
output
=
options
[
'rendered'
]
self
.
output
=
options
[
'rendered'
]
self
.
template
=
options
[
'template'
]
template
=
options
[
'template'
]
if
template
.
startswith
(
'inline:'
):
self
.
template
=
True
,
template
[
7
:].
lstrip
(
'
\
r
\
n
'
)
else
:
self
.
template
=
False
,
template
else
:
self
.
template
=
self
.
_template
(
options
)
extension_list
=
[
x
for
x
in
(
y
.
strip
()
extension_list
=
[
x
for
x
in
(
y
.
strip
()
for
y
in
options
.
get
(
'extensions'
,
''
).
split
())
if
x
]
for
y
in
options
.
get
(
'extensions'
,
''
).
split
())
if
x
]
self
.
context
=
context
=
DEFAULT_CONTEXT
.
copy
()
self
.
context
=
context
=
DEFAULT_CONTEXT
.
copy
()
...
@@ -187,11 +196,10 @@ class Recipe(Recipe):
...
@@ -187,11 +196,10 @@ class Recipe(Recipe):
loader
=
loader
)
loader
=
loader
)
def
_render
(
self
):
def
_render
(
self
):
template
=
self
.
template
env
=
self
.
env
env
=
self
.
env
i
f
template
.
startswith
(
'inline:'
):
i
nline
,
template
=
self
.
template
source
=
template
[
7
:].
lstrip
(
'
\
r
\
n
'
)
if
inline
:
compiled_source
=
env
.
compile
(
sourc
e
,
filename
=
'<inline>'
)
compiled_source
=
env
.
compile
(
templat
e
,
filename
=
'<inline>'
)
else
:
else
:
try
:
try
:
compiled_source
=
compiled_source_cache
[
template
]
compiled_source
=
compiled_source_cache
[
template
]
...
...
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