Changed files list are added for the template executor. fixed #9

master
Иванов Денис 4 years ago
parent c45c3068ac
commit f42ebc0075

@ -56,7 +56,8 @@ class ContentsFormat(Format):
command['path'],
command['lineno'],
source=source_package)
return self._save_changes()
self._save_changes()
return {}
def _add_command(self, target, glob_path, lineno, source=None):
# Если файл уже есть в пакете -- ничего не делаем.
@ -94,7 +95,6 @@ class ContentsFormat(Format):
paths_to_remove.append(file_path)
for file_path in paths_to_remove:
print(file_path)
target.remove_file(file_path)
def _move_command(self, target, glob_path, lineno, source=None):
@ -126,12 +126,9 @@ class ContentsFormat(Format):
target.sort_contents_dictionary()
def _save_changes(self):
changed_files = []
for atom_name, package in self._packages.items():
package.write_contents_file()
changed_files.append(package.contents_file_path)
self._packages = {}
return changed_files
def _get_package(self, atom_name: str, chroot_path: str) -> Package:
atom = self._atom_parser.parse_package_parameter(atom_name)

@ -71,10 +71,10 @@ class PatchFormat(Format):
line[13:].strip())
if path.exists(changed_file_path):
self.changed_files.update({changed_file_path:
'modify'})
'C'})
else:
self.changed_files.update({changed_file_path:
'remove'})
'D'})
return patch_run.read()
else:
return ''

