You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

from calculate.templates.template_engine import TemplateEngine, DIR, Variables
from calculate.templates.template_processor import TemplateAction
from calculate.utils.package import Version
from calculate.utils.files import read_file_lines
from pprint import pprint
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})
print('\nREAD LINES EXPERIMENT\n')
config_dictionary = {}
generator = read_file_lines('/var/lib/portage/config')
for fileline in generator:
filename, md5_sum = fileline.strip().split(' ')
config_dictionary.update({filename: md5_sum})
pprint(config_dictionary)
print('\nFIRST TEMPLATE\n')
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))