|
|
|
from calculate.templates.template_engine import TemplateEngine, DIR, Variables
|
|
|
|
|
|
|
|
from calculate.templates.template_processor import TemplateAction
|
|
|
|
|
|
|
|
from calculate.utils.package import Version
|
|
|
|
|
|
|
|
|
|
|
|
main = Variables({'cl_template_path':
|
|
|
|
('tests/templates/testfiles/template_dir_1,'
|
|
|
|
'tests/templates/testfiles/template_dir_2'),
|
|
|
|
'cl_chroot_path': '/'})
|
|
|
|
|
|
|
|
values = Variables({'val_1': 11, 'val_2': 13, 'val_3': 12})
|
|
|
|
|
|
|
|
|
|
|
|
datavars = Variables({'main': main, 'values': values})
|
|
|
|
|
|
|
|
template_engine = TemplateEngine(
|
|
|
|
datavars_module=datavars,
|
|
|
|
appends_set=TemplateAction().available_appends)
|
|
|
|
|
|
|
|
template_engine.process_template_from_string(
|
|
|
|
"{% calculate env = 'values', name = 'dir_name', append = 'join' %}",
|
|
|
|
DIR)
|
|
|
|
|
|
|
|
template_engine.parameters.print_parameters_for_debug()
|
|
|
|
|
|
|
|
print('\nSECOND TEMPLATE\n')
|
|
|
|
template_engine.process_template_from_string(
|
|
|
|
'''{% calculate package = 'dev-lang/python-2.7', action = 'update' -%}
|
|
|
|
{% if pkg('category/name') < '3.6.9' -%}
|
|
|
|
The package exists.
|
|
|
|
{% else -%}
|
|
|
|
The package does not exist.
|
|
|
|
{% endif -%}
|
|
|
|
{% if Version('12.3.4-r1') < '12.2.5' %}
|
|
|
|
Version is correct.
|
|
|
|
{% endif -%}''',
|
|
|
|
DIR)
|
|
|
|
|
|
|
|
template_engine.parameters.print_parameters_for_debug()
|
|
|
|
print('\nTEMPLATE TEXT:\n{0}'.format(template_engine.template_text))
|