|
|
|
@ -253,13 +253,15 @@ 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:
|
|
|
|
|
self.remove_original = True
|
|
|
|
|
else:
|
|
|
|
|
if self.parameters.append and self.parameters.append == "replace":
|
|
|
|
|
self.remove_original = True
|
|
|
|
|
self.target_type = None
|
|
|
|
|
|
|
|
|
|
if self.format_class is not None and self.format_class.EXECUTABLE:
|
|
|
|
@ -979,23 +981,23 @@ class TemplateExecutor:
|
|
|
|
|
template_object.template_path,
|
|
|
|
|
ignore_comments=True)
|
|
|
|
|
|
|
|
|
|
if (not parsed_template and not template_object.parameters.source
|
|
|
|
|
and template_object.format_class.EXECUTABLE):
|
|
|
|
|
# Если шаблон пуст, параметром source не задан входной файл,
|
|
|
|
|
# а шаблон является исполнительным
|
|
|
|
|
if template_object.target_type is DIR:
|
|
|
|
|
self._remove_directory(template_object.target_path)
|
|
|
|
|
shutil.copytree(input_path,
|
|
|
|
|
template_object.target_path)
|
|
|
|
|
elif template_object.target_type is FILE:
|
|
|
|
|
self._remove_file(template_object.target_path)
|
|
|
|
|
shutil.copy(input_path,
|
|
|
|
|
template_object.template_path)
|
|
|
|
|
if (not parsed_template and template_object.parameters.source
|
|
|
|
|
and template_object.parameters.append == "replace"
|
|
|
|
|
and template_object.parameters.format == "raw"):
|
|
|
|
|
# Если шаблон пуст, параметром source задан входной файл,
|
|
|
|
|
# и при этом формат шаблона raw и append = 'replace'
|
|
|
|
|
# значит этот шаблон предназначен для копирования.
|
|
|
|
|
shutil.copy(input_path, output_path)
|
|
|
|
|
if chown:
|
|
|
|
|
self._chown_file(template_object.target_path, chown)
|
|
|
|
|
self._chown_file(template_object.output_path, chown)
|
|
|
|
|
|
|
|
|
|
if chmod:
|
|
|
|
|
self._chmod_file(template_object.target_path, chmod)
|
|
|
|
|
self._chmod_file(template_object.output_path, chmod)
|
|
|
|
|
|
|
|
|
|
input_file_md5 = None
|
|
|
|
|
with open(output_path, "rb") as output_file:
|
|
|
|
|
output_file_data = output_file.read()
|
|
|
|
|
output_file_md5 = hashlib.md5(output_file_data).hexdigest()
|
|
|
|
|
|
|
|
|
|
elif not template_object.format_class.EXECUTABLE:
|
|
|
|
|
# Действия для шаблонов не являющихся исполнительными.
|
|
|
|
@ -1039,8 +1041,8 @@ class TemplateExecutor:
|
|
|
|
|
|
|
|
|
|
# Удаляем форматный объект входного файла.
|
|
|
|
|
del(parsed_input)
|
|
|
|
|
output_text_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
input_text_md5 = hashlib.md5(input_text.encode()).hexdigest()
|
|
|
|
|
output_file_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
input_file_md5 = hashlib.md5(input_text.encode()).hexdigest()
|
|
|
|
|
|
|
|
|
|
for save_path in output_paths:
|
|
|
|
|
if not os.path.exists(os.path.dirname(save_path)):
|
|
|
|
@ -1089,7 +1091,7 @@ class TemplateExecutor:
|
|
|
|
|
template_object.update_contents_from_list(changed_files)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if input_text_md5 != output_text_md5:
|
|
|
|
|
if input_file_md5 != output_file_md5:
|
|
|
|
|
if template_object.target_type is None:
|
|
|
|
|
self.changed_files[
|
|
|
|
|
template_object.target_path] = 'N'
|
|
|
|
@ -1111,7 +1113,7 @@ class TemplateExecutor:
|
|
|
|
|
template_object.remove_from_contents()
|
|
|
|
|
else:
|
|
|
|
|
template_object.add_to_contents(
|
|
|
|
|
file_md5=output_text_md5)
|
|
|
|
|
file_md5=output_file_md5)
|
|
|
|
|
else:
|
|
|
|
|
if template_object.target_type is not None and not replace:
|
|
|
|
|
if (not input_path.startswith(self.cl_config_archive_path) or
|
|
|
|
@ -1141,11 +1143,11 @@ class TemplateExecutor:
|
|
|
|
|
|
|
|
|
|
# Удаляем форматный объект входного файла.
|
|
|
|
|
del(parsed_input)
|
|
|
|
|
output_text_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
output_file_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
|
|
|
|
|
if not self.calculate_config_file.compare_md5(
|
|
|
|
|
template_object.target_path,
|
|
|
|
|
output_text_md5):
|
|
|
|
|
output_file_md5):
|
|
|
|
|
if not os.path.exists(os.path.dirname(output_path)):
|
|
|
|
|
self._create_directory(
|
|
|
|
|
template_object,
|
|
|
|
@ -1164,11 +1166,11 @@ class TemplateExecutor:
|
|
|
|
|
# Обновляем CL.
|
|
|
|
|
self.calculate_config_file.set_files_md5(
|
|
|
|
|
template_object.target_path,
|
|
|
|
|
output_text_md5)
|
|
|
|
|
output_file_md5)
|
|
|
|
|
|
|
|
|
|
self.changed_files[template_object.target_path] = 'C'
|
|
|
|
|
# Обновляем CONTENTS.
|
|
|
|
|
template_object.add_to_contents(file_md5=output_text_md5)
|
|
|
|
|
template_object.add_to_contents(file_md5=output_file_md5)
|
|
|
|
|
else:
|
|
|
|
|
# Действия если CL совпало. Hичего не делаем.
|
|
|
|
|
pass
|
|
|
|
|