From 62db17009ab53df368329f49eb3fd7a1af6da39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Wed, 13 Jan 2021 15:15:55 +0300 Subject: [PATCH] Now handler templates have default values for append and format parameters. fixed #57 --- calculate/templates/template_processor.py | 9 +++++++++ tests/templates/format/test_raw.py | 1 - .../templates_35/install/handler_1 | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index 3864071..3bd5ee1 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -2282,6 +2282,15 @@ class DirectoryProcessor: handler_name, parameters) + if not parameters.run and not parameters.exec: + if not parameters.format: + parameters.set_parameter({'format': 'raw'}) + if not parameters.append: + if parameters.format == "raw": + parameters.set_parameter({'append': 'replace'}) + else: + parameters.set_parameter({'append': 'join'}) + # Выполняем действия, указанные в обработчике. self._execute_template(target_file_path, parameters, FILE, handler_path, diff --git a/tests/templates/format/test_raw.py b/tests/templates/format/test_raw.py index c24b9a3..fd11fd8 100644 --- a/tests/templates/format/test_raw.py +++ b/tests/templates/format/test_raw.py @@ -1,5 +1,4 @@ import pytest -from collections import OrderedDict from calculate.templates.format.raw_format import RawFormat from calculate.templates.template_engine import ParametersContainer diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_35/install/handler_1 b/tests/templates/testfiles/test_dir_processor_root/templates_35/install/handler_1 index bc2259c..58f9dcf 100644 --- a/tests/templates/testfiles/test_dir_processor_root/templates_35/install/handler_1 +++ b/tests/templates/testfiles/test_dir_processor_root/templates_35/install/handler_1 @@ -1,5 +1,5 @@ -{% calculate handler = 'handler_1', append = 'join', path = 'dir_39/', -name = 'file_0', format = 'samba', notify = 'handler_2' %} +{% calculate handler = 'handler_1', path = 'dir_39/', +name = 'file_0', notify = 'handler_2' %} [section 1] parameter 1 = {{ ns.variable_1 }} parameter 2 = {{ ns.variable_2 }}