From 73ce266ed2d2cad44d201bacc722a5820b7784a2 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: Tue, 13 Oct 2020 18:07:32 +0300 Subject: [PATCH] Now build packages and uninstalled packages can be specified when running templates. fixed #5 --- calculate/templates/template_processor.py | 22 ++++++++++++++----- run_templates.py | 10 +++++++++ .../test_runner/install/.calculate_directory | 4 ++-- .../test_runner/remove/.calculate_directory | 4 ++-- .../test_runner/update/.calculate_directory | 4 ++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index 25e99c5..bab529c 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -1869,18 +1869,30 @@ class DirectoryProcessor: '''Метод для выполнения шаблонов относящихся к пакетам, указанным во всех встреченных значениях параметра merge.''' not_merged_packages = [] - founded_packages = iter(self.packages_file_trees.keys()) + self.for_package = None while self.packages_to_merge: - self.for_package = next(founded_packages, None) - if self.for_package is None: # Если список найденных пакетов пройден, но пакеты для # настройки еще есть -- заново проходимся по списку. + for package in self.packages_to_merge.difference( + self.packages_file_trees): + self.output.set_error( + ("Error: package '{0}' not found for" + " action{1} '{2}'.").format( + package, + 's' if len(self.action) > 1 else '', + ', '.join(self.action))) + self.packages_to_merge.remove(package) + if not self.packages_to_merge: + break founded_packages = iter(self.packages_file_trees.keys()) + + self.for_package = next(founded_packages, None) + if (self.for_package is None + or self.for_package not in self.packages_to_merge): continue - elif self.for_package not in self.packages_to_merge: - continue + self.template_engine.for_package = self.for_package if self.for_package not in self.packages_file_trees: diff --git a/run_templates.py b/run_templates.py index 199637d..859d415 100644 --- a/run_templates.py +++ b/run_templates.py @@ -17,6 +17,10 @@ def main(): help=("flag for switching template engine's mode from" " standard mode to the mode allowing changing of" "CONTENTS files.")) + parser.add_argument('-b', '--build', type=str, + help="atom name of a build package.") + parser.add_argument('-u', '--uninstall', type=str, + help="atom name of a uninstalling package.") args = parser.parse_args() datavars = Datavars() io_module = IOModule() @@ -25,6 +29,12 @@ def main(): else: package = args.package + group_packages = {} + if args.build is not None: + group_packages['build'] = args.build + if args.uninstall is not None: + group_packages['unistall'] = args.uninstall + action = list(flat_iterable(args.action)) template_processor = DirectoryProcessor(action, datavars_module=datavars, diff --git a/tests/templates/testfiles/test_runner/install/.calculate_directory b/tests/templates/testfiles/test_runner/install/.calculate_directory index 9ef11b6..767d616 100644 --- a/tests/templates/testfiles/test_runner/install/.calculate_directory +++ b/tests/templates/testfiles/test_runner/install/.calculate_directory @@ -1,2 +1,2 @@ -{% calculate append = 'skip', action = 'install' %} -{% calculate path = '/var/calculate/development/dir/test_dir' %} +{% calculate append = 'skip', action = 'install', +path = '/var/calculate/development/dir/test_dir' %} diff --git a/tests/templates/testfiles/test_runner/remove/.calculate_directory b/tests/templates/testfiles/test_runner/remove/.calculate_directory index a9e78a9..2f50ae3 100644 --- a/tests/templates/testfiles/test_runner/remove/.calculate_directory +++ b/tests/templates/testfiles/test_runner/remove/.calculate_directory @@ -1,2 +1,2 @@ -{% calculate append = 'skip', action = 'remove' %} -{% calculate path = '/var/calculate/development/dir' %} +{% calculate append = 'skip', action = 'remove', +path = '/var/calculate/development/dir' %} diff --git a/tests/templates/testfiles/test_runner/update/.calculate_directory b/tests/templates/testfiles/test_runner/update/.calculate_directory index 697e9a3..34eabba 100644 --- a/tests/templates/testfiles/test_runner/update/.calculate_directory +++ b/tests/templates/testfiles/test_runner/update/.calculate_directory @@ -1,2 +1,2 @@ -{% calculate append = 'skip', action = 'update' %} -{% calculate path = '/var/calculate/development/dir/test_dir' %} +{% calculate append = 'skip', action = 'update', +path = '/var/calculate/development/dir/test_dir' %}