1
0
Fork 0
mirror of synced 2024-11-16 06:15:34 -05:00
Commit graph

16 commits

Author SHA1 Message Date
Erik Flodin
8ba9823407
Rewrite default template to handle nested ifs, != and env vars in if
The awk script now performs all processing in the BEGIN block using an
implementation that is capable of handling if statements which contain nested
if statments (fixes #436). To make nested ifs look better, if, else and endif
lines can now have optional whitespace before {%.

Includes are now handled in the same way as the main file which means that
included files can both include other files and have if statements in addition
to variables (fixes #406). Include lines can now also have optional whitespace
before {%.

All variables are handled in the same way now so it's now possible to use env
variables in if statements (fixes #488).

Also add support for != in addition to == (fixes #358). Thus it's now
e.g. possible to check if a variable is set (#477) by doing:

{% if yadm.class != ""%}
Class is set to {{ yadm.class }}
{% endif %}

A non-existing yadm or env variable is now replaced with the empty string.
2024-11-04 22:30:23 +01:00
Tim Byrne
76ce3defea
Changes for black compliance 2023-07-12 09:20:00 -05:00
Tim Byrne
50bf8716cd
Unify template support for classes (#185) 2022-02-21 11:31:44 -06:00
Tim Byrne
0b75e71237
Merge pull request #347 from rasa/develop 2022-02-17 16:45:45 -06:00
Ross Smith II
487f030405
Update test/test_unit_template_default.py
Co-authored-by: Paulo Köch <paulo.koch@gmail.com>
2022-02-17 16:45:07 -06:00
Paulo Köch
b0e0856658
Add test 2022-02-17 16:44:57 -06:00
Tim Byrne
027c7359ac
Merge pull request #304 from erijo/multiple-classes 2022-01-22 18:14:23 -06:00
Tim Byrne
5ae553b078
Add support for distro_family (#213)
Obtained from /etc/os-release: ID_LIKE.
Alternate attributes f & distro_family.
2022-01-22 18:05:15 -06:00
Erik Flodin
42c74efbac
Add support for multiple local classes
A local class is set with:
$ yadm config local.class cls1

More classes can be added with:
$ yadm config --add local.class cls2
$ yadm config --add local.class cls3

Any of cls1, cls2 and cls3 can be used in an alternate condition.

For templates, the existing variable yadm.class/YADM_CLASS is set to
the last class (i.e. cls3) to remain compatible with how it works
today and with what the following command gives:
$ yadm config local.class

For the default template processor there is no explicit yadm.classes
variable. Instead a yadm.class condition will check against all
classes.

For the other processors, a new template variable YADM_CLASSES will be
set to all classes separated by newline. For jinja2 templates a class
can be checked with: {%- if "cls" in YADM_CLASSES.split("\n") %}

For esh templates the logic is a bit more complex, but it is possible
to do.

Fixes #185.
2021-12-27 21:14:09 +01:00
Tim Byrne
4843e1fa14
Add arch to template tests 2021-12-23 15:43:30 -06:00
Tim Byrne
216aed2f87
Adjust special handling of existing read-only output files
Instead of duplicating the permissions on the temp file, the permissions
are duplicated on the output file directly. If the output file exists as
read-only, it is made writeable first.

There are some environments which don't allow the mv to work if the file
itself is read-only.
2021-02-28 10:55:37 -06:00
Tim Byrne
6b068a141d
Remove superfluous f-strings 2020-12-21 17:06:14 -06:00
Erik Flodin
9bcf070dfe
Add support for including files using the default template processor
The syntax is '{% include "file" %}' where file is either an absolute path or a
path relative to the current template file's directory.

Variables in the included file will be replaced as for the main template. But
the included file can't include files itself.
2020-10-12 16:13:50 +02:00
Tim Byrne
102ba5d558
Preserve file mode of template (#193)
Any processed templates will inherit the file mode of the source
template.
2020-07-11 21:52:28 -05:00
Tim Byrne
f7485915ed
Update tests for gawk support 2019-12-04 22:18:55 -06:00
Tim Byrne
616baaeac6
Rename default template processor 2019-10-30 17:29:17 -05:00
Renamed from test/test_unit_template_builtin.py (Browse further)