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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.recipe.template
Commits
7fa2695a
Commit
7fa2695a
authored
Feb 01, 2022
by
Julien Muchembled
7
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 @@
Similar to the default recipe but the template syntax is Jinja2 instead of
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.
- Dependencies are explicit (see ``context`` option) instead of deduced from
the template.
- 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::
>>> write('buildout.cfg',
...
...
slapos/recipe/template/__init__.py
View file @
7fa2695a
...
...
@@ -71,24 +71,31 @@ class Recipe(object):
self
.
mode
=
int
(
mode
,
8
)
if
mode
else
None
self
.
_init
(
name
,
options
)
def
_init
(
self
,
name
,
options
):
self
.
output
=
options
[
'output'
]
rendered
=
options
.
get
(
'inline'
)
def
_template
(
self
,
options
):
inline
=
options
.
get
(
'inline'
)
try
:
url
=
options
[
'url'
]
except
KeyError
:
if
rendered
is
None
:
if
inline
is
None
:
raise
if
self
.
md5sum
:
raise
UserError
(
"options 'inline' & 'md5sum' conflict"
)
self
.
md5sum
=
True
# tell update() to do nothing
self
.
rendered
=
rendered
return
True
,
inline
else
:
if
rendered
:
if
inline
:
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
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
):
path
,
is_temp
=
zc
.
buildout
.
download
.
Download
(
...
...
slapos/recipe/template/jinja2_template.py
View file @
7fa2695a
...
...
@@ -165,8 +165,17 @@ class Recipe(Recipe):
delimiter
=
import_delimiter
)
else
:
loader
=
None
try
:
self
.
output
=
options
[
'output'
]
except
KeyError
:
# BBB
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
()
for
y
in
options
.
get
(
'extensions'
,
''
).
split
())
if
x
]
self
.
context
=
context
=
DEFAULT_CONTEXT
.
copy
()
...
...
@@ -187,11 +196,10 @@ class Recipe(Recipe):
loader
=
loader
)
def
_render
(
self
):
template
=
self
.
template
env
=
self
.
env
i
f
template
.
startswith
(
'inline:'
):
source
=
template
[
7
:].
lstrip
(
'
\
r
\
n
'
)
compiled_source
=
env
.
compile
(
sourc
e
,
filename
=
'<inline>'
)
i
nline
,
template
=
self
.
template
if
inline
:
compiled_source
=
env
.
compile
(
templat
e
,
filename
=
'<inline>'
)
else
:
try
:
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