@ -147,7 +147,6 @@ class ParametersProcessor:
self._groups.update({group: packages})
except Exception:
pass
pprint(self._groups)
self._inspect_formats_package()
@ -583,6 +582,10 @@ class ParametersProcessor:
else:
groups = self._parameters_container.group
print(f'PACKAGE: {parameter_value}')
print(f'PARSED: {package_atom}')
print(f'GROUPS: {groups}')
print(f'UNINSTALL: {self._groups.get("uninstall", None)}')
for group in groups:
if group == 'install':
try:
@ -597,8 +600,10 @@ class ParametersProcessor:
self._parameters_container.remove_parameter('package')
return
print('check failed')
raise ConditionFailed(f"package '{parameter_value}'"
" does not template condition", self.lineno)
" does not match the template condition",
self.lineno)
def _check_package_group(self, package: dict, group_packages: list):
'''Метод для проверки соответствия описания пакета, заданного словарем,
@ -608,15 +613,18 @@ class ParametersProcessor:
if package[parameter] is not None:
if (group_package[parameter] is None
or group_package[parameter] != package[parameter]):
print(f'{group_package[parameter]} !='
f' {package[parameter]}')
break
else:
if package['use_flags'] is not None:
if group_package['use_flags'] is None:
continue
if package['use_flags'] is not None:
if group_package['use_flags'] is None:
continue
else:
for use_flag in package['use_flags']:
if use_flag not in group_package['use_flags']:
continue
return True
else:
for use_flag in package['use_flags']:
if use_flag not in group_package['use_flags']:
continue
return True
return False
# Методы для проверки того, являются ли параметры наследуемыми.

@ -5,7 +5,7 @@ from ..utils.package import PackageAtomParser, Package, PackageNotFound,\
PackageAtomName, Version, NonePackage
from ..utils.files import join_paths, write_file, read_file_lines, FilesError,\
check_directory_link, read_link, Process,\
get_target_from_link
get_target_from_link, get_directory_contents
from .template_engine import TemplateEngine, Variables, ConditionFailed,\
ParametersProcessor, DIR, FILE,\
ParametersContainer
@ -597,7 +597,7 @@ class TemplateWrapper:
return
for file_path, mode in changed_list.items():
if mode == "modify":
if mode == "M":
if os.path.islink(file_path):
self.target_package.add_sym(file_path)
@ -606,7 +606,7 @@ class TemplateWrapper:
elif os.path.isfile(file_path):
self.target_package.add_obj(file_path)
elif mode == "remove":
elif mode == "D":
if os.path.islink(file_path) or os.path.isfile(file_path):
self.target_package.remove_obj(file_path)
@ -665,7 +665,10 @@ class TemplateExecutor:
self.dbpkg = dbpkg
# Список целевых путей измененных файлов. Нужен для корректиного
# Словарь с измененными файлами и статусами их изменений.
self.changed_files = {}
# Список целевых путей измененных файлов. Нужен для корректного
# формирования calculate-заголовка.
self.processed_targets = []
@ -796,6 +799,12 @@ class TemplateExecutor:
if template_object.target_type is None:
self._create_directory(template_object)
# Корректируем список измененных файлов.
if template_object.target_path in self.changed_files:
self.changed_files[template_object.target_path] = 'M'
else:
self.changed_files[template_object.target_path] = 'N'
if self.dbpkg:
template_object.add_to_contents()
@ -804,8 +813,20 @@ class TemplateExecutor:
'''Метод описывающий действия для append = "remove", если шаблон --
директория. Удаляет директорию со всем содержимым, если она есть.'''
if template_object.target_type is not None:
changed = [template_object.target_path]
changed.extend(get_directory_contents(template_object.target_path))
self._remove_directory(template_object.target_path)
# Добавляем все содержимое директории в список измененных файлов.
for file_path in changed:
if file_path in self.changed_files:
if self.changed_files[file_path] == 'N':
self.changed_files.pop(file_path)
else:
self.changed_files[file_path] = 'D'
else:
self.changed_files[file_path] = 'D'
if self.dbpkg:
template_object.remove_from_contents()
@ -818,8 +839,19 @@ class TemplateExecutor:
'''Метод описывающий действия для append = "clear", если шаблон --
директория. Удаляет все содержимое директории, если она есть.'''
if template_object.target_type is not None:
dir_contents = get_directory_contents(template_object.target_path)
self._clear_directory(template_object.target_path)
# Добавляем все содержимое директории в список изменных файлов.
for file_path in dir_contents:
if file_path in self.changed_files:
if self.changed_files[file_path] == 'N':
self.changed_files.pop(file_path)
else:
self.changed_files[file_path] = 'D'
else:
self.changed_files[file_path] = 'D'
# Меняем права и владельца очищенной директории, если это
# необходимо.
if template_object.parameters.chmod:
@ -839,6 +871,12 @@ class TemplateExecutor:
self._link_directory(template_object.parameters.source,
template_object.target_path)
# Корректируем список измененных файлов.
if template_object.target_path in self.changed_files:
self.changed_files[template_object.target_path] = 'M'
else:
self.changed_files[template_object.target_path] = 'N'
# Меняем права и владельца файла, на который указывает ссылка.
if template_object.parameters.chmod:
self._chmod_directory(template_object.parameters.source,
@ -859,8 +897,26 @@ class TemplateExecutor:
self._create_directory(template_object)
if self.dbpkg:
template_object.add_to_contents()
# Корректируем список измененных файлов.
if template_object.target_path in self.changed_files:
self.changed_files[template_object.target_path] = 'M'
else:
self.changed_files[template_object.target_path] = 'N'
else:
dir_contents = get_directory_contents(template_object.target_path)
self._clear_directory(template_object.target_path)
# Добавляем все содержимое директории в список измененных файлов.
for file_path in dir_contents:
if file_path in self.changed_files:
if self.changed_files[file_path] == 'N':
self.changed_files.pop(file_path)
else:
self.changed_files[file_path] = 'D'
else:
self.changed_files[file_path] = 'D'
if self.dbpkg:
template_object.clear_dir_contents()
@ -912,8 +968,7 @@ class TemplateExecutor:
with open(input_path, 'r') as input_file:
input_text = input_file.read()
else:
# В противном случае используем пустой файл. (!)
# TODO КАВО ЧЕГО
# В противном случае используем пустой файл. TODO Подумать.
input_text = ''
else:
input_text = ''
@ -965,6 +1020,11 @@ class TemplateExecutor:
self.calculate_config_file.remove_file(
template_object.target_path)
if template_object.target_type is None:
self.changed_files[template_object.target_path] = 'N'
else:
self.changed_files[template_object.target_path] = 'M'
# Обновляем CONTENTS.
if template_object.protected:
if template_object.parameters.unbound:
@ -981,6 +1041,23 @@ class TemplateExecutor:
# Если исполняемый формат выдал список измененных файлов для
# изменения CONTENTS и при этом задан пакет -- обновляем
# CONTENTS.
for file_path, status in changed_files.items():
if status == 'M':
if file_path in self.changed_files:
if self.changed_files[file_path] == 'D':
self.changed_files[file_path] == 'N'
else:
self.changed_files[file_path] = 'M'
elif status == 'D':
if file_path in self.changed_files:
if self.changed_files[file_path] == 'M':
self.changed_files[file_path] == 'D'
if self.changed_files[file_path] == 'N':
self.changed_files.pop(file_path)
else:
self.changed_files[file_path] = 'D'
if (self.dbpkg and changed_files and
template_object.target_package and
template_object.format_class.FORMAT != 'contents'):
@ -1038,6 +1115,8 @@ class TemplateExecutor:
self.calculate_config_file.set_files_md5(
template_object.target_path,
output_text_md5)
self.changed_files[template_object.target_path] = 'C'
# Обновляем CONTENTS.
template_object.add_to_contents(file_md5=output_text_md5)
else:
@ -1072,6 +1151,13 @@ class TemplateExecutor:
if template_object.target_type is not None:
self._remove_file(template_object.target_path)
if template_object.target_path in self.changed_files:
if self.changed_files[template_object.target_path] == 'N':
self.changed_files.pop(template_object.target_path)
elif self.changed_files[template_object.target_path] == 'M':
self.changed_files[template_object.target_path] = 'D'
else:
self.changed_files[template_object.target_path] = 'D'
if self.dbpkg:
template_object.remove_from_contents()
@ -1090,6 +1176,10 @@ class TemplateExecutor:
self._chmod_file(template_object.target_path,
template_object.parameters.chmod)
# Корректируем список измененных файлов.
if template_object.target_path not in self.changed_files:
self.changed_files[template_object.target_path] = 'M'
if self.dbpkg:
template_object.add_to_contents()
@ -1108,6 +1198,10 @@ class TemplateExecutor:
self._chown_file(template_object.parameters.source,
template_object.parameters.chown)
# Корректируем список измененных файлов.
if template_object.target_path not in self.changed_files:
self.changed_files[template_object.target_path] = 'N'
if self.dbpkg:
template_object.add_to_contents()

@ -126,8 +126,7 @@ class Process:
self._opened = True
except Exception as error:
print('error:', error)
raise FilesError('Can not open process.')
raise FilesError(f'Can not open process. Reason: {error}')
def close(self):
'''Метод для закрытия процесса.'''
@ -408,6 +407,24 @@ def list_directory(directory_path, fullpath=False, only_dir=False):
return []
def get_directory_contents(path: str):
'''Функция для получения списка путей ко всем файлам и директориям,
содержащимся в указанной директории.'''
output = []
for entry in os.scandir(path):
try:
if entry.is_symlink():
output.append(entry.path)
elif entry.is_dir():
output.append(entry.path)
output.extend(get_directory_contents(entry.path))
elif entry.is_file():
output.append(entry.path)
except Exception:
continue
return output
def make_directory(directory_path, force=False):
try:
parent = os.path.split(path.normpath(directory_path))[0]

@ -117,9 +117,7 @@ class Version:
version_value['literal'] = result_dict['literal'] or ''
# Парсим всю совокупность имеющихся суффиксов.
print('result dict:', result_dict)
suffixes = result_dict['suffix']
print('suffixes:', suffixes)
suffix_list = []
if suffixes is not None:
suffixes = suffixes.strip('_')

@ -114,6 +114,9 @@ class TestDirectoryProcessor:
datavars_module=datavars)
directory_processor.process_template_directories()
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_a_single_template_file__the_directory_processor_creates_new_file_and_adds_one_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_1')
@ -144,6 +147,9 @@ class TestDirectoryProcessor:
output_file_text = output_file.read()
assert output_file_text == output_text
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, 'etc/file_0'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_a_single_other_directory_with_same_a_file__the_directory_processor_creates_new_directory(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_2')
@ -153,6 +159,9 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_1'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, '/etc/dir_1'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_a_single_other_directory_without_calculate_directory_file__the_directory_processor_creates_new_directory(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_4')
@ -166,6 +175,9 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_3'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, '/etc/dir_3'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_with_a_single_directory_with_a_single_template_file__the_directory_processor_creates_new_directory_and_file_and_adds_one_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_3')
@ -199,6 +211,11 @@ class TestDirectoryProcessor:
output_file_text = output_file.read()
assert output_file_text == output_text
assert directory_processor.template_executor.\
changed_files == {
join_paths(CHROOT_PATH, '/etc/dir_2'): 'N',
join_paths(CHROOT_PATH, '/etc/dir_2/file_0'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_with_two_directories_with_a_template_files__the_directory_processor_creates_all_new_directories_and_files_and_adds_them_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_5')
@ -256,6 +273,13 @@ class TestDirectoryProcessor:
output_file_text = output_file.read()
assert output_file_text == output_text_2
assert directory_processor.template_executor.\
changed_files == {
join_paths(CHROOT_PATH, '/etc/dir_4'): 'N',
join_paths(CHROOT_PATH, '/etc/dir_4/file_0'): 'N',
join_paths(CHROOT_PATH, '/etc/dir_5/dir_6'): 'N',
join_paths(CHROOT_PATH, '/etc/dir_5/dir_6/file_0'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_a_single_template_file_and_there_is_a_file_without_user_changes_on_its_target_path__the_directory_processor_joins_a_template_file_with_a_target_file_and_updates_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_6')
@ -291,6 +315,9 @@ class TestDirectoryProcessor:
hashlib.md5(
output_text.encode()).hexdigest())
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, '/etc/file_1'): 'M'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_with_a_single_directory_with_a_single_template_file_and_there_is_a_file_without_user_changes_on_its_target_path__the_directory_processor_joins_a_template_file_with_a_target_file_and_updates_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_7')
@ -327,6 +354,9 @@ class TestDirectoryProcessor:
assert test_package.is_md5_equal('/etc/dir_6/file_0',
hashlib.md5(
output_text.encode()).hexdigest())
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_6/file_0'): 'M'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_and_a_single_template_file_and_there_is_a_file_with_user_changes_on_its_target_path__the_directory_processor_joins_a_template_file_with_a_target_file_and_updates_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
@ -365,6 +395,10 @@ class TestDirectoryProcessor:
hashlib.md5(
output_text.encode()).hexdigest())
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_2'): 'C'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_one_template_directory_and_a_single_template_file_with_a_target_path_to_a_file_removed_by_user_in_the_last_one__the_directory_processor_creates_a_new_empty_cfg_file__joins_template_with_it_and_updates_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_9')
@ -401,6 +435,10 @@ class TestDirectoryProcessor:
hashlib.md5(
output_text.encode()).hexdigest())
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_3'): 'C'}
def test_if_templates_are_hierarchy_of_a_multiple_template_files_with_a_removed_or_changed_by_user_targets_and_there_is_the_autoupdate_parameter_in_the_root_calculate_directory_template__the_directory_processor_uses_autoupdate_parameter_for_all_templates_and_joins_all_templates_as_if_target_files_have_no_user_changes(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_10')
@ -484,6 +522,14 @@ class TestDirectoryProcessor:
hashlib.md5(
output_text_3.encode()).hexdigest())
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_4'): 'M',
join_paths(CHROOT_PATH,
'/etc/file_5'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_7/file_0'): 'M'}
def test_if_the_template_directory_have_no_the_action_parameter_value_and_append_parameter_is_not_skip__the_directory_processor_skips_this_template_branch_and_sets_warning(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_11')
@ -499,6 +545,9 @@ class TestDirectoryProcessor:
assert not os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_8'))
assert io_module.messages[-1] == ('warning', warning_message)
assert directory_processor.template_executor.\
changed_files == {}
def test_if_the_template_has_two_root_directories_with_different_action_values_and_directory_processor_intialized_for_the_one_of_this_actions__the_directory_processor_skips_one_this_template_s_roots_and_processed_a_template_s_root_with_the_same_action_parameter_value(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_12')
@ -518,6 +567,10 @@ class TestDirectoryProcessor:
assert not os.path.exists(join_paths(CHROOT_PATH, '/etc/file_7'))
assert ('warning', warning_message) in io_module.messages
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_6'): 'N'}
def test_if_some_template_directories_have_no_the_action_parameter_value_but_the_append_parameter_s_value_is_skip__the_directory_processor_does_not_stop_the_directories_processing_and_sends_no_warnings(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_13')
@ -526,6 +579,10 @@ class TestDirectoryProcessor:
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_8'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_8'): 'N'}
def test_if_template_s_directory_contains_two_directories_with_single_template_files_that_belongs_to_a_different_packages_and_target_files_does_not_exist__the_directory_processor_creates_two_files_and_adds_them_to_a_different_packages(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_14')
@ -544,6 +601,16 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_10/file_0'))
assert '/etc/dir_10/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_9/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_10/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_9'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_10'): 'N'}
def test_if_template_s_directory_contains_one_directory_with_a_template_file_without_a_package_value_target_file_does_not_exist_and_template_executor_is_not_able_to_detect_package_using_target_path__the_directory_processor_skips_this_template_and_sets_error_in_the_output(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_15')
@ -565,6 +632,9 @@ class TestDirectoryProcessor:
'/etc/dir_11/file_0'))
assert ('error', error_message) in io_module.messages
assert directory_processor.template_executor.\
changed_files == {}
def test_if_template_s_directory_contains_one_directory_with_a_template_file_without_a_package_value_target_file_exists_and_template_executor_is_able_to_detect_package_using_target_path__the_directory_processor_joins_template_to_a_target_file_and_updates_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_16')
@ -580,6 +650,10 @@ class TestDirectoryProcessor:
'/etc/dir_12/file_0'))
assert '/etc/dir_12/file_0' in new_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_12/file_0'): 'M'}
def test_if_template_s_directory_contains_two_directories_with_single_template_files_that_belongs_to_a_different_packages_and_target_files_does_not_exist_and_directory_processor_is_used_for_a_package__the_directory_processor_creates_one_file_using_template_with_actual_package_parameter_and_adds_it_to_a_package_and_add_to_the_packages_file_trees_a_directory_with_an_other_template(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_17')
@ -600,6 +674,12 @@ class TestDirectoryProcessor:
'/etc/dir_14/file_0'))
assert '/etc/dir_14/file_0' not in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_13'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_13/file_0'): 'N'}
def test_if_template_s_directory_contains_two_directories_with_single_template_files_that_belongs_to_a_different_packages_and_target_files_does_not_exist_and_one_of_a_template_files_has_the_merge_parameter_with_other_package_and_directory_processor_is_used_for_a_package__the_directory_processor_creates_one_file_using_template_with_actual_package_parameter_and_then_uses_the_packages_file_tree_to_merge_an_other_package(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_18')
@ -620,6 +700,16 @@ class TestDirectoryProcessor:
'/etc/dir_16/file_0'))
assert '/etc/dir_16/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_15'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_15/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_16'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_16/file_0'): 'N'}
def test_if_template_s_directory_contains_a_template_directory_which_target_is_a_link_to_an_other_directory_and_force_parameter_is_not_set__the_directory_processor_changes_a_template_target_path_to_a_link_source_path_and_joins_all_templates_from_the_template_directory(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_19')
@ -639,6 +729,14 @@ class TestDirectoryProcessor:
'/etc/dir_18/dir_0/file_0'))
assert '/etc/dir_18/dir_0/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_18/dir_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_18/dir_0/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_18/file_0'): 'D'}
def test_if_template_s_directory_contains_a_template_directory_which_target_is_a_link_to_an_other_directory_and_force_parameter_is_set__the_directory_processor_removes_link_on_a_target_path_and_joins_all_templates_from_a_template_directory(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_20')
@ -662,6 +760,14 @@ class TestDirectoryProcessor:
'/etc/dir_19/dir_0/file_0'))
assert '/etc/dir_19/dir_0/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_19'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_19/dir_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_19/dir_0/file_0'): 'N'}
def test_if_template_s_directory_contains_some_directories_with_single_template_files_that_belongs_to_a_different_packages_and_target_files_does_not_exist_and_one_of_a_template_file_has_the_merge_parameter_with_other_packages_and_directory_processor_is_used_for_a_package__the_directory_processor_creates_one_file_using_template_with_actual_package_parameter_and_then_uses_the_packages_file_trees_to_merge_other_packages(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_21')
@ -688,6 +794,22 @@ class TestDirectoryProcessor:
'/etc/dir_23/file_0'))
assert '/etc/dir_23/file_0' in new_package
assert directory_processor.template_executor.\
changed_files == {
join_paths(CHROOT_PATH,
'/etc/dir_21'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_21/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_22'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_22/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_23'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_23/file_0'): 'N'
}
def test_if_template_s_directory_contains_some_directories_with_single_template_files_that_belong_to_a_different_packages_and_target_files_does_not_exist_and_some_of_a_template_files_have_the_merge_parameters_with_other_packages_and_directory_processor_is_used_for_a_package__the_directory_processor_creates_one_file_using_template_with_actual_package_parameter_and_then_uses_the_packages_file_trees_to_merge_other_packages(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_22')
@ -715,11 +837,21 @@ class TestDirectoryProcessor:
'/etc/dir_26/file_0'))
assert '/etc/dir_26/file_0' in new_package
print('DIRECTORY TREE:')
for key in directory_processor.packages_file_trees.keys():
print("{} -> {}".format(
key,
directory_processor.packages_file_trees[key]))
assert directory_processor.template_executor.\
changed_files == {
join_paths(CHROOT_PATH,
'/etc/dir_24'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_24/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_25'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_25/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_26'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_26/file_0'): 'N'
}
def test_if_template_s_directory_contains_some_directories_with_single_template_files_and_file_that_belong_to_a_different_packages_and_target_files_does_not_exist_and_some_of_a_template_files_have_the_merge_parameters_with_other_packages_and_directory_processor_is_used_for_a_package__the_directory_processor_creates_one_file_using_template_with_actual_package_parameter_and_then_uses_the_packages_file_trees_to_merge_other_packages(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
@ -751,6 +883,20 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_9'))
assert '/etc/file_9' in test_package
assert directory_processor.template_executor.\
changed_files == {
join_paths(CHROOT_PATH,
'/etc/dir_27'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_27/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_28'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_28/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/file_9'): 'N'
}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_a_single_template_file_with_condition_and_condition_is_true__the_directory_processor_creates_new_file_and_adds_one_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_24')
@ -762,6 +908,10 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_10'))
assert '/etc/file_10' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/file_10'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_a_single_template_file_with_condition_and_condition_is_false__the_directory_processor_does_nothing(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_25')
@ -773,6 +923,9 @@ class TestDirectoryProcessor:
assert not os.path.exists(join_paths(CHROOT_PATH, '/etc/file_11'))
assert '/etc/file_11' not in test_package
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_with_a_single_directory_that_contains_calculate_directory_file_with_condition_that_is_true_and_a_single_template_file__the_directory_processor_creates_new_directory_and_file_and_adds_one_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_26')
@ -788,6 +941,12 @@ class TestDirectoryProcessor:
assert '/etc/dir_29' in test_package
assert '/etc/dir_29/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_29'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_29/file_0'): 'N'}
def test_if_templates_consist_only_one_directory_with_a_calculate_directory_file_with_a_single_directory_that_contains_calculate_directory_file_with_condition_that_is_false_and_a_single_template_file__the_directory_processor_creates_new_directory_and_file_and_adds_one_in_the_CONTENTS_file(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_27')
@ -805,6 +964,9 @@ class TestDirectoryProcessor:
assert '/etc/dir_30' not in test_package
assert '/etc/dir_30/file_0' not in test_package
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_contain_a_template_file_with_a_target_path_to_a_file_with_some_cfg_files_and_changes_in_the_template_is_the_same_as_in_the_last_cfg_file__the_directory_processor_does_nothing(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_28')
@ -826,6 +988,9 @@ class TestDirectoryProcessor:
assert '/etc/file_12'\
in directory_processor.template_executor.calculate_config_file
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_contain_a_template_file_with_the_run_parameter_and_a_correct_script___the_directory_processor_runs_the_script_using_the_interpreter_from_the_run_parameter(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_29')
@ -836,6 +1001,11 @@ class TestDirectoryProcessor:
# Скрипт создает файл.
assert os.path.exists(join_paths(CHROOT_PATH, 'etc/file_13'))
# Из скрипта не получить список файлов измененных или созданных
# шаблоном.
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_contain_a_directory_with_a_calculate_directory_file_with_the_run_parameter_and_a_correct_script___the_directory_processor_runs_the_script_using_the_interpreter_from_the_run_parameter(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_30')
@ -846,6 +1016,11 @@ class TestDirectoryProcessor:
# Скрипт создает файл.
assert os.path.exists(join_paths(CHROOT_PATH, 'etc/file_14'))
# Из скрипта не получить список файлов измененных или созданных
# шаблоном.
assert directory_processor.template_executor.\
changed_files == {}
def test_if_templates_contain_some_files_with_the_exec_parameter_and_a_correct_scripts___the_directory_processor_saves_all_the_scripts_in_the_special_execute_directory_and_runs_all_the_files_after_all_templates_are_joined_and_packages_from_the_merge_parameter_is_processed(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_31')
@ -867,6 +1042,14 @@ class TestDirectoryProcessor:
file_text = file_16.read()
assert file_text == 'There is a value = 128'
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_31'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_31/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/file_17'): 'N'}
def test_multiple_actions(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_32')
@ -887,6 +1070,16 @@ class TestDirectoryProcessor:
'etc/dir_33/file_0'))
assert '/etc/dir_33/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_32'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_32/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_33'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_33/file_0'): 'N'}
def test_None_package(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_33')
@ -901,6 +1094,12 @@ class TestDirectoryProcessor:
'etc/dir_35/file_0'))
assert '/etc/dir_35/file_0' in test_package
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_35'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_35/file_0'): 'N'}
def test_handlers_basic(self):
try:
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
@ -979,6 +1178,20 @@ class TestDirectoryProcessor:
'etc/dir_47'))
assert os.path.exists(join_paths(CHROOT_PATH,
'etc/dir_48'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'/etc/dir_37'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_37/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_39/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_41/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_43/file_0'): 'N',
join_paths(CHROOT_PATH,
'/etc/dir_48/file_0'): 'N'}
except KeyboardInterrupt:
assert False
@ -1007,6 +1220,9 @@ class TestDirectoryProcessor:
assert real_output == expected_output
assert directory_processor.template_executor.\
changed_files == {}
def test_group_parameter_without_merge(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_37')
@ -1019,10 +1235,6 @@ class TestDirectoryProcessor:
)
assert 'build' in datavars.main.cl.groups
assert 'uninstall' in datavars.main.cl.groups
print('ATOMS:')
pprint(datavars.main.cl.groups.build)
pprint(datavars.main.cl.groups.uninstall)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_51'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_51/file_0'))
@ -1036,6 +1248,12 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_54'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_54/file_0'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'etc/dir_51'): 'N',
join_paths(CHROOT_PATH,
'etc/dir_51/file_0'): 'N'}
def test_group_parameter_with_merge_parameter(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_38')
@ -1056,6 +1274,16 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_56'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_56/file_0'))
assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH,
'etc/dir_55'): 'N',
join_paths(CHROOT_PATH,
'etc/dir_55/file_0'): 'N',
join_paths(CHROOT_PATH,
'etc/dir_56'): 'N',
join_paths(CHROOT_PATH,
'etc/dir_56/file_0'): 'N'}
def test_solving_collisions_for_the_same_packages_from_different_slots(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_39')

@ -688,8 +688,10 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
print('PROTECTED SET')
print(template_wrapper._protected_set)
print('UNPROTECTED SET')
print(template_wrapper._unprotected_set)
assert not template_wrapper.protected
# Тестируем проверку хэш-сумм и флаг получаемый в результате нее.
@ -1076,11 +1078,11 @@ class TestTemplateWrapper:
'append': 'join',
'format': 'patch'})
changed_files = {join_paths(CHROOT_PATH,
'/etc/dir/subdir/config.json'): 'remove',
'/etc/dir/subdir/config.json'): 'D',
join_paths(CHROOT_PATH,
'/etc/file'): 'modify',
'/etc/file'): 'M',
join_paths(CHROOT_PATH,
'/etc/dir/subdir/file'): 'modify'}
'/etc/dir/subdir/file'): 'M'}
try:
template_wrapper = TemplateWrapper(
join_paths(CHROOT_PATH,

@ -1,5 +1,5 @@
{% calculate run = '/usr/bin/python' %}
import os
os.mkdir('./dir_54')
with open('./dir_54/file_0', 'w') as output_file:
with open('./dir_54/file_1', 'w') as output_file:
output_file.write('Made for uninstalled-package')

Loading…
Cancel
Save