Added default processing of templates without calculate header. fixed #26

master
Иванов Денис 3 years ago
parent 15e8a10f78
commit 4272faead6

@ -204,6 +204,8 @@ class TemplateWrapper:
self.template_type = template_type
self.template_text = template_text
self.contents_matching = True
# Флаг, указывающий, что нужно удалить файл из target_path перед
# применением шаблона.
self.remove_original = False
@ -253,10 +255,6 @@ class TemplateWrapper:
self.target_is_link = os.path.islink(target_file_path)
# Удаляем целевой файл, если append = 'replace'
if self.parameters.append and self.parameters.append == "replace":
self.remove_original = True
# Если установлен параметр mirror и есть параметр source,
# содержащий несуществующий путь -- удаляем целевой файл.
if self.parameters.source is True and self.parameters.mirror:
@ -291,6 +289,11 @@ class TemplateWrapper:
self._check_user_changes()
if self.target_type is not None and self.contents_matching:
# Удаляем целевой файл, если append = 'replace'
if self.parameters.append and self.parameters.append == "replace":
self.remove_original = True
def _check_type_conflicts(self) -> None:
'''Метод для проверки конфликтов типов.'''
if self.parameters.append == 'link':
@ -524,6 +527,7 @@ class TemplateWrapper:
self.contents_matching = self.target_package.check_contents_data(
self.target_path,
symlink=self.target_is_link)
print("matching:", self.contents_matching)
# Если по целевому пути файл не относящийся к какому-либо пакету и
# присутствует параметр autoupdate -- удаляем этот файл.

@ -1392,6 +1392,48 @@ class TestDirectoryProcessor:
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/copy.gif'))
def test_default_raw_and_append_replace(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_43')
directory_processor = DirectoryProcessor(
'install',
datavars_module=datavars,
package='test-category/test-package'
)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_60/file_0'))
assert not os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_60/._cfg0000_file_0'))
def test_default_raw_and_append_replace_contents_not_matching(self):
template_path = join_paths(CHROOT_PATH,
"templates_44/install/dir_61/file_0")
expected_new_text = ('#' + '-' * 79 + '\n' +
'# Modified by Calculate Utilities 4.0\n' +
'# Processed template files:\n' +
f'# { template_path }\n' +
'#' + '-' * 79 + '\n\nnew content')
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_44')
directory_processor = DirectoryProcessor(
'install',
datavars_module=datavars,
package='test-category/test-package'
)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH,'/etc/dir_61/file_0'))
with open(join_paths(CHROOT_PATH,
'/etc/dir_61/file_0'), 'r') as original_file:
original_text = original_file.read()
assert original_text == "old content\n"
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_61/._cfg0000_file_0'))
with open(join_paths(CHROOT_PATH,
'/etc/dir_61/._cfg0000_file_0'),
'r') as new_file:
new_text = new_file.read()
assert new_text == expected_new_text
def test_view_tree(self):
list_path = join_paths(CHROOT_PATH, '/etc')
show_tree(list_path)

@ -3000,9 +3000,6 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
def test_raw_format_error(self):
pass
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
shutil.rmtree(os.path.join(CHROOT_PATH, 'unprotected'))

@ -0,0 +1 @@
{% calculate action = "install", append = "skip", package = "test-category/test-package" %}

@ -0,0 +1 @@
{% calculate action = "install", append = "skip", package = "test-category/test-package" %}

@ -4,3 +4,5 @@ obj /etc/dir_17/file_0 c585be6f171462940b44af994a54040d 1593525253
dir /etc/dir_17/dir_0
obj /etc/dir_17/dir_0/file_0 c585be6f171462940b44af994a54040d 1593525253
obj /etc/file_12 ee090b452dbf92d697124eb424f5de5b 1592574626
dir /etc/dir_60
obj /etc/dir_60/file_0 c9a9459e4266ea35a612b90dc3653112 1593525253

Loading…
Cancel
Save