From 74e9ef8b9fa34e54df0c6ed4830075600c2f2ad2 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: Fri, 11 Dec 2020 15:34:48 +0300 Subject: [PATCH] Warning messages while processing packages from 'merge' parameters was fixed #63 --- calculate/templates/template_processor.py | 6 +++--- calculate/utils/package.py | 5 +++++ tests/templates/test_directory_processor.py | 17 +++++++++++++++++ .../templates_48/install/.calculate_directory | 1 + .../install/dir_66/.calculate_directory | 2 ++ .../templates_48/install/dir_66/file_0 | 2 ++ 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/templates/testfiles/test_dir_processor_root/templates_48/install/.calculate_directory create mode 100644 tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory create mode 100644 tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/file_0 diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index 2118674..2918fc5 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -2231,10 +2231,10 @@ class DirectoryProcessor: # настройки еще есть -- заново проходимся по списку. for package in self.packages_to_merge.difference( self.packages_file_trees): - self.output.set_error( - ("Error: package '{0}' not found for" + self.output.set_warning( + ("Warning: package '{0}' not found for" " action{1} '{2}'.").format( - package, + str(package), 's' if len(self.action) > 1 else '', ', '.join(self.action))) self.packages_to_merge.remove(package) diff --git a/calculate/utils/package.py b/calculate/utils/package.py index ceaa2e1..41aa9cf 100644 --- a/calculate/utils/package.py +++ b/calculate/utils/package.py @@ -447,6 +447,11 @@ class PackageAtomName: def __hash__(self) -> bool: return hash(self._package_directory) + def __str__(self) -> str: + category_path, name = os.path.split(self._package_directory) + category = os.path.basename(category_path) + return f'{category}/{name}' + NonePackage = PackageAtomName({'pkg_path': None, 'version': None}) diff --git a/tests/templates/test_directory_processor.py b/tests/templates/test_directory_processor.py index b5262e3..a4c5a44 100644 --- a/tests/templates/test_directory_processor.py +++ b/tests/templates/test_directory_processor.py @@ -1474,6 +1474,23 @@ class TestDirectoryProcessor: directory_processor.process_template_directories() assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_65/file_0')) + def test_warning_while_merge(self): + datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, + 'templates_48') + io = IOModule(save_messages=True) + directory_processor = DirectoryProcessor( + 'install', + datavars_module=datavars, + package='test-category/test-package', + output_module=io + ) + directory_processor.process_template_directories() + assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_66/file_0')) + assert io.messages[-2] ==\ + ("warning", + "Warning: package 'test-category/new-package-0.1.1'" + " not found for action 'install'.") + def test_view_tree(self): list_path = join_paths(CHROOT_PATH, '/etc') show_tree(list_path) diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_48/install/.calculate_directory b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/.calculate_directory new file mode 100644 index 0000000..cb8c8fa --- /dev/null +++ b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/.calculate_directory @@ -0,0 +1 @@ +{% calculate action = "install", append = "skip" %} diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory new file mode 100644 index 0000000..e6945f5 --- /dev/null +++ b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/.calculate_directory @@ -0,0 +1,2 @@ +{% calculate package = "test-category/test-package", +merge = "test-category/new/package" %} diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/file_0 b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/file_0 new file mode 100644 index 0000000..5b18600 --- /dev/null +++ b/tests/templates/testfiles/test_dir_processor_root/templates_48/install/dir_66/file_0 @@ -0,0 +1,2 @@ +{% calculate append = 'join', format = 'raw' %} +Something I can never have