Added backgrounds format. fixed #75

master
Иванов Денис 3 years ago
parent d6c944890c
commit e59a4511d6

@ -0,0 +1,318 @@
# vim: fileencoding=utf-8
#
from ..template_engine import ParametersContainer, Variables
from ...variables.datavars import NamespaceNode, VariableNotFoundError
from ...variables.loader import Datavars
from ...utils.images import ImageMagick
from .base_format import Format, FormatError
from typing import Union, List, Tuple, NoReturn
import hashlib
import re
import os
class BackgroundsFormat(Format):
FORMAT = 'backgrounds'
EXECUTABLE = True
FORMAT_PARAMETERS = {'convert', 'stretch'}
def __init__(self, template_text: str,
template_path: str,
parameters: ParametersContainer,
datavars: Union[Datavars, NamespaceNode, Variables],
chroot_path: str = "/"):
self._lines: List[str] = [line for line
in template_text.strip().split('\n') if line]
self._datavars: Union[Datavars, NamespaceNode, Variables] = datavars
if parameters.source:
self._source = parameters.source
else:
raise FormatError("source parameter is not set for template with"
"with 'backgrounds' format.")
self._mirror: bool = parameters.mirror
self._stretch: bool = parameters.stretch
self._convert: Union[bool, str] = parameters.convert
self._empty_name: bool = (parameters.name == '')
# Измененные файлы.
self.changed_files: dict = dict()
# Список предупреждений.
self._warnings: list = []
# Флаг для тестов.
self._fake_chroot: bool = False
try:
self._fake_chroot = datavars.main.fake_chroot
except Exception:
pass
def execute_format(self, target_path: str, chroot_path: str = '/') -> dict:
'''Метод для запуска работы формата.'''
if not self._check_source(self._source, target_path, self._mirror):
return self.changed_files
print(f"FAKE_CHROOT: {self._fake_chroot}")
self._magician = ImageMagick(
chroot=chroot_path if not self._fake_chroot else "/")
source_resolution = self._magician.get_image_resolution(self._source)
resolutions_from_var = False
resolutions = self._get_resolutions_from_lines(self._lines,
source_resolution)
if not resolutions:
resolutions = self._get_resolutions_from_var(self._datavars)
resolutions_from_var = True
action_md5sum = self._get_action_md5sum(self._source, resolutions)
if not self._check_target_directory(target_path, self._mirror,
resolutions, action_md5sum):
return {}
images_format = self._get_format_value(self._convert,
self._datavars)
if self._convert and self._convert == "GFXBOOT":
converter = self._magician.convert_resize_gfxboot
else:
converter = self._magician.convert_resize_crop_center
output_paths = self._make_output_paths(self._lines, images_format,
target_path, resolutions,
resolutions_from_var)
# Выполняем преобразование изображений в требуемый размер и формат.
for resolution, output_path in output_paths.items():
if not self._check_stretch(source_resolution,
resolution,
self._stretch):
continue
width, height = resolution
converter(self._source, output_path, height, width,
image_format=images_format)
if output_path in self.changed_files:
self.changed_files[output_path] = 'M'
else:
self.changed_files[output_path] = 'N'
self._create_md5sum_file(target_path, action_md5sum)
return self.changed_files
def _get_format_value(self, convert: Union[bool, str],
datavars: Union[Datavars, NamespaceNode, Variables]
) -> str:
"""Метод для получения значения формата."""
if convert:
if convert == "JPG" or convert == "GFXBOOT":
images_format = "JPEG"
else:
images_format = convert
else:
images_format = self._magician.get_image_format(self._source)
return images_format
def _make_output_paths(self, lines: List[str],
images_format: str,
target_path: str,
resolutions: List[Tuple[int, int]],
resolutions_from_var: bool
) -> List[str]:
"""Метод для получения списка путей, по которым будут создаваться
изображения."""
if not self._empty_name:
path, name = os.path.split(target_path)
else:
path = os.path.dirname(target_path)
name = ''
paths = {}
if not resolutions_from_var and len(resolutions) == 1:
if self._empty_name:
raise FormatError("'name' parameter is empty in 'backgrounds'"
" format template with single file output.")
paths = {next(iter(resolutions)): target_path}
return paths
for width, height in resolutions:
paths[(width, height)] = (f"{path}/{name}{width}x{height}"
f".{images_format.lower()}")
return paths
def _get_resolutions_from_lines(self, lines: List[str],
source_resolution: Tuple[int, int]
) -> List[Tuple[int, int]]:
"""Метод для получения списка кортежей с разрешениями выходных
изображений из текста шаблона."""
resolutions = []
if lines:
for line in lines:
if (line.strip() == "original"
and source_resolution not in resolutions):
resolutions.append(source_resolution)
else:
try:
width, height = line.lower().strip().split("x")
resolution = (int(width), int(height))
except Exception:
raise FormatError("can not parse line from template"
" with 'backgrounds' format:"
f" '{line}'")
if resolution not in resolutions:
resolutions.append(resolution)
return resolutions
def _get_resolutions_from_var(self, datavars: Union[Datavars,
NamespaceNode,
Variables]
) -> List[Tuple[int, int]]:
"""Метод для получения списка кортежей с разрешениями выходных
изображений из переменной."""
try:
resolutions = []
for resolution in self._datavars.main.cl_resolutions:
resolution = tuple(resolution.strip().split("x"))
resolutions.append(resolution)
return resolutions
except VariableNotFoundError:
raise FormatError("resolutions values was not found.")
except Exception:
raise FormatError("can not use resolution values from variable:"
" 'main.cl_resolutions'")
def _check_target_directory(self, target_path: str, mirror: bool,
resolutions: List[Tuple[int, int]],
action_md5sum: str
) -> Union[bool, str]:
"""Метод для проверки содержимого целевой директории, удаления
изображений и md5-сумм, подлежащих удалению, а также сравнения
имеющейся в директории md5-суммы с суммой, полученной для действия
текущего шаблона."""
if not self._empty_name:
path, name = os.path.split(target_path)
else:
path = os.path.dirname(target_path)
name = ''
name_pattern = re.compile(rf"^{name}\d+x\d+")
md5sum = None
images = []
# Проверяем содержимое целевой директории.
for node in os.scandir(path):
if node.is_file():
if (node.name ==
f"{name.strip('-_.')}{'.' if name else ''}md5sum"):
md5sum = node.name
elif (node.name == name
or (name_pattern.search(node.name) is not None)):
images.append(node.name)
if not images and md5sum is None:
# Если нет файла суммы и нет изображений -- продолжаем выполнение
# шаблона.
return True
elif not images and md5sum is not None:
# Если есть файл суммы, но нет изображений -- удаляем файл суммы.
md5sum_path = os.path.join(path, md5sum)
os.unlink(md5sum_path)
self.changed_files[md5sum_path] = 'D'
return True
elif images and md5sum is None:
# Если есть файлы изображений, но нет суммы -- удаляем файлы
# изображений.
for image in images:
image_path = os.path.join(path, image)
os.unlink(image_path)
self.changed_files[image_path] = 'D'
return True
else:
# Сравниваем суммы из md5sum и для текущего действия если они
# сходятся, то делать ничего не надо, если нет -- удаляем
# имеющиеся изображения и md5-сумму.
with open(os.path.join(path, md5sum), "r") as md5sum_file:
current_md5sum = md5sum_file.read().strip()
if current_md5sum != action_md5sum:
for image in images:
image_path = os.path.join(path, image)
os.unlink(image_path)
self.changed_files[image_path] = 'D'
md5sum_path = os.path.join(path, md5sum)
os.unlink(md5sum_path)
self.changed_files[md5sum_path] = 'D'
return True
else:
return False
def _check_source(self, source: str, target_path: str, mirror: bool
) -> bool:
"""Метод для проверки исходного изображения."""
if not self._empty_name:
path, name = os.path.split(target_path)
else:
path = os.path.dirname(target_path)
name = ''
name_pattern = re.compile(rf"^{name}\d+x\d+")
if not os.path.exists(source):
if mirror:
for node in os.scandir(path):
if (node.name == name
or name_pattern.search(node.name) is not None
or node.name == (f"{node.name.strip('_-.')}"
f"{ '.' if name else '' }md5sum")):
os.unlink(node.path)
self.changed_files[node.path] = "D"
return False
else:
raise FormatError("image from 'source' parameter does not"
f" exist: {source}.")
return True
def _get_action_md5sum(self, source: str,
resolutions: List[Tuple[int, int]]) -> bool:
"""Метод для получения md5-суммы текущего действия шаблона,
рассчитываемой из последовательности байтов изображения и списка
разрешений, в которые данный файл должен быть конвертирован."""
print("RESOLUTIONS:", resolutions)
with open(source, "rb") as source_file:
md5_object = hashlib.md5(source_file.read())
for width, height in resolutions:
resolution = f"{width}x{height}"
md5_object.update(resolution.encode())
return md5_object.hexdigest()
def _create_md5sum_file(self, target_path: str, action_md5sum: str
) -> NoReturn:
"""Метод для создания файла с md5-суммой действия, выполненного
данным шаблоном."""
if not self._empty_name:
path, name = os.path.split(target_path)
else:
path = os.path.dirname(target_path)
name = ''
md5sum_path = (f"{path}/{name.strip('_-.')}"
f"{ '.' if name else '' }md5sum")
with open(md5sum_path, "w") as md5sum_file:
md5sum_file.write(action_md5sum)
if md5sum_path in self.changed_files:
self.changed_files[md5sum_path] = 'M'
else:
self.changed_files[md5sum_path] = 'N'
def _check_stretch(self, source_resolution: Tuple[int, int],
resolution: Tuple[int, int],
stretch: bool) -> bool:
"""Метод определяющий необходимость растягивания исходного изображения
и делающий вывод о том, возможно ли создание изображения заданного
разрешения исходя из значения параметра stretch."""
return (stretch
or (source_resolution[0] >= resolution[0]
and source_resolution[1] >= resolution[1]))
@property
def warnings(self):
return self._warnings

@ -2,11 +2,15 @@
#
import os
from .base_format import Format, FormatError
from calculate.utils.files import join_paths
from pyparsing import Literal, Regex, SkipTo, LineEnd, lineno, LineStart
from calculate.utils.package import PackageAtomParser, Package, PackageNotFound
from calculate.utils.files import join_paths
from glob import iglob
from ..template_engine import ParametersContainer, Variables
from ...variables.datavars import NamespaceNode
from ...variables.loader import Datavars
from fnmatch import fnmatch
from typing import Union
from glob import iglob
ADD, REMOVE, MOVE = range(0, 3)
@ -25,7 +29,8 @@ class ContentsFormat(Format):
def __init__(self, template_text: str,
template_path: str,
ignore_comments=None):
parameters: ParametersContainer,
datavars: Union[Datavars, NamespaceNode, Variables]):
self._command_methods = {ADD: self._add_command,
REMOVE: self._remove_command,
MOVE: self._move_command}
@ -39,7 +44,10 @@ class ContentsFormat(Format):
self._packages = dict()
self._atom_parser = None
def execute_format(self, target_path, chroot_path='/'):
# Предупреждения.
self._warnings: list = []
def execute_format(self, target_path: str, chroot_path='/') -> dict:
'''Метод для запуска работы формата.'''
self._package = dict()
self._atom_parser = PackageAtomParser(chroot_path=chroot_path)
@ -215,3 +223,7 @@ class ContentsFormat(Format):
if not result:
return [None]
return {'error': result, 'lineno': lineno(location, string)}
@property
def warnings(self):
return self._warnings

@ -3,6 +3,10 @@
from .base_format import Format
from calculate.utils.files import Process
from calculate.templates.format.base_format import FormatError
from ..template_engine import ParametersContainer, Variables
from ...variables.datavars import NamespaceNode
from ...variables.loader import Datavars
from typing import Union
from os import path
@ -12,7 +16,8 @@ class PatchFormat(Format):
def __init__(self, patch_text: str,
template_path: str,
ignore_comments=None):
parameters: ParametersContainer,
datavars: Union[Datavars, NamespaceNode, Variables]):
self._patch_text = patch_text
self._cwd_path = '/'
self._last_level = 0
@ -20,6 +25,9 @@ class PatchFormat(Format):
# Измененные файлы.
self.changed_files = dict()
# Предупреждения.
self._warnings: list = []
def execute_format(self, target_path, chroot_path='/'):
'''Метод для запуска работы формата.'''
self._cwd_path = target_path
@ -81,3 +89,7 @@ class PatchFormat(Format):
def __bool__(self):
return bool(self._patch_text)
@property
def warnings(self):
return self._warnings

@ -1,12 +1,15 @@
# vim: fileencoding=utf-8
#
from jinja2.ext import Extension
from jinja2.lexer import Token
from jinja2.parser import Parser
from jinja2 import (
Environment,
FileSystemLoader,
TemplateSyntaxError,
nodes,
contextfunction
contextfunction,
Template,
)
from jinja2.utils import missing
from jinja2.runtime import Context, Undefined
@ -22,7 +25,10 @@ from typing import (
Union,
Any,
List,
Tuple
Tuple,
NoReturn,
Optional,
Iterator,
)
from ..utils.package import (
PackageAtomName,
@ -39,6 +45,7 @@ from ..utils.files import (
FilesError
)
from calculate.variables.datavars import (
VariableNotFoundError,
HashType,
NamespaceNode,
VariableNode,
@ -55,7 +62,6 @@ import calculate.templates.template_filters as template_filters
# Типы шаблона: директория или файл.
DIR, FILE, LINK = range(3)
# Словарь, в котором можно регистрировать фильтры.
CALCULATE_FILTERS = {"cut": template_filters.cut}
@ -79,19 +85,23 @@ class ConditionFailed(TemplateSyntaxError):
class Variables(MutableMapping):
'''Класс-заглушка вместо модуля переменных для тестов.'''
def __init__(self, *args, **kwargs):
self.__attrs = dict(*args, **kwargs)
self.__attrs: dict = dict(*args, **kwargs)
self.__iter: Union[Iterator, None] = None
def __next__(self):
iterator = iter(self.__attrs)
return next(iterator)
def __next__(self) -> Any:
if self._iter is None:
self._iter = iter(self.__attrs)
return next(self._iter)
def __getattribute__(self, name: str):
def __getattribute__(self, name: str) -> Any:
if name == '_Variables__attrs':
return super().__getattribute__(name)
if name == 'available_packages':
return super().__getattribute__(name)
if name == '_variables':
return self.__attrs
if name == '_iter':
return self._iter
try:
return self.__attrs[name]
except KeyError:
@ -103,16 +113,16 @@ class Variables(MutableMapping):
packages.update({'custom'})
return packages
def __getitem__(self, name: str):
def __getitem__(self, name: str) -> Any:
return self.__attrs[name]
def __setitem__(self, name: str, value) -> None:
def __setitem__(self, name: str, value: Any) -> NoReturn:
self.__attrs[name] = value
def __delitem__(self, name: str) -> None:
def __delitem__(self, name: str) -> NoReturn:
del self.__attrs[name]
def __iter__(self):
def __iter__(self) -> Iterator:
return iter(self.__attrs)
def __len__(self) -> int:
@ -124,7 +134,7 @@ class Variables(MutableMapping):
def __contains__(self, name: str) -> bool:
return name in self.__attrs
def __hash__(self):
def __hash__(self) -> int:
return hash(id(self))
@ -135,7 +145,8 @@ class ParametersProcessor:
'format', 'unbound', 'mirror', 'run', 'exec',
'env', 'package', 'merge', 'postmerge',
'action', 'rebuild', 'restart', 'stop',
'start', 'handler', 'notify', 'group'}
'start', 'handler', 'notify', 'group',
'convert', 'stretch'}
inheritable_parameters: set = {'chmod', 'chown', 'autoupdate', 'env',
'package', 'action', 'handler', 'group'}
@ -158,21 +169,24 @@ class ParametersProcessor:
r'([r-][w-][Xx-])([r-][w-][Xx-])([r-][w-][Xx-])')
def __init__(self,
parameters_container: Union["ParametersContainer",
None] = None,
parameters_container: Optional["ParametersContainer"] = None,
chroot_path: str = '/',
datavars_module: Union[Datavars, Variables] = Variables(),
for_package: Union[Package, None] = None):
datavars_module: Union[Datavars,
NamespaceNode,
Variables] = Variables(),
for_package: Optional[Package] = None):
self.chroot_path: str = chroot_path
self.template_type: int = DIR
self.datavars_module: Union[Datavars, Variables] = datavars_module
self.datavars_module: Union[Datavars,
NamespaceNode,
Variables] = datavars_module
self._parameters_container: ParametersContainer = parameters_container
self.package_atom_parser: PackageAtomParser =\
PackageAtomParser(chroot_path=chroot_path)
self.package_atom_parser: PackageAtomParser = PackageAtomParser(
chroot_path=chroot_path)
self._groups: dict = {}
try:
@ -212,7 +226,9 @@ class ParametersProcessor:
'merge': self.check_merge_parameter,
'format': self.check_format_parameter,
'handler': self.check_handler_parameter,
'notify': self.check_notify_parameter
'notify': self.check_notify_parameter,
'convert': self.check_convert_parameter,
'stretch': self.check_stretch_parameter,
})
# Если добавляемый параметр должен быть проверен после того, как
@ -225,7 +241,9 @@ class ParametersProcessor:
'autoupdate': self.check_postparse_autoupdate,
'run': self.check_postparse_run,
'exec': self.check_postparse_exec,
'handler': self.check_postparse_handler
'handler': self.check_postparse_handler,
'convert': self.check_postparse_convert,
'stretch': self.check_postparse_stretch,
})
# Если параметр является наследуемым только при некоторых условиях --
@ -234,7 +252,7 @@ class ParametersProcessor:
def set_parameters_container(self,
parameters_container: "ParametersContainer"
) -> None:
) -> NoReturn:
'''Метод для установки текущего контейнера параметров.'''
self._parameters_container = parameters_container
self._added_parameters = set()
@ -244,7 +262,7 @@ class ParametersProcessor:
return self._for_package
@for_package.setter
def for_package(self, package: Package):
def for_package(self, package: Package) -> NoReturn:
self._for_package = package
def __getattr__(self, parameter_name: str) -> Any:
@ -258,7 +276,7 @@ class ParametersProcessor:
def check_template_parameter(self, parameter_name: str,
parameter_value: Any,
template_type: int, lineno: int) -> None:
template_type: int, lineno: int) -> NoReturn:
'''Метод, проверяющий указанный параметр.'''
self.lineno = lineno
self.template_type = template_type
@ -293,7 +311,7 @@ class ParametersProcessor:
self._parameters_container.set_parameter({parameter_name:
checked_value})
def check_postparse_parameters(self) -> None:
def check_postparse_parameters(self) -> NoReturn:
'''Метод, запускающий проверку параметров после их разбора.'''
for parameter, parameter_checker in\
self.postparse_checkers_list.items():
@ -306,7 +324,7 @@ class ParametersProcessor:
result)
def check_template_parameters(self, parameters: dict,
template_type: int, lineno: int) -> None:
template_type: int, lineno: int) -> NoReturn:
'''Метод, запускающий проверку указанных параметров.'''
self.template_type = template_type
self.lineno = lineno
@ -339,7 +357,6 @@ class ParametersProcessor:
parameter_name=checked_value)
# Методы для проверки параметров во время разбора шаблона.
def check_package_parameter(self, parameter_value: Any) -> str:
if not isinstance(parameter_value, str):
raise IncorrectParameter("'package' parameter must have value of"
@ -402,17 +419,17 @@ class ParametersProcessor:
raise IncorrectParameter(
"'restart' parameter value is not correct")
def check_stop_parameter(self, parameter_value: Any):
def check_stop_parameter(self, parameter_value: Any) -> str:
if not parameter_value and isinstance(parameter_value, bool):
raise IncorrectParameter("'stop' parameter value is empty")
return parameter_value
def check_start_parameter(self, parameter_value: Any):
def check_start_parameter(self, parameter_value: Any) -> str:
if not parameter_value and isinstance(parameter_value, bool):
raise IncorrectParameter("'start' parameter value is empty")
return parameter_value
def check_run_parameter(self, parameter_value: Any):
def check_run_parameter(self, parameter_value: Any) -> str:
if self.template_type == DIR:
raise IncorrectParameter("'run' parameter is not available in"
" directory templates")
@ -425,7 +442,7 @@ class ParametersProcessor:
" found")
return interpreter_path
def check_exec_parameter(self, parameter_value: Any):
def check_exec_parameter(self, parameter_value: Any) -> str:
if self.template_type == DIR:
raise IncorrectParameter("'exec' parameter is not available in"
" directory templates")
@ -438,7 +455,7 @@ class ParametersProcessor:
" found")
return interpreter_path
def check_chown_parameter(self, parameter_value: Any):
def check_chown_parameter(self, parameter_value: Any) -> dict:
if not parameter_value or isinstance(parameter_value, bool):
raise IncorrectParameter("'chown' parameter value is empty.")
parameter_value = self.get_chown_values(parameter_value)
@ -478,7 +495,8 @@ class ParametersProcessor:
x_mask = x_mask + "0"
return (int(chmod, 2), int(x_mask, 2))
def check_source_parameter(self, parameter_value: Any):
def check_source_parameter(self, parameter_value: Any
) -> Union[str, Tuple[bool, str]]:
if not parameter_value or isinstance(parameter_value, bool):
raise IncorrectParameter("'source' parameter value is empty")
@ -510,7 +528,7 @@ class ParametersProcessor:
return os.path.normpath(real_path)
def check_env_parameter(self, parameter_value: Any):
def check_env_parameter(self, parameter_value: Any) -> Union[None, set]:
env_set = set()
for env_value in parameter_value.split(','):
@ -538,20 +556,20 @@ class ParametersProcessor:
return env_set
def check_force_parameter(self, parameter_value: Any):
def check_force_parameter(self, parameter_value: Any) -> bool:
if isinstance(parameter_value, bool):
return parameter_value
else:
raise IncorrectParameter("'force' parameter value is not bool")
def check_autoupdate_parameter(self, parameter_value: Any):
def check_autoupdate_parameter(self, parameter_value: Any) -> bool:
if isinstance(parameter_value, bool):
return parameter_value
else:
raise IncorrectParameter(
"'autoupdate' parameter value is not bool.")
def check_format_parameter(self, parameter_value: Any):
def check_format_parameter(self, parameter_value: Any) -> str:
if self.template_type == DIR:
raise IncorrectParameter("'format' parameter is redundant for"
" directory templates.")
@ -564,13 +582,13 @@ class ParametersProcessor:
raise IncorrectParameter("'format' parameter must be string value not"
f" {type(parameter_value)}.")
def check_handler_parameter(self, parameter_value: Any):
def check_handler_parameter(self, parameter_value: Any) -> str:
if not isinstance(parameter_value, str):
raise IncorrectParameter("'handler' parameter must be string"
f" value not {type(parameter_value)}.")
return parameter_value
def check_notify_parameter(self, parameter_value: Any):
def check_notify_parameter(self, parameter_value: Any) -> List[str]:
if isinstance(parameter_value, list):
return parameter_value
elif isinstance(parameter_value, str):
@ -579,9 +597,33 @@ class ParametersProcessor:
raise IncorrectParameter("'notify' parameter must be string or list"
f" value not {type(parameter_value)}.")
# Методы для проверки параметров после разбора всего шаблона.
def check_convert_parameter(self, parameter_value: Any) -> str:
if not isinstance(parameter_value, str):
raise IncorrectParameter("'convert' parameter value must be string"
f" not '{type(parameter_value)}'.")
parameter_value = parameter_value.strip().upper()
try:
available_image_formats =\
self.datavars_module.main.cl_image_formats
except VariableNotFoundError:
# TODO возможно стоит кидать ошибку.
available_image_formats = ["JPEG", "PNG", "GIF", "JPG"]
if parameter_value not in available_image_formats:
raise IncorrectParameter(f"'{parameter_value}' image format is "
"not available. Available image formats: "
f"'{', '.join(available_image_formats)}.'"
)
return parameter_value
def check_stretch_parameter(self, parameter_value: Any) -> bool:
if not isinstance(parameter_value, bool):
raise IncorrectParameter("'stretch' parameter value should be bool"
f" value not '{type(parameter_value)}'")
return parameter_value
def check_postparse_append(self, parameter_value):
# Методы для проверки параметров после разбора всего шаблона.
def check_postparse_append(self, parameter_value: str) -> NoReturn:
if parameter_value == 'link':
if 'source' not in self._parameters_container:
raise IncorrectParameter("append = 'link' without source "
@ -595,7 +637,7 @@ class ParametersProcessor:
raise IncorrectParameter("'append' parameter is not 'compatible' "
"with the 'exec' parameter")
def check_postparse_run(self, parameter_value):
def check_postparse_run(self, parameter_value: str) -> NoReturn:
if self._parameters_container.append:
raise IncorrectParameter("'run' parameter is not 'compatible' "
"with the 'append' parameter")
@ -604,7 +646,7 @@ class ParametersProcessor:
raise IncorrectParameter("'run' parameter is not 'compatible' "
"with the 'exec' parameter")
def check_postparse_exec(self, parameter_value):
def check_postparse_exec(self, parameter_value: str) -> NoReturn:
if self._parameters_container.append:
raise IncorrectParameter("'exec' parameter is not 'compatible' "
"with the 'append' parameter")
@ -613,13 +655,16 @@ class ParametersProcessor:
raise IncorrectParameter("'exec' parameter is not 'compatible' "
"with the 'run' parameter")
def check_postparse_source(self, parameter_value):
def check_postparse_source(self,
parameter_value: Union[str, Tuple[bool, str]]
) -> NoReturn:
# Если файл по пути source не существует, но присутствует параметр
# mirror -- пропускаем шаблон для того, чтобы целевой файл мог быть
# удален в исполнительном модуле.
if isinstance(parameter_value, tuple):
if (self._parameters_container.append == "link" and
self._parameters_container.force):
if ((self._parameters_container.append == "link" and
self._parameters_container.force)
or self._parameters_container.format == "backgrounds"):
self._parameters_container['source'] = parameter_value[1]
elif not self._parameters_container.mirror:
raise IncorrectParameter(
@ -632,12 +677,12 @@ class ParametersProcessor:
"append = 'link' for directory template")
)
def check_postparse_autoupdate(self, parameter_value):
def check_postparse_autoupdate(self, parameter_value: bool) -> NoReturn:
if self._parameters_container.unbound:
raise IncorrectParameter("'unbound' parameter is incompatible"
" with 'autoupdate' parameter")
def check_postparse_handler(self, parameter_value):
def check_postparse_handler(self, parameter_value: bool) -> NoReturn:
if self._parameters_container.merge:
raise IncorrectParameter("'merge' parameter is not available"
" in handler templates")
@ -646,7 +691,7 @@ class ParametersProcessor:
raise IncorrectParameter("'package' parameter is not available"
" in handler templates")
def check_postparse_package(self, parameter_value):
def check_postparse_package(self, parameter_value: str) -> NoReturn:
groups = []
package_atom = PackageAtomParser.parse_atom_name(parameter_value)
@ -679,7 +724,8 @@ class ParametersProcessor:
" does not match the template condition",
self.lineno if hasattr(self, 'lineno') else 0)
def _check_package_group(self, package: dict, group_packages: list):
def _check_package_group(self, package: dict, group_packages: list
) -> bool:
'''Метод для проверки соответствия описания пакета, заданного словарем,
какому-либо описанию пакета, заданного в переменных groups.'''
for group_package in group_packages:
@ -699,16 +745,28 @@ class ParametersProcessor:
return True
return False
def check_postparse_convert(self, parameter_value: str) -> NoReturn:
template_format = self._parameters_container.format
if not template_format or template_format != "backgrounds":
raise IncorrectParameter("'convert' parameter available for"
" 'backgrounds' format only.")
def check_postparse_stretch(self, parameter_value: str) -> NoReturn:
template_format = self._parameters_container.format
if not template_format or template_format != "backgrounds":
raise IncorrectParameter("'stretch' parameter available for"
" 'backgrounds' format only.")
# Методы для проверки того, являются ли параметры наследуемыми.
def is_chmod_inheritable(self, parameter_value):
def is_chmod_inheritable(self, parameter_value: str) -> bool:
chmod_regex = re.compile(r'\d+')
if chmod_regex.search(parameter_value):
return False
return True
def get_chown_values(self, chown: str):
def get_chown_values(self, chown: str) -> dict:
"""Получить значения uid и gid из параметра chown."""
if chown and ':' in chown:
user_name, group_name = chown.split(':')
@ -746,7 +804,7 @@ class ParametersProcessor:
raise IncorrectParameter("'chown' value '{0}' is not correct".
format(chown))
def get_uid_from_passwd(self, user_name: str):
def get_uid_from_passwd(self, user_name: str) -> int:
"""Функция для получения uid из chroot passwd файла."""
passwd_file_path = os.path.join(self.chroot_path, 'etc/passwd')
passwd_dictionary = dict()
@ -771,7 +829,7 @@ class ParametersProcessor:
raise FilesError("passwd file was not found in {}".
format(passwd_file_path))
def get_gid_from_group(self, group_name: str):
def get_gid_from_group(self, group_name: str) -> int:
"""Функция для получения gid из chroot group файла."""
group_file_path = os.path.join(self.chroot_path, 'etc/group')
group_dictionary = dict()
@ -797,7 +855,7 @@ class ParametersProcessor:
format(group_file_path))
@classmethod
def _inspect_formats_package(cls):
def _inspect_formats_package(cls) -> NoReturn:
'''Метод для определения множества доступных форматов и
предоставляемых ими параметров.'''
if cls.format_is_inspected:
@ -845,9 +903,13 @@ class ParametersProcessor:
cls.formats_inspected = True
def resolve_or_missing(context, key, missing=missing, env={}):
def resolve_or_missing(context: "CalculateContext",
key: str, missing=missing,
env: Optional[set] = None) -> Any:
'''Переопределение функции из для поиска значений переменных из jinja2.
Ищет переменные в datavars.'''
if env is None:
env = {}
datavars = context.parent['__datavars__']
if key in context.vars:
@ -871,7 +933,7 @@ class CalculateContext(Context):
сохранять их.'''
_env_set = set()
def resolve(self, key):
def resolve(self, key: str) -> Any:
if self._legacy_resolve_mode:
rv = resolve_or_missing(self, key,
env=self._env_set)
@ -881,7 +943,7 @@ class CalculateContext(Context):
return self.environment.undefined(name=key)
return rv
def resolve_or_missing(self, key):
def resolve_or_missing(self, key: str) -> Any:
if self._legacy_resolve_mode:
rv = self.resolve(key)
if isinstance(rv, Undefined):
@ -894,56 +956,56 @@ class CalculateContext(Context):
class ParametersContainer(MutableMapping):
'''Класс для хранения параметров, взятых из шаблона, и передачи
их шаблонизатору.'''
def __init__(self, parameters_dictionary=None):
def __init__(self, parameters_dictionary: Optional[dict] = None):
# Слой ненаследуемых параметров.
self.__parameters = {}
self.__parameters: dict = {}
# Слой наследуемых параметров.
if parameters_dictionary is not None:
self.__inheritable = parameters_dictionary
self.__inheritable: dict = parameters_dictionary
else:
self.__inheritable = {}
self.__inheritable: dict = {}
def set_parameter(self, item_to_add: dict):
def set_parameter(self, item_to_add: dict) -> NoReturn:
self.__parameters.update(item_to_add)
def set_inheritable(self, item_to_add: dict):
def set_inheritable(self, item_to_add: dict) -> NoReturn:
self.__inheritable.update(item_to_add)
def get_inheritables(self):
def get_inheritables(self) -> "ParametersContainer":
return ParametersContainer(copy.deepcopy(self.__inheritable))
def remove_not_inheritable(self):
def remove_not_inheritable(self) -> NoReturn:
self.__parameters.clear()
def print_parameters_for_debug(self):
def print_parameters_for_debug(self) -> NoReturn:
print('Parameters:')
pprint(self.__parameters)
print('Inherited:')
pprint(self.__inheritable)
def is_inherited(self, parameter_name):
def is_inherited(self, parameter_name: str) -> bool:
return (parameter_name not in self.__parameters
and parameter_name in self.__inheritable)
def remove_parameter(self, parameter_name):
def remove_parameter(self, parameter_name: str) -> NoReturn:
if parameter_name in self.__parameters:
self.__parameters.pop(parameter_name)
elif parameter_name in self.__inheritable:
self.__inheritable.pop(parameter_name)
def change_parameter(self, parameter, value):
def change_parameter(self, parameter: str, value: Any) -> NoReturn:
if parameter in self.__parameters:
self.__parameters.update({parameter: value})
elif parameter in self.__inheritable:
self.__inheritable.update({parameter: value})
def _clear_container(self):
def _clear_container(self) -> NoReturn:
self.__parameters.clear()
self.__inheritable.clear()
def __getattr__(self, parameter_name):
def __getattr__(self, parameter_name: str) -> Any:
if (parameter_name not in
ParametersProcessor.available_parameters):
raise IncorrectParameter("Unknown parameter: '{}'".
@ -956,7 +1018,7 @@ class ParametersContainer(MutableMapping):
else:
return False
def __getitem__(self, name):
def __getitem__(self, name: str) -> Any:
if name in self.__parameters:
return self.__parameters[name]
elif name in self.__inheritable:
@ -964,31 +1026,31 @@ class ParametersContainer(MutableMapping):
else:
return False
def __setitem__(self, name, value):
def __setitem__(self, name: str, value: Any) -> NoReturn:
self.__parameters[name] = value
def __delitem__(self, name):
def __delitem__(self, name: str) -> NoReturn:
if name in self.__parameters:
del self.__parameters[name]
if name in self.__inheritable:
del self.__inheritable[name]
def __iter__(self):
def __iter__(self) -> Iterator[str]:
return iter(set(self.__parameters).union(self.__inheritable))
def __len__(self):
def __len__(self) -> int:
return len(set(self.__parameters).union(self.__inheritable))
def __repr__(self):
def __repr__(self) -> str:
return '<ParametersContainer: parameters={0}, inheritables={1}>'.\
format(self.__parameters, self.__inheritable)
def __contains__(self, name):
def __contains__(self, name: str) -> bool:
return name in self.__parameters or name in self.__inheritable
@property
def parameters(self):
def parameters(self) -> dict:
return self.__parameters
@ -999,10 +1061,14 @@ class CalculateExtension(Extension):
# Виды операций в теге save.
ASSIGN, APPEND, REMOVE = range(3)
def __init__(self, environment, parameters_processor: ParametersProcessor,
datavars_module=Variables(), chroot_path="/"):
def __init__(self, environment: Environment,
parameters_processor: ParametersProcessor,
datavars_module: Union[Datavars,
NamespaceNode,
Variables] = Variables(),
chroot_path: str = "/"):
super().__init__(environment)
self.environment = environment
self.environment: Environment = environment
self.package_atom_parser = PackageAtomParser(chroot_path=chroot_path)
self.environment.globals.update({'pkg': self.pkg})
@ -1011,11 +1077,11 @@ class CalculateExtension(Extension):
self._datavars = datavars_module
self.parameters_processor = parameters_processor
self.template_type = DIR
self.template_type: int = DIR
# Флаг, указывающий, что тег calculate уже был разобран. Нужен для
# того, чтобы проверять единственность тега calculate.
self.calculate_parsed = False
self.calculate_parsed: bool = False
self.tags = {'calculate', 'save', 'set_var'}
self.CONDITION_TOKENS_TYPES = {'eq', 'ne', 'lt', 'gt', 'lteq', 'gteq'}
@ -1031,24 +1097,25 @@ class CalculateExtension(Extension):
self.parse_methods = {'calculate': self.parse_calculate,
'save': self.parse_save}
def __call__(self, env):
def __call__(self, env: Environment) -> "CalculateExtension":
# Необходимо для обеспечения возможности передать готовый объект
# расширения, а не его класс.
return self
def parse(self, parser):
def parse(self, parser: Parser) -> List[nodes.Output]:
self.parser = parser
self.stream = parser.stream
tag_token = self.stream.current.value
return [self.parse_methods[tag_token]()]
def parse_save(self):
def parse_save(self) -> nodes.Output:
'''Метод для разбора тега save, сохраняющего значение указанной
переменной datavars.'''
lineno = next(self.stream).lineno
target_file = nodes.Const('', lineno=lineno)
# Получаем имя целевого файла.
if self.stream.skip_if('dot'):
target_file_name = self.stream.expect('name').value
if target_file_name in self.TARGET_FILES_SET:
@ -1084,7 +1151,7 @@ class CalculateExtension(Extension):
raise TemplateSyntaxError("'=' is expected in 'save' tag",
lineno=lineno)
def parse_calculate(self):
def parse_calculate(self) -> nodes.Output:
'''Метод для разбора тега calculate, содержащего значения параметров и
условия выполнения шаблона.'''
lineno = next(self.stream).lineno
@ -1155,7 +1222,7 @@ class CalculateExtension(Extension):
self.calculate_parsed = True
return nodes.Output([nodes.Const('')], lineno=lineno)
def _is_variable_name(self, token):
def _is_variable_name(self, token: Token) -> bool:
'''Метод для проверки токена на предмет того, что он является частью
имени переменной.'''
if not token.type == 'name':
@ -1168,7 +1235,8 @@ class CalculateExtension(Extension):
return True
return False
def check_parameter(self, parameter_name, parameter_value, context):
def check_parameter(self, parameter_name: str, parameter_value: Any,
context: CalculateContext) -> str:
self.parameters_processor.check_template_parameter(
parameter_name,
parameter_value,
@ -1176,7 +1244,7 @@ class CalculateExtension(Extension):
self.stream.current.lineno)
return ''
def parse_condition(self):
def parse_condition(self) -> Template:
try:
condition_node = self.parser.parse_expression(with_condexpr=True)
condition_node = self.call_method(
@ -1196,7 +1264,7 @@ class CalculateExtension(Extension):
.format(str(error)),
lineno=self.stream.current.lineno)
def check_conditions(self, conditions: list):
def check_conditions(self, conditions: List[Template]) -> NoReturn:
for condition in conditions:
self.condition_result = False
try:
@ -1210,7 +1278,7 @@ class CalculateExtension(Extension):
lineno=self.stream.current.lineno)
# DEPRECATED
def get_condition_result(self):
def get_condition_result(self) -> bool:
'''Метод для разбора условий из тега calculate.'''
self.condition_result = False
@ -1233,13 +1301,14 @@ class CalculateExtension(Extension):
return self.condition_result
def set_condition_result(self, condition_result):
def set_condition_result(self, condition_result: Any) -> str:
'''Метод для сохранения результата вычисления условия.'''
self.condition_result = condition_result
return ''
def _make_save_node(self, variable_name_node, target_file_node, optype,
lineno):
def _make_save_node(self, variable_name_node: nodes.List,
target_file_node: nodes.Const, optype: int,
lineno: int) -> nodes.Output:
'''Метод для создания ноды, сохраняющей переменные.'''
right_value = self.parser.parse_expression(with_condexpr=True)
optype_node = nodes.Const(optype, lineno=lineno)
@ -1252,8 +1321,9 @@ class CalculateExtension(Extension):
lineno=lineno)
return nodes.Output([save_variable_node], lineno=lineno)
def save_variable(self, variable, right_value, target_file,
optype, context):
def save_variable(self, variable: List[str], right_value: Any,
target_file: str, optype: int,
context: CalculateContext) -> str:
'''Метод для сохранения значений переменных указанных в теге save.'''
datavars = context.parent['__datavars__']
if variable[0] not in datavars:
@ -1272,7 +1342,7 @@ class CalculateExtension(Extension):
# Теперь меняем знaчение переменной.
if isinstance(value_container, NamespaceNode):
self._modify_variables(variable, value_container, right_value,
optype, target=target_file,
optype, target_file=target_file,
modify_only=modify_only)
elif isinstance(value_container, VariableNode):
hash_value = value_container.get_value().get_hash()
@ -1296,7 +1366,7 @@ class CalculateExtension(Extension):
def _find_value_container(self, variable: List[str],
vars_package: NamespaceNode,
modify_only: bool = True
) -> Union[NamespaceNode]:
) -> Union[NamespaceNode, VariableNode]:
'''Метод для поиска контейнера, путь к которому указан в аргументе.
Этим контейнером может быть пространство имен или хэш.'''
current_container = vars_package
@ -1329,8 +1399,10 @@ class CalculateExtension(Extension):
current_container.get_fullname()))
return current_container
def _modify_variables(self, variable, namespace, new_value, optype,
target='', modify_only=True):
def _modify_variables(self, variable: List[str], namespace: NamespaceNode,
new_value: Any, optype: int,
target_file: Optional[str] = None,
modify_only: bool = True) -> NoReturn:
'''Метод для модификации значения переменной.'''
variable_name = variable[-1]
@ -1353,18 +1425,20 @@ class CalculateExtension(Extension):
raise SaveError("can not create variable '{}' in not 'custom'"
" namespace".format('.'.join(variable)))
if target:
if target_file:
if namespace._variables[variable_name].variable_type is HashType:
for key, value in new_value.items():
self._save_to_target(variable, key, value, target)
self._save_to_target(variable, key, value, target_file)
else:
self._save_to_target(variable[:-1], variable_name,
new_value, target)
new_value, target_file)
def _modify_hash(self, variable, hash_variable, new_value, optype,
target=''):
# DEPRECATED
def _modify_hash(self, variable_name: List[str],
hash_variable: VariableNode, new_value, optype,
target_file: Optional[str] = None) -> NoReturn:
'''Метод для модификации значения в переменной-хэше.'''
value_name = variable[-1]
value_name = variable_name[-1]
hash_value = hash_variable.get_value().get_hash()
if value_name in hash_value:
@ -1376,22 +1450,25 @@ class CalculateExtension(Extension):
hash_value.update({value_name: new_value})
hash_variable.set(hash_value)
if target:
self._save_to_target(variable[:-1], value_name,
new_value, target)
if target_file:
self._save_to_target(variable_name[:-1], value_name,
new_value, target_file)
def _save_to_target(self, namespace_name, variable_name, value, target):
def _save_to_target(self, namespace_name: List[str],
variable_name: str, value: Any, target_file: str
) -> NoReturn:
'''Метод для добавления переменной в список переменных, значение
которых было установлено через тег save и при этом должно быть
сохранено в указанном файле: save.target_file.'''
namespace_name = tuple(namespace_name)
target_file_dict = self._datavars.variables_to_save[target]
target_file_dict = self._datavars.variables_to_save[target_file]
if namespace_name not in target_file_dict:
target_file_dict.update({namespace_name: dict()})
target_file_dict[namespace_name].update(
{variable_name: ('=', str(value))})
def _append_variable_value(self, variable, value):
def _append_variable_value(self, variable: VariableNode,
value: Any) -> Any:
'''Метод описывающий операцию += в теге save.'''
variable_value = variable.get_value()
if (variable.variable_type is IntegerType or
@ -1429,7 +1506,8 @@ class CalculateExtension(Extension):
# значение.
return variable_value
def _remove_variable_value(self, variable, value):
def _remove_variable_value(self, variable: VariableNode, value: Any
) -> Any:
'''Метод описывающий операцию -= в теге save.'''
variable_value = variable.get_value()
@ -1469,7 +1547,7 @@ class CalculateExtension(Extension):
# значение.
return variable_value
def _get_parameter(self):
def _get_parameter(self) -> Tuple[nodes.Const, nodes.Node]:
'''Метод для разбора параметров, содержащихся в теге calculate.'''
lineno = self.stream.current.lineno
@ -1491,13 +1569,14 @@ class CalculateExtension(Extension):
return (parameter_name_node, parameter_rvalue)
def save_parameters(cls, parameters_dictionary, context):
def save_parameters(cls, parameters_dictionary: dict,
context: CalculateContext) -> str:
'''Метод для сохранения значений параметров.'''
context.parent['__parameters__'].set_parameter(parameters_dictionary)
return ''
@contextfunction
def pkg(self, context, *args) -> Version:
def pkg(self, context: CalculateContext, *args: dict) -> Version:
'''Метод, реализующий функцию pkg() шаблонов. Функция предназначена для
получения версии пакета, к которому уже привязан шаблон, если
аргументов нет, или версию пакета в аргументе функции. Если аргументов
@ -1518,7 +1597,7 @@ class CalculateExtension(Extension):
return Version()
return package.version
def get_full_filepath(self, fname):
def get_full_filepath(self, fname: str) -> str:
# TODO: добавить получение домашней директории пользователя
# if fname[0] == "~":
# # Получаем директорию пользователя
@ -1531,10 +1610,9 @@ class CalculateExtension(Extension):
return fname
@contextfunction
def grep(self, context, fname, regpattern) -> str:
'''
Метод реализующий функцию grep
'''
def grep(self, context: CalculateContext, fname: str,
regpattern: str) -> str:
'''Метод реализующий функцию grep.'''
fname = self.get_full_filepath(fname)
try:
reg = re.compile(regpattern, re.MULTILINE)
@ -1554,10 +1632,8 @@ class CalculateExtension(Extension):
return ""
@contextfunction
def exists(self, context, fname) -> str:
'''
Метод реализующий функцию exists
'''
def exists(self, context: CalculateContext, fname: str) -> str:
'''Метод реализующий функцию exists.'''
fname = self.get_full_filepath(fname)
try:
@ -1627,19 +1703,20 @@ class TemplateEngine:
self.environment.context_class = CalculateContext
@property
def for_package(self):
def for_package(self) -> Package:
return self.parameters_processor.for_package
@for_package.setter
def for_package(self, package):
def for_package(self, package: Package) -> NoReturn:
self.parameters_processor.for_package = package
def change_directory(self, directory_path):
def change_directory(self, directory_path: str) -> NoReturn:
'''Метод для смены директории в загрузчике.'''
self.environment.loader = FileSystemLoader(directory_path)
def process_template(self, template_path, template_type,
parameters=None):
def process_template(self, template_path: str, template_type: str,
parameters: Optional[ParametersContainer] = None
) -> NoReturn:
'''Метод для обработки файла шаблона, расположенного по указанному
пути.'''
if parameters is not None:
@ -1666,8 +1743,10 @@ class TemplateEngine:
Version=Version
)
def process_template_from_string(self, string, template_type,
parameters=None):
def process_template_from_string(
self, string: str, template_type: int,
parameters: Optional[ParametersContainer] = None
) -> NoReturn:
'''Метод для обработки текста шаблона.'''
if parameters is not None:
self._parameters_object = parameters
@ -1694,10 +1773,10 @@ class TemplateEngine:
)
@property
def parameters(self):
def parameters(self) -> ParametersContainer:
return self._parameters_object
@property
def template_text(self):
def template_text(self) -> str:
text, self._template_text = self._template_text, ''
return text

@ -275,7 +275,8 @@ class TemplateWrapper:
# Если установлен параметр mirror и есть параметр source,
# содержащий несуществующий путь -- удаляем целевой файл.
if self.parameters.source is True and self.parameters.mirror:
if (self.parameters.source is True and self.parameters.mirror and
not self.format_class.EXECUTABLE):
self.remove_original = True
else:
self.target_type = None
@ -283,13 +284,10 @@ class TemplateWrapper:
if self.format_class is not None and self.format_class.EXECUTABLE:
# Если формат исполняемый -- проверяем, существует ли директория,
# из которой будет выполняться шаблон.
if not os.path.exists(self.target_path):
if self.target_type is None:
# Если не существует -- создаем ее.
os.makedirs(self.target_path)
elif os.path.isfile(self.target_path):
# Если вместо директории файл -- определяем по файлу
# директорию.
self.target_path = os.path.dirname(self.target_path)
if not os.path.exists(os.path.dirname(self.target_path)):
os.makedirs(os.path.dirname(self.target_path))
# Если есть параметр package, определяем по нему пакет.
if self.parameters.package:
@ -656,11 +654,12 @@ class TemplateWrapper:
def update_contents_from_list(self, changed_list: dict) -> NoReturn:
'''Метод для изменения CONTENTS по списку измененных файлов.'''
print("UPDATE CONTENTS FROM LIST")
if self.target_package is None:
return
for file_path, mode in changed_list.items():
if mode == "M":
if mode in {"M", "N"}:
if os.path.islink(file_path):
self.target_package.add_sym(file_path)
@ -790,7 +789,7 @@ class TemplateExecutor:
self.executor_output = {'target_path': None,
'stdout': None,
'stderr': None,
'warning': None}
'warnings': []}
if parameters.append == 'skip':
return self.executor_output
@ -859,7 +858,7 @@ class TemplateExecutor:
template_object.target_path
if template_object.ca_is_missed:
self.executor_output['warning'] = (
self.executor_output['warnings'].append(
"archive file is missed,"
" target file was used instead")
@ -1027,10 +1026,8 @@ class TemplateExecutor:
# Действия, если целевой файл не имеет пользовательских изменений
# или если он исполнительный.
# Парсим текст шаблона используя его формат.
parsed_template = template_format(template_object.template_text,
template_object.template_path,
ignore_comments=True)
if (not parsed_template and template_object.parameters.source
if (not template_object.template_text.strip()
and template_object.parameters.source
and template_object.parameters.append == "replace"
and template_object.parameters.format == "raw"):
# Если шаблон пуст, параметром source задан входной файл,
@ -1042,6 +1039,10 @@ class TemplateExecutor:
chown=chown,
chmod=chmod)
elif not template_object.format_class.EXECUTABLE:
parsed_template = template_format(
template_object.template_text,
template_object.template_path,
ignore_comments=True)
# Действия для шаблонов не являющихся исполнительными.
output_paths = [output_path]
@ -1090,10 +1091,14 @@ class TemplateExecutor:
# если это необходимо.
if chown:
self._chown_file(save_path, chown)
if chmod:
self._chmod_file(save_path, chmod)
elif template_object.format_class.EXECUTABLE:
parsed_template = template_format(
template_object.template_text,
template_object.template_path,
template_object.parameters,
self.datavars_module)
changed_files = parsed_template.execute_format(
template_object.target_path,
chroot_path=self.chroot_path)
@ -1102,7 +1107,6 @@ class TemplateExecutor:
# Если исполняемый формат выдал список измененных файлов для
# изменения CONTENTS и при этом задан пакет -- обновляем
# CONTENTS.
for file_path, status in changed_files.items():
if status == 'M':
if file_path in self.changed_files:
@ -1119,6 +1123,12 @@ class TemplateExecutor:
else:
self.changed_files[file_path] = 'D'
# Если в ходе работы формат выкидывал предупреждения --
# добавляем их в список предупреждений.
if parsed_template.warnings:
self.executor_output['warnings'].extend(
parsed_template.warnings)
if (self.dbpkg and changed_files and
template_object.target_package and
template_object.format_class.FORMAT != 'contents'):
@ -2853,8 +2863,8 @@ class DirectoryProcessor:
parameters: ParametersContainer) -> str:
'''Метод для получения пути к целевому файлу с учетом наличия
параметров name, path и append = skip.'''
# Если есть параметр name -- меняем имя шаблона.
if parameters.name:
# Если есть непустой параметр name -- меняем имя шаблона.
if parameters.name is not False and parameters.name != '':
template_name = parameters.name
# Если для шаблона задан путь -- меняем путь к директории шаблона.
@ -2924,8 +2934,11 @@ class DirectoryProcessor:
if output['target_path'] is not None:
target_path = output['target_path']
if output['warning'] is not None:
self.output.set_warning(f"{output['warning']}."
if output['warnings']:
if not isinstance(output['warnings'], list):
output['warnings'] = [output['warnings']]
for warning in output['warnings']:
self.output.set_warning(f"{warning}."
f" Template: {template_path}")
# Если есть вывод от параметра run -- выводим как info.

@ -1,6 +1,7 @@
# vim: fileencoding=utf-8
#
from subprocess import Popen, PIPE, STDOUT
from typing import Union, List
from io import TextIOWrapper
from os import path
from .tools import GenericFS, get_traceback_caller
@ -248,9 +249,9 @@ class ProgramPathCache:
'''Класс, для поиска и кэширования путей к исполнительным файлам различных
команд.'''
def __init__(self):
self._cache = {}
self._cache: dict = {}
def __call__(self, program_name, prefix='/'):
def __call__(self, program_name: str, prefix: str = '/'):
program_base_name = path.basename(program_name)
PATH = os.environ['PATH']
PATH = PATH.split(':')
@ -274,7 +275,7 @@ class ProgramPathCache:
get_program_path = ProgramPathCache()
def check_command(*utils):
def check_command(*utils: List[str]):
'''Функция для проверки наличия той или иной команды системе.'''
output = []
for util in utils:
@ -289,7 +290,7 @@ def check_command(*utils):
return output
def join_paths(*paths):
def join_paths(*paths: List[str]) -> str:
'''Функция для объединения путей. Объединяет также абсолютные пути.'''
if len(paths) == 1:
return next(iter(paths))
@ -307,7 +308,7 @@ def join_paths(*paths):
return output_path
def read_link(file_path):
def read_link(file_path: str) -> str:
'''Функция для получения целевого пути символьной ссылки.'''
try:
if path.exists(file_path):
@ -321,7 +322,8 @@ def read_link(file_path):
format(str(error), mod, lineno))
def get_target_from_link(link_path, link_source, chroot_path='/'):
def get_target_from_link(link_path: str, link_source: str,
chroot_path: str = '/') -> str:
'''Метод для получения целевого пути из целевого пути символьной ссылки
с учетом того, что целевой путь символьной ссылки может быть
относительным.'''
@ -342,11 +344,11 @@ def get_target_from_link(link_path, link_source, chroot_path='/'):
return '/'.join(link_dir)
def read_file(file_path):
def read_file(file_path: str, binary: bool = False) -> Union[str, bytes]:
'''Функция для чтения файлов, возвращает текст файла.'''
try:
if path.exists(file_path):
with open(file_path, 'r') as opened_file:
with open(file_path, f'r{"b" if binary else ""}') as opened_file:
return opened_file.read()
except (OSError, IOError) as error:
mod, lineno = get_traceback_caller(*sys.exc_info())

@ -1,92 +1,135 @@
import os
import hashlib
from calculate.utils.files import Process, write_file, read_file
# import hashlib
from calculate.utils.files import Process, join_paths
from calculate.templates.format.base_format import FormatError
from typing import NoReturn, Union, List, Tuple, Optional
class ImageMagickError(Exception):
class ImageMagickError(FormatError):
pass
class ImageMagick:
def __init__(self, prefix='/'):
self.prefix = prefix
self.init_commands(prefix)
self.default_opts = []
def __init__(self, chroot: str = '/'):
self._chroot_path: str = chroot
self.init_commands(chroot)
self.default_opts: List[str] = []
@property
def available(self):
return self.convert_cmd and self.identify_cmd
def available(self) -> bool:
return bool(self.convert_cmd and self.identify_cmd)
@property
def chroot(self):
return self.prefix != '/'
def init_commands(self, prefix):
self.convert_cmd = "/usr/bin/convert"
self.identify_cmd = "/usr/bin/identify"
self.chroot_cmd = "/bin/chroot"
self.bash_cmd = "/bin/bash"
if not os.path.exists(os.path.join(prefix, self.convert_cmd[1:])):
def chrooted(self) -> bool:
return self._chroot_path != '/'
def init_commands(self, chroot: str) -> NoReturn:
self.convert_cmd: str = "/usr/bin/convert"
self.identify_cmd: str = "/usr/bin/identify"
self.chroot_cmd: str = "/bin/chroot"
self.bash_cmd: str = "/bin/bash"
if not os.path.exists(join_paths(chroot, self.convert_cmd)):
self.convert_cmd = None
if not os.path.exists(os.path.join(prefix, self.identify_cmd[1:])):
if not os.path.exists(join_paths(chroot, self.identify_cmd)):
self.identify_cmd = None
def trim_prefix_path(self, filename):
retpath = "/%s" % os.path.relpath(filename, self.prefix)
def trim_prefix_path(self, filename: str) -> Union[str, None]:
retpath = "/{}".format(os.path.relpath(filename, self._chroot_path))
if retpath.startswith("/.."):
return None
return retpath
def get_image_resolution(self, source):
if self.chroot:
identify = Process(self.chroot_cmd, self.prefix,
def get_image_resolution(self, source: str
) -> Union[None, Tuple[int, int]]:
'''Метод для получения разрешения указанного изображения,
с помощью команды 'identify -format %w %h <path_to_image>'.'''
print(f"SOURCE: {source}")
if self.chrooted:
print(f"CHROOT_PATH: {self._chroot_path}")
identify = Process(self.chroot_cmd, self._chroot_path,
self.bash_cmd, "-c",
" ".join([self.identify_cmd,
"-format '%w %h'", source]))
else:
identify = Process(self.identify_cmd, "-format", "%w %h", source)
if identify.success():
swidth, _sep, sheight = identify.read().strip().partition(" ")
result = identify.read()
swidth, sheight = result.split(" ")
if swidth.isdigit() and sheight.isdigit():
return int(swidth), int(sheight)
return None
else:
raise ImageMagickError(f"ERROR: can not parse: '{result}'")
else:
raise ImageMagickError(f"ERROR: {identify.read_error()}")
def convert(self, source, target, *opts):
def convert(self, source: str, target: str, *opts: List[str],
image_format: Optional[str] = None) -> bool:
command = [self.convert_cmd, "-quality", "95",
source]
command.extend(self.default_opts)
command.extend(opts)
if image_format is not None:
command.append(f"{image_format}:{target}")
else:
command.append(target)
if self.chroot:
convert = Process(self.chroot_cmd, self.prefix,
if self.chrooted:
convert = Process(self.chroot_cmd, self._chroot_path,
self.bash_cmd, "-c",
" ".join(command))
else:
print("OPTIONS:")
print(command)
convert = Process(*command)
if convert.success():
print("CREATED: {}".format(target))
return True
else:
print(convert.read_error())
print("ERROR:", convert.read_error())
return False
def convert_resize_crop_center(self, source, target, height, width):
#if ((width == self.source_width and height == self.source_height) and
def convert_resize_crop_center(self, source: str, target: str,
height: int, width: int,
image_format: Optional[str] = None) -> bool:
# if ((width == self.source_width and height == self.source_height) and
# (source.rpartition('.')[2] == target.rpartition('.')[2])):
# with write_file(target) as sf:
# sf.write(read_file(source))
# return True
res = "%dx%d" % (width, height)
res = f"{width}x{height}"
return self.convert(source, target, "-quality", "95",
"-resize", "%s^" % res,
"-resize", f"{res}^",
"-strip", "-gravity", "center",
"-crop", "%s+0+0" % res)
def convert_resize_gfxboot(self, source, target, height, width):
res = "%dx%d" % (width, height)
"-crop", f"{res}+0+0",
image_format=image_format)
def convert_resize_gfxboot(self, source: str, target: str,
height: int, width: int,
image_format: Optional[str] = None) -> bool:
res = f"{width}x{height}"
return self.convert(source, target, "-quality", "95",
"-resize", "%s^" % res,
"-resize", f"{res}^",
"-strip", "-gravity", "center",
"-crop", "%s+0+0" % res,
"-crop", f"{res}+0+0",
"-sampling-factor", "2x2",
"-interlace", "none",
"-set", "units", "PixelsPerSecond")
"-set", "units", "PixelsPerSecond",
image_format=image_format)
def get_image_format(self, source: str) -> str:
"""Метод для получения формата указанного файла."""
if self.chrooted:
identify = Process(self.chroot_cmd, self._chroot_path,
self.bash_cmd, "-c",
" ".join([self.identify_cmd,
"-format '%m'", source]))
else:
identify = Process(self.identify_cmd, "-format", "%m", source)
if identify.success():
image_format = identify.read()
return image_format
else:
raise ImageMagickError(f"ERROR: {identify.read_error()}")

@ -1032,7 +1032,7 @@ class Package(metaclass=PackageCreator):
if file_md5 is None:
try:
file_text = read_file(real_path).encode()
file_text = read_file(real_path, binary=True)
except FilesError as error:
raise PackageError(str(error))
file_md5 = hashlib.md5(file_text).hexdigest()

@ -1,6 +1,14 @@
from calculate.variables.datavars import (Variable, Namespace, Dependence,
StringType, BooleanType, HashType,
ListType, Calculate, Copy)
from calculate.variables.datavars import (
Variable,
Namespace,
Dependence,
StringType,
BooleanType,
HashType,
ListType,
Calculate,
Copy
)
from calculate.vars.main.os.func import get_arch_gentoo
from calculate.vars.install.os.func import (get_audio_selected,
get_available_audio_system)
@ -10,6 +18,7 @@ def import_variables():
with Namespace("arch"):
Variable("machine", type=StringType,
source=Copy("main.os.arch.machine"))
Variable("gentoo", type=StringType,
source=Calculate(get_arch_gentoo, ".machine"))
@ -17,6 +26,7 @@ def import_variables():
Variable("available", type=ListType,
source=Calculate(
get_available_audio_system))
Variable("selected", type=StringType,
source=Calculate(
get_audio_selected,
@ -26,12 +36,24 @@ def import_variables():
Variable("subsystem", type=StringType, source=Copy("main.os.subsystem"))
with Namespace("container"):
Variable("type", type=StringType, source=Copy("main.os.container.type"))
Variable("type", type=StringType,
source=Copy("main.os.container.type"))
with Namespace("linux"):
Variable("shortname", type=StringType, source=Copy("main.os.linux.shortname"))
Variable("name", type=StringType, source=Copy("main.os.linux.name"))
Variable("subname", type=StringType, source=Copy("main.os.linux.subname"))
Variable("system", type=StringType, source=Copy("main.os.linux.system"))
Variable("ver", type=StringType, source=Copy("main.os.linux.ver"))
Variable("build", type=StringType, source=Copy("main.os.linux.build"))
Variable("shortname", type=StringType,
source=Copy("main.os.linux.shortname"))
Variable("name", type=StringType,
source=Copy("main.os.linux.name"))
Variable("subname", type=StringType,
source=Copy("main.os.linux.subname"))
Variable("system", type=StringType,
source=Copy("main.os.linux.system"))
Variable("ver", type=StringType,
source=Copy("main.os.linux.ver"))
Variable("build", type=StringType,
source=Copy("main.os.linux.build"))

@ -1,5 +1,6 @@
from calculate.utils.package import PackageAtomParser
def get_available_audio_system():
audio_systems = (
('alsa', None),
@ -12,6 +13,7 @@ def get_available_audio_system():
if pkg is None or package_db.is_package_exists(pkg)
]
def get_audio_selected(available_systems, cmdline_audio):
available_systems = available_systems.value

@ -26,3 +26,12 @@ Variable('cl_config_archive', type=StringType.readonly,
Variable('cl_exec_dir_path', type=StringType.readonly,
source='/var/lib/calculate/.execute')
Variable('cl_resolutions', type=ListType.readonly,
source=["1680x1050", "1024x768"])
Variable('cl_resolutions', type=ListType.readonly,
source=["1680x1050", "1024x768"])
Variable('cl_image_formats', type=ListType.readonly,
source=["GIF", "JPG", "JPEG", "PNG", "GFXBOOT"])

@ -9,6 +9,7 @@ from calculate.variables.datavars import (
Calculate
)
def get_ebuild_phase():
return os.environ.get("EBUILD_PHASE", "")
@ -105,9 +106,9 @@ def get_isoscan_fullpath(base_path, filename):
def import_variables():
Variable("chroot_path", type=StringType,
source=Calculate(lambda x:x.value, "main.cl_chroot_path"))
source=Calculate(lambda x: x.value, "main.cl_chroot_path"))
Variable("root_path", type=StringType,
source=Calculate(lambda x:x.value, "main.cl_root_path"))
source=Calculate(lambda x: x.value, "main.cl_root_path"))
Variable("ebuild_phase", type=StringType,
source=Calculate(get_ebuild_phase))

@ -1,4 +1,3 @@
import os
from calculate.utils.fs import readFile
from calculate.variables.datavars import Variable, Namespace, Dependence, \
@ -6,6 +5,7 @@ from calculate.variables.datavars import Variable, Namespace, Dependence, \
from calculate.utils.files import Process, FilesError
import re
def get_resolution_by_xdpyinfo():
"""
Get resolution by xdpyinfo utility
@ -23,13 +23,17 @@ def get_resolution_by_xdpyinfo():
return "%sx%s" % (searchRes.group(1), searchRes.group(2))
return ""
def get_resolution_by_xorg():
pass
def get_standart_resolution():
# TODO: заглушка
return "1024x768"
with Namespace('resolution'):
def import_variables():
with Namespace('resolution'):
Variable("standard", type=StringType,
source=Calculate(get_standart_resolution))

@ -7,14 +7,17 @@ from calculate.variables.datavars import (
TableType
)
def get_repository_table():
return [
{'name':'gentoo',
'url': 'git://git.calculate-linux.org/calculate/gentoo-overlay.git'},
{'name':'calculate',
'url': 'git://git.calculate-linux.org/calculate/calculate-overlay.git'},
return [{'name': 'gentoo',
'url':
'git://git.calculate-linux.org/calculate/gentoo-overlay.git'},
{'name': 'calculate',
'url':
'git://git.calculate-linux.org/calculate/calculate-overlay.git'},
]
def import_variables():
Variable('repositories', type=TableType,
source=Calculate(get_repository_table))

@ -163,18 +163,46 @@ def DictionariesWithoutSections():
return (OriginalDictionary, TemplateDictionary, ResultDictionary)
import pytest
def pytest_addoption(parser):
parser.addoption(
"--chroot-test", action="store_true", default=False, help="run chroot tests"
"--chroot-test",
action="store_true",
default=False,
help="run chroot tests"
)
parser.addoption(
"--backgrounds-slow",
action="store_true",
default=False,
help="run slow backgrounds tests."
)
parser.addoption(
"--from-root",
action="store_true",
default=False,
help="run tests that needs root rights."
)
def pytest_collection_modifyitems(config, items):
if config.getoption("--chroot-test"):
return
skip_chroot = pytest.mark.skip(reason="need --chroot option to run")
if not config.getoption("--chroot-test"):
skip_chroot = pytest.mark.skip(
reason="need --chroot-test option to run")
for item in items:
if "chroot" in item.keywords:
item.add_marker(skip_chroot)
if not config.getoption("--backgrounds-slow"):
skip_backgrounds = pytest.mark.skip(
reason="need --backgrounds-slow option to run")
for item in items:
if "backgrounds_slow" in item.keywords:
item.add_marker(skip_backgrounds)
if not config.getoption("--from-root"):
skip_from_root = pytest.mark.skip(
reason="need --from-root option to run")
for item in items:
if "needs_root" in item.keywords:
item.add_marker(skip_from_root)

@ -3,6 +3,8 @@
[pytest]
markers =
base: marker for running tests for base format class.
backgrounds: marker for running tests for backgrounds format.
backgrounds_slow: marker for running slow tests for backgrounds format.
bind: marker for running tests for bind format.
compiz: marker for running tests for compiz format.
contents: marker for running tests for contents format.
@ -44,3 +46,4 @@ markers =
server: marker for testing of the server.
chroot: marker for testing running by chroot
needs_root: marker for tests that needs root rights.

@ -0,0 +1,331 @@
import os
import pytest
import shutil
from calculate.templates.format.base_format import FormatError
from calculate.templates.format.backgrounds_format import BackgroundsFormat
from calculate.templates.template_engine import ParametersContainer
from calculate.variables.datavars import NamespaceNode, VariableNode, ListType
datavars = NamespaceNode("<root>")
datavars.add_namespace(NamespaceNode("main"))
VariableNode("cl_resolutions", datavars.main, ListType,
source=["1024x768"])
TMP_BACKUP_DIR = 'tests/templates/format/testfiles/backgrounds/tmp.backup'
TMP_DIR = 'tests/templates/format/testfiles/backgrounds/tmp'
@pytest.mark.backgrounds
def test_make_tmp_dir():
if not os.path.exists(TMP_DIR):
shutil.copytree(TMP_BACKUP_DIR, TMP_DIR)
@pytest.mark.backgrounds
@pytest.mark.parametrize('case', [
{
"id": "PNG -> PNG",
"source":
'tests/templates/format/testfiles/backgrounds/picture_0.png',
"convert": False,
"stretch": True,
"target": 'result_0-',
"template_text": ("original\n1024x768"),
"result": ("PNG", ["32x16", "1024x768"]),
},
{
"id": "JPEG -> JPEG",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": False,
"stretch": True,
"target": 'result_1-',
"template_text": ("original\n1024x768"),
"result": ("JPEG", ["320x180", "1024x768"]),
},
{
"id": "PNG -> JPEG",
"source":
'tests/templates/format/testfiles/backgrounds/picture_0.png',
"convert": "JPEG",
"stretch": True,
"target": "result_2-",
"template_text": ("320x160\n1024x768"),
"result": ("JPEG", ["320x160", "1024x768"]),
},
{
"id": "PNG -> GIF",
"source":
'tests/templates/format/testfiles/backgrounds/picture_0.png',
"convert": "GIF",
"stretch": True,
"target": "result_3-",
"template_text": ("320x160\n1024x768"),
"result": ("GIF", ["320x160", "1024x768"]),
},
pytest.param(
{
"id": "JPEG -> PNG",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": "PNG",
"stretch": True,
"target": "result_4-",
"template_text": ("640x360\n1024x768"),
"result": ("PNG", ["640x360", "1024x768"]),
},
marks=pytest.mark.backgrounds_slow
),
{
"id": "JPEG -> GIF",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": "GIF",
"stretch": True,
"target": "result_5-",
"template_text": ("original\n1024x768"),
"result": ("GIF", ["320x180", "1024x768"]),
},
{
"id": "JPEG -> GFXBOOT(JPEG)",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": "GFXBOOT",
"stretch": False,
"target": "result_6-",
"template_text": ("original\n200x100"),
"result": ("JPEG", ["320x180", "200x100"]),
},
{
"id": "PNG -> JPEG (single from template)",
"source":
'tests/templates/format/testfiles/backgrounds/picture_0.png',
"convert": "JPEG",
"stretch": True,
"target": "result_7",
"template_text": ("320x160"),
"result": ("JPEG", ["320x160"]),
},
{
"id": "JPEG -> JPEG (single from variable)",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": False,
"stretch": True,
"target": "result_8-",
"template_text": "",
"result": ("JPEG", ["1024x768"]),
},
],
ids=lambda x: x["id"])
def test_resize_and_convert_of_different_formats(case):
target_path = os.path.join(TMP_DIR, case["target"])
parameters = ParametersContainer({'source': case["source"],
'convert': case["convert"],
'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
images_format, resolutions = case["result"]
output_paths = []
if len(resolutions) > 1 or not case['template_text']:
for resolution in resolutions:
output_paths.append("{}{}.{}".format(target_path, resolution,
images_format.lower()))
elif len(resolutions) == 1:
resolution = next(iter(resolutions))
output_paths.append(target_path)
for outpath in output_paths:
assert os.path.exists(outpath)
assert backgrounds_object._magician.get_image_format(outpath
) == images_format
# print("CHANGED FILES:")
# for path, status in changed_files.items():
# print(f"{path} -> {status}")
# assert False
@pytest.mark.backgrounds
@pytest.mark.parametrize('case', [
{
"id": "stretch off",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": False,
"stretch": False,
"target": 'result_8-',
"template_text": ("400x200\n30x10"),
"result": {"400x200": False, "30x10": True},
},
{
"id": "stretch on",
"source":
'tests/templates/format/testfiles/backgrounds/picture_1.jpg',
"convert": False,
"stretch": True,
"target": 'result_9-',
"template_text": ("400x200\n30x10"),
"result": {"400x200": True, "30x10": True},
},
],
ids=lambda x: x["id"])
def test_scretch_parameter(case):
target_path = os.path.join(TMP_DIR, case["target"])
parameters = ParametersContainer({'source': case["source"],
'convert': case["convert"],
'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
for resolution, result in case["result"].items():
image_path = "{}{}.jpeg".format(target_path, resolution)
assert os.path.exists(image_path) is result
if result:
width, height = resolution.split("x")
assert backgrounds_object._magician.get_image_resolution(
image_path) == (
int(width),
int(height))
# @pytest.mark.backgrounds
# def test_to_create():
# target_path = os.path.join(TMP_BACKUP_DIR, "result_13-")
# source_path = 'tests/templates/format/testfiles/backgrounds/picture_2.png'
# parameters = ParametersContainer({'source': source_path,
# 'convert': False,
# 'stretch': False})
# backgrounds_object = BackgroundsFormat("1650x1050\n1024x768",
# "path/to/template",
# parameters, datavars)
# backgrounds_object.execute_format(target_path)
@pytest.mark.backgrounds
def test_if_template_has_been_already_used__it_will_not_be_reused():
target_path = os.path.join(TMP_DIR, "result_10-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_2.png'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False})
backgrounds_object = BackgroundsFormat("1650x1050\n1024x768",
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not changed_files
@pytest.mark.backgrounds_slow
@pytest.mark.backgrounds
def test_if_template_is_using_in_directory_but_other_template_has_been_already_used_for_the_same_image_name__latest_template_will_remove_old_images_and_md5sum_file_and_create_new_ones():
target_path = os.path.join(TMP_DIR, "result_11-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_2.png'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.png")
assert os.path.exists(f"{target_path}1440x1080.png")
assert os.path.exists(f"{target_path}1280x960.png")
assert not os.path.exists(f"{target_path}1024x768.png")
assert changed_files == {f"{target_path}1650x1050.png": "D",
f"{target_path}1024x768.png": "D",
f"{target_path.strip('_-.')}.md5sum": "M",
f"{target_path}1440x1080.png": "N",
f"{target_path}1280x960.png": "N"}
@pytest.mark.backgrounds_slow
@pytest.mark.backgrounds
def test_if_template_is_using_in_directory_which_contains_md5sum_file_without_any_images__the_template_will_remove_md5sum_file_and_create_new_one_and_images():
target_path = os.path.join(TMP_DIR, "result_12-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_2.png'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert os.path.exists(f"{target_path}1440x1080.png")
assert os.path.exists(f"{target_path}1280x960.png")
assert changed_files == {f"{target_path.strip('_-.')}.md5sum": "M",
f"{target_path}1440x1080.png": "N",
f"{target_path}1280x960.png": "N"}
@pytest.mark.backgrounds_slow
@pytest.mark.backgrounds
def test_if_template_is_using_in_directory_which_contains_some_image_files_without_md5sum_file__the_template_will_remove_all_images_and_create_new_ones_and_new_md5sum_file():
target_path = os.path.join(TMP_DIR, "result_13-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_2.png'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.png")
assert os.path.exists(f"{target_path}1440x1080.png")
assert os.path.exists(f"{target_path}1280x960.png")
assert not os.path.exists(f"{target_path}1024x768.png")
assert changed_files == {f"{target_path}1650x1050.png": "D",
f"{target_path}1024x768.png": "D",
f"{target_path.strip('_-.')}.md5sum": "N",
f"{target_path}1440x1080.png": "N",
f"{target_path}1280x960.png": "N"}
@pytest.mark.backgrounds
def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_two_or_more_resolution_values__the_output_files_name_will_contains_its_resolutions_only():
target_path = os.path.join(TMP_DIR, "result_14-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_1.jpg'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False,
'name': ''})
backgrounds_object = BackgroundsFormat("100x100\n60x60",
"path/to/template",
parameters, datavars)
backgrounds_object.execute_format(target_path)
assert os.path.exists(os.path.join(TMP_DIR, "100x100.jpeg"))
assert os.path.exists(os.path.join(TMP_DIR, "60x60.jpeg"))
assert os.path.exists(os.path.join(TMP_DIR, "md5sum"))
@pytest.mark.backgrounds
def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_one_resolution_value__the_format_will_raise_FormatError_exception():
target_path = os.path.join(TMP_DIR, "result_15-")
source_path = 'tests/templates/format/testfiles/backgrounds/picture_1.jpg'
parameters = ParametersContainer({'source': source_path,
'convert': False,
'stretch': False,
'name': ''})
backgrounds_object = BackgroundsFormat("100x100",
"path/to/template",
parameters, datavars)
with pytest.raises(FormatError):
backgrounds_object.execute_format(target_path)
@pytest.mark.backgrounds
def test_remove_tmp():
if os.path.exists(TMP_DIR):
shutil.rmtree(TMP_DIR)

@ -3,6 +3,8 @@ import pytest
import shutil
from calculate.templates.format.contents_format import ContentsFormat
from calculate.utils.package import PackageAtomName, Version, Package
from calculate.templates.template_engine import ParametersContainer
from calculate.variables.datavars import NamespaceNode
from calculate.utils.files import join_paths
@ -54,7 +56,9 @@ sym /etc/dir_3/link_0 -> ../dir_1/file_0 {2}
int(os.lstat(join_paths(chroot_path,
'/etc/dir_3/link_0')).st_mtime))
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name,
@ -101,7 +105,9 @@ dir /etc/dir_1
dir /etc/dir_3
'''
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name,
@ -177,7 +183,9 @@ dir /etc/dir_5
sym /etc/dir_5/link_0 -> ../dir_1/file_0 1601991426
'''
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name,

@ -1,6 +1,8 @@
import pytest
import shutil
from calculate.templates.format.patch_format import PatchFormat
from calculate.templates.template_engine import ParametersContainer
from calculate.variables.datavars import NamespaceNode
from calculate.utils.files import Process
from os import path
import os
@ -31,7 +33,9 @@ class TestExecuteMethods:
with open(path.join(cwd_path, 'diff_1.patch')) as patch_file:
patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path')
diff_patch = PatchFormat(patch_text, '/template/path',
ParametersContainer(),
NamespaceNode("<root>"))
output = diff_patch.execute_format(target_path=cwd_path)
if output:
for changed_file, change_type in diff_patch.changed_files.items():
@ -62,7 +66,9 @@ class TestExecuteMethods:
with open(path.join(patch_path)) as patch_file:
patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path')
diff_patch = PatchFormat(patch_text, '/template/path',
ParametersContainer(),
NamespaceNode("<root>"))
diff_patch.execute_format(target_path=cwd_path)
for changed_file, change_type in diff_patch.changed_files.items():

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

@ -82,7 +82,10 @@ main = Variables({'cl_template_path':
'cl_config_path': CONFIG_PATH,
'cl_config_archive': CONFIG_ARCHIVE_PATH,
'cl_exec_dir_path': EXECUTE_ARCHIVE_PATH,
'cl_ignore_files': '*.swp',
'cl_ignore_files': '*.swp,*.swo',
'cl_image_formats': ["JPEG", "PNG", "GIF", "JPG"],
'cl_resolutions': ['200x150'],
'fake_chroot': True,
'os': vars_os})
test = Variables({'test_root': CHROOT_PATH})
@ -95,6 +98,7 @@ datavars = Variables({'install': install,
'custom': Variables()})
@pytest.mark.directory_processor
def show_tree(dir_path: str, indent: int = 0,
test_names: Optional[List[str]] = None,
check_cfg: bool = False) -> None:
@ -130,8 +134,7 @@ def show_tree(dir_path: str, indent: int = 0,
@pytest.mark.directory_processor
class TestDirectoryProcessor:
def test_create_testfiles(self):
def test_create_testfiles():
TemplateWrapper._protected_is_set = False
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
@ -142,7 +145,9 @@ class TestDirectoryProcessor:
symlinks=True)
PackageCreator.clear_instances()
def test_if_templates_consist_only_one_directory_with_a_single_calculate_directory_file_with_the_append_skip_parameter__the_directory_processor_does_nothing(self):
@pytest.mark.directory_processor
def test_if_templates_consist_only_one_directory_with_a_single_calculate_directory_file_with_the_append_skip_parameter__the_directory_processor_does_nothing():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_0')
directory_processor = DirectoryProcessor('install',
@ -152,7 +157,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_1')
directory_processor = DirectoryProcessor('install',
@ -186,7 +193,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_2')
directory_processor = DirectoryProcessor('install',
@ -198,7 +207,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_4')
if not os.path.exists(os.path.join(CHROOT_PATH,
@ -214,7 +225,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_3')
directory_processor = DirectoryProcessor('install',
@ -253,7 +266,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_5')
directory_processor = DirectoryProcessor('install',
@ -319,7 +334,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_6')
directory_processor = DirectoryProcessor('install',
@ -359,7 +376,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_7')
directory_processor = DirectoryProcessor('install',
@ -400,7 +419,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_8')
directory_processor = DirectoryProcessor('install',
@ -442,7 +463,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_9')
directory_processor = DirectoryProcessor('install',
@ -483,7 +506,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_10')
directory_processor = DirectoryProcessor('install',
@ -576,7 +601,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_11')
io_module = IOModule(save_messages=True)
@ -594,7 +621,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_12')
io_module = IOModule(save_messages=True)
@ -617,7 +646,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_13')
directory_processor = DirectoryProcessor('install',
@ -629,7 +660,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_14')
directory_processor = DirectoryProcessor('install',
@ -659,7 +692,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_15')
error_message = ("Template execution error: collision: 'package' "
@ -686,7 +721,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_16')
@ -706,7 +743,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_17')
directory_processor = DirectoryProcessor('install',
@ -734,7 +773,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_18')
directory_processor = DirectoryProcessor('install',
@ -766,7 +807,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_19')
directory_processor = DirectoryProcessor('install',
@ -794,7 +837,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_20')
directory_processor = DirectoryProcessor('install',
@ -826,7 +871,9 @@ class TestDirectoryProcessor:
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_files_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):
@pytest.mark.directory_processor
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_files_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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_21')
directory_processor = DirectoryProcessor('install',
@ -871,7 +918,9 @@ class TestDirectoryProcessor:
'/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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_22')
directory_processor = DirectoryProcessor(
@ -917,7 +966,9 @@ class TestDirectoryProcessor:
'/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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_23')
directory_processor = DirectoryProcessor(
@ -963,7 +1014,9 @@ class TestDirectoryProcessor:
'/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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_24')
directory_processor = DirectoryProcessor('install',
@ -979,7 +1032,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_25')
directory_processor = DirectoryProcessor('install',
@ -994,7 +1049,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_26')
directory_processor = DirectoryProcessor('install',
@ -1016,7 +1073,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_27')
directory_processor = DirectoryProcessor('install',
@ -1037,7 +1096,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_28')
cfg_path_1 = os.path.join(CHROOT_PATH, 'etc/._cfg0000_file_12')
@ -1061,7 +1122,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_29')
directory_processor = DirectoryProcessor('install',
@ -1076,7 +1139,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_30')
directory_processor = DirectoryProcessor('install',
@ -1089,7 +1154,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
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():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_31')
directory_processor = DirectoryProcessor('install',
@ -1118,7 +1185,9 @@ class TestDirectoryProcessor:
join_paths(CHROOT_PATH,
'/etc/file_17'): 'N'}
def test_multiple_actions(self):
@pytest.mark.directory_processor
def test_multiple_actions():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_32')
directory_processor = DirectoryProcessor(['install', 'update'],
@ -1149,7 +1218,9 @@ class TestDirectoryProcessor:
join_paths(CHROOT_PATH,
'/etc/dir_33/file_0'): 'N'}
def test_None_package(self):
@pytest.mark.directory_processor
def test_None_package():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_33')
directory_processor = DirectoryProcessor(['install', 'update'],
@ -1170,7 +1241,9 @@ class TestDirectoryProcessor:
join_paths(CHROOT_PATH,
'/etc/dir_35/file_0'): 'N'}
def test_handlers_basic(self):
@pytest.mark.directory_processor
def test_handlers_basic():
try:
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_35')
@ -1268,7 +1341,9 @@ class TestDirectoryProcessor:
except KeyboardInterrupt:
assert False
def test_merge_order(self):
@pytest.mark.directory_processor
def test_merge_order():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_36')
directory_processor = DirectoryProcessor(
@ -1296,7 +1371,9 @@ class TestDirectoryProcessor:
assert directory_processor.template_executor.\
changed_files == {}
def test_group_parameter_without_merge(self):
@pytest.mark.directory_processor
def test_group_parameter_without_merge():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_37')
directory_processor = DirectoryProcessor(
@ -1328,7 +1405,9 @@ class TestDirectoryProcessor:
'etc/dir_51/file_0'): 'N'}
datavars.main.cl['groups'] = Variables({})
def test_group_parameter_with_merge_parameter(self):
@pytest.mark.directory_processor
def test_group_parameter_with_merge_parameter():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_38')
directory_processor = DirectoryProcessor(
@ -1359,7 +1438,9 @@ class TestDirectoryProcessor:
'etc/dir_56/file_0'): 'N'}
datavars.main.cl['groups'] = Variables({})
def test_solving_collisions_for_the_same_packages_from_different_slots(self):
@pytest.mark.directory_processor
def test_solving_collisions_for_the_same_packages_from_different_slots():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_39')
directory_processor = DirectoryProcessor(
@ -1402,7 +1483,9 @@ class TestDirectoryProcessor:
assert '/etc/dir_57/file_0' in test_package_1
assert '/etc/dir_57/file_0' not in test_package_0
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_package_parameter(self):
@pytest.mark.directory_processor
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_package_parameter():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_40')
directory_processor = DirectoryProcessor(
@ -1445,7 +1528,9 @@ class TestDirectoryProcessor:
assert '/etc/dir_58/file_0' in test_package_1
assert '/etc/dir_58/file_0' not in test_package_0
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_for_package_parameter(self):
@pytest.mark.directory_processor
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_for_package_parameter():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_41')
directory_processor = DirectoryProcessor(
@ -1490,7 +1575,9 @@ class TestDirectoryProcessor:
assert '/etc/dir_59/file_0' in test_package_1
assert '/etc/dir_59/file_0' not in test_package_0
def test_copy_file_using_source(self):
@pytest.mark.directory_processor
def test_copy_file_using_source():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_42')
directory_processor = DirectoryProcessor(
@ -1501,7 +1588,9 @@ 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):
@pytest.mark.directory_processor
def test_default_raw_and_append_replace():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_43')
directory_processor = DirectoryProcessor(
@ -1514,7 +1603,9 @@ class TestDirectoryProcessor:
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):
@pytest.mark.directory_processor
def test_default_raw_and_append_replace_contents_not_matching():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_44')
directory_processor = DirectoryProcessor(
@ -1536,7 +1627,9 @@ class TestDirectoryProcessor:
new_text = new_file.read()
assert new_text == 'new content\n'
def test_current_template_variable(self):
@pytest.mark.directory_processor
def test_current_template_variable():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_45')
template_path = join_paths(CHROOT_PATH,
@ -1559,7 +1652,9 @@ class TestDirectoryProcessor:
output_text = output_file.read()
assert output_text == expected_output
def test_ignoring_files_in_templates_base_directory(self):
@pytest.mark.directory_processor
def test_ignoring_files_in_templates_base_directory():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_46')
directory_processor = DirectoryProcessor(
@ -1570,7 +1665,9 @@ class TestDirectoryProcessor:
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_63/file_0'))
def test_using_excepting_action_values(self):
@pytest.mark.directory_processor
def test_using_excepting_action_values():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_47')
directory_processor = DirectoryProcessor(
@ -1581,7 +1678,9 @@ 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):
@pytest.mark.directory_processor
def test_warning_while_merge():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_48')
io = IOModule(save_messages=True)
@ -1598,7 +1697,9 @@ class TestDirectoryProcessor:
"Warning: package 'test-category/new-package-0.1.1'"
" not found for action 'install'.")
def test_group_and_package_parameter_for_unexisting_package(self):
@pytest.mark.directory_processor
def test_group_and_package_parameter_for_unexisting_package():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_49')
directory_processor = DirectoryProcessor(
@ -1609,7 +1710,9 @@ class TestDirectoryProcessor:
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_67/file_0'))
def test_group_and_some_templates_ignored(self):
@pytest.mark.directory_processor
def test_group_and_some_templates_ignored():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_50')
directory_processor = DirectoryProcessor(
@ -1622,7 +1725,9 @@ class TestDirectoryProcessor:
assert not os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_69/file_0'))
def test_group_with_NonePackage(self):
@pytest.mark.directory_processor
def test_group_with_NonePackage():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_51')
directory_processor = DirectoryProcessor(
@ -1639,7 +1744,9 @@ class TestDirectoryProcessor:
assert not os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_72/file_0'))
def test_merge_parameter_with_unexisting_packages(self):
@pytest.mark.directory_processor
def test_merge_parameter_with_unexisting_packages():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_52')
directory_processor = DirectoryProcessor(
@ -1651,7 +1758,9 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_73/file_0'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_74/file_0'))
def test_to_solve_bug_with_patch_template(self):
@pytest.mark.directory_processor
def test_to_solve_bug_with_patch_template():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_53')
io = IOModule(save_messages=True)
@ -1673,7 +1782,9 @@ class TestDirectoryProcessor:
"Format execution error: correction failed. Template:"
f" {join_paths(CHROOT_PATH, 'templates_53/install/patch')}")
def test_templates_with_append_link_force_and_source_paths_to_an_unexisting_file_or_directory(self):
@pytest.mark.directory_processor
def test_templates_with_append_link_force_and_source_paths_to_an_unexisting_file_or_directory():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_54')
directory_processor = DirectoryProcessor('install',
@ -1683,7 +1794,9 @@ class TestDirectoryProcessor:
assert os.path.lexists(join_paths(CHROOT_PATH, '/etc/link_0'))
assert os.path.lexists(join_paths(CHROOT_PATH, '/etc/link_1'))
def test_using_directory_template_to_an_link_to_directory(self):
@pytest.mark.directory_processor
def test_using_directory_template_to_an_link_to_directory():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_55')
directory_processor = DirectoryProcessor('install',
@ -1697,7 +1810,9 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/link_3/file_0'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/link_3/file_1'))
def test_check_permissions_after_using_template_when_CONTENTS_file_contains_target_file_path_and_hash_sum_is_correct(self):
@pytest.mark.directory_processor
def test_check_permissions_after_using_template_when_CONTENTS_file_contains_target_file_path_and_hash_sum_is_correct():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_56')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_19')).st_mode
@ -1716,7 +1831,9 @@ class TestDirectoryProcessor:
assert target_text == ("Eluveitie -- Inis Mona\n"
"Eluveitie -- Uis Elveti\n")
def test_check_permissions_after_using_template_when_CONTENTS_file_does_not_contain_target_file_path(self):
@pytest.mark.directory_processor
def test_check_permissions_after_using_template_when_CONTENTS_file_does_not_contain_target_file_path():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_57')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_20')).st_mode
@ -1737,7 +1854,9 @@ class TestDirectoryProcessor:
assert target_text == ("amenra -- solitary reign\n"
"agalloch -- falling snow\n")
def test_changing_permissions_of_a_directory_using_template(self):
@pytest.mark.directory_processor
def test_changing_permissions_of_a_directory_using_template():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_58')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/dir_76')).st_mode
@ -1758,8 +1877,12 @@ class TestDirectoryProcessor:
"Eluveitie -- Your gaulish war\n")
assert oct(mode) == "0o40770"
def test_changing_owner_of_a_directory_using_template(self):
if os.getuid() == 0:
@pytest.mark.needs_root
@pytest.mark.directory_processor
def test_changing_owner_of_a_directory_using_template():
assert os.getuid() == 0, "Need superuser privileges"
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_59')
stat = os.stat(join_paths(CHROOT_PATH, '/etc/dir_77'))
@ -1781,8 +1904,12 @@ class TestDirectoryProcessor:
"Eluveitie -- Siraxta\n")
assert (stat.st_uid, stat.st_gid) == (0, 0)
def test_different_symbol_chmod_values_for_dirs_and_files(self):
if os.getuid() == 0:
@pytest.mark.needs_root
@pytest.mark.directory_processor
def test_different_symbol_chmod_values_for_dirs_and_files():
assert os.getuid() == 0, "Need superuser privileges"
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_60')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/dir_78')).st_mode
@ -1816,8 +1943,12 @@ class TestDirectoryProcessor:
'/etc/dir_78/file_1')).st_mode
assert int(mode) == 0o100655
def test_saving_permissions_after_file_replace(self):
if os.getuid() == 0:
@pytest.mark.needs_root
@pytest.mark.directory_processor
def test_saving_permissions_after_file_replace():
assert os.getuid() == 0, "Need superuser privileges"
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_62')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode
@ -1836,7 +1967,9 @@ class TestDirectoryProcessor:
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode
assert int(mode) == 0o100645
def test_using_file_templates_from_base_directory(self):
@pytest.mark.directory_processor
def test_using_file_templates_from_base_directory():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_61')
@ -1848,7 +1981,9 @@ class TestDirectoryProcessor:
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_21'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_22'))
def test_autoupdate_for_symlink(self):
@pytest.mark.directory_processor
def test_autoupdate_for_symlink():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_63')
@ -1859,7 +1994,9 @@ class TestDirectoryProcessor:
assert os.path.lexists(join_paths(CHROOT_PATH,
'/etc/._cfg0000_link_5'))
def test_for_debug_packages_error(self):
@pytest.mark.directory_processor
def test_for_debug_packages_error():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_64')
@ -1877,7 +2014,9 @@ class TestDirectoryProcessor:
assert '/etc/file_26' in vim_pkg
assert '/etc/file_26' not in vim_core_pkg
def test_to_solve_bug_with_xml_templates(self):
@pytest.mark.directory_processor
def test_to_solve_bug_with_xml_templates():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_65')
@ -1886,16 +2025,90 @@ class TestDirectoryProcessor:
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_27.xml'))
with open (join_paths(CHROOT_PATH, '/etc/file_27.xml'), 'r') as result:
with open(join_paths(CHROOT_PATH, '/etc/file_27.xml'), 'r') as result:
result_text = result.read()
print("RESULT TEXT:")
print(result_text)
with open (join_paths(CHROOT_PATH, '/etc/file_28.xml'), 'r') as result:
with open(join_paths(CHROOT_PATH, '/etc/file_28.xml'), 'r') as result:
expected_text = result.read()
assert result_text == expected_text
def test_view_tree(self):
@pytest.mark.directory_processor
def test_backgrounds_format():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_66')
directory_processor = DirectoryProcessor('install',
datavars_module=datavars,
)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_79'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_79/image-320x180.jpeg'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_79/image-300x100.jpeg'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_79/image.md5sum'))
pkg = Package(test_package_name_1, chroot_path=CHROOT_PATH)
assert '/etc/dir_79/image-320x180.jpeg' in pkg
assert '/etc/dir_79/image-300x100.jpeg' in pkg
assert '/etc/dir_79/image.md5sum' in pkg
@pytest.mark.directory_processor
def test_backgrounds_format_with_replacement():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_67')
directory_processor = DirectoryProcessor('install',
datavars_module=datavars,
dbpkg=False)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_80'))
assert not os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_80/image-320x180.jpeg'))
assert not os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_80/image-300x100.jpeg'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_80/image-666x333.jpeg'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_80/image-220x130.jpeg'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_80/image.md5sum'))
@pytest.mark.directory_processor
def test_backgrounds_format_with_single_resolution():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_68')
directory_processor = DirectoryProcessor('install',
datavars_module=datavars,
dbpkg=False)
directory_processor.process_template_directories()
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_81'))
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_81/image.png'))
assert os.path.exists(join_paths(CHROOT_PATH,
'/etc/dir_81/image.png.md5sum'))
@pytest.mark.directory_processor
def test_backgrounds_format_making_no_changes():
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_69')
directory_processor = DirectoryProcessor('install',
datavars_module=datavars,
dbpkg=False)
changed_files = directory_processor.process_template_directories()
assert changed_files == {}
@pytest.mark.directory_processor
def test_view_tree():
list_path = join_paths(CHROOT_PATH, '/etc')
test_names = ['dir', 'file', 'link']
last_names = show_tree(list_path,
@ -1908,6 +2121,8 @@ class TestDirectoryProcessor:
last_names)]))
assert True
def test_for_removing_testfile(self):
@pytest.mark.directory_processor
def test_for_removing_testfile():
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
shutil.rmtree(os.path.join(CHROOT_PATH, 'var'))

File diff suppressed because it is too large Load Diff

@ -23,8 +23,7 @@ test_package_name = PackageAtomName(
@pytest.mark.template_wrapper
class TestTemplateWrapper:
def test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths(self):
def test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -50,9 +49,13 @@ class TestTemplateWrapper:
mask_set.add(join_paths(CHROOT_PATH, path))
assert template_wrapper._unprotected_set == mask_set
# Тестируем проверку типов шаблонов и файлов и поиск конфликтов.
# Тесты типов.
def test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None(self):
# Тестируем проверку типов шаблонов и файлов и поиск конфликтов.
# Тесты типов.
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -67,7 +70,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir/none')
def test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_DIR__the_TemplateWrapper_target_type_is_DIR():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
template_wrapper = TemplateWrapper(
@ -81,7 +86,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir/dir_2')
def test_if_template_type_is_FILE_and_target_file_is_FILE__the_TemplateWrapper_target_type_is_FILE(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_and_target_file_is_FILE__the_TemplateWrapper_target_type_is_FILE():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -96,9 +103,12 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf')
# Тесты проверки конфликтов.
# Если шаблон -- файл.
def test_if_template_type_is_FILE_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_FILE_and_target_path_is_same(self):
# Тесты проверки конфликтов.
# Если шаблон -- файл.
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_FILE_and_target_path_is_same():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -114,7 +124,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf')
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -127,7 +139,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_FILE_but_target_file_is_a_link_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_but_target_file_is_a_link_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -140,7 +154,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_but_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -158,7 +174,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -176,7 +194,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_but_target_file_is_a_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -193,8 +213,11 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/file')
# Если шаблон -- директория.
def test_if_template_type_is_DIR_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_DIR_and_target_path_is_the_same(self):
# Если шаблон -- директория.
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_target_type_is_DIR_and_target_path_is_the_same():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'force': True})
@ -209,7 +232,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir/dir_2')
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_changes_its_target_path_to_the_link_source_file():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
@ -225,7 +250,8 @@ class TestTemplateWrapper:
'/etc/dir/dir_2')
def test_if_template_type_is_DIR_but_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_but_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -238,7 +264,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_file_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_a_link_to_a_file_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -251,7 +279,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'force': True})
@ -268,7 +298,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'force': True})
@ -285,7 +317,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_and_target_file_is_the_link_to_a_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'force': True})
@ -302,8 +336,12 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
# Если шаблон создает ссылку.
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag(self):
# Если шаблон создает ссылку.
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
try:
@ -319,7 +357,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -331,7 +371,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_FILE__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -343,7 +385,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_the_link_to_a_DIR__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
try:
@ -359,7 +403,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -371,7 +417,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -383,7 +431,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -395,7 +445,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_not_set__the_TemplateWrapper_throws_TemplateTypeConflict_exception():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link'})
with pytest.raises(TemplateTypeConflict):
@ -407,7 +459,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'force': True})
@ -424,7 +478,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_FILE_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'force': True})
@ -441,7 +497,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_FILE_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'force': True})
@ -458,7 +516,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag(self):
@pytest.mark.template_wrapper
def test_if_template_type_is_DIR_with_the_append_link_parameter_and_target_file_is_DIR_and_force_parameter_is_set__the_TemplateWrapper_sets_remove_original_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'force': True})
@ -475,8 +535,10 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
# Тестируем определитель пакетов и проверку на коллизии.
def test_if_template_contains_append_parameters_but_does_not_have_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_throws_TemplateCollisionError_exception(self):
# Тестируем определитель пакетов и проверку на коллизии.
@pytest.mark.template_wrapper
def test_if_template_contains_append_parameters_but_does_not_have_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_throws_TemplateCollisionError_exception():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
with pytest.raises(TemplateCollisionError):
@ -488,7 +550,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_template_contains_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_uses_package_from_parameter_and_sets_target_without_package_flag(self):
@pytest.mark.template_wrapper
def test_if_template_contains_package_parameter_and_target_file_does_not_belong_to_any_package__the_TemplateWrapper_uses_package_from_parameter_and_sets_target_without_package_flag():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -505,7 +569,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_without_package
def test_if_template_does_not_have_package_parameter_but_target_file_belongs_to_the_package__the_TemplateWrapper_uses_package_from_parameter(self):
@pytest.mark.template_wrapper
def test_if_template_does_not_have_package_parameter_but_target_file_belongs_to_the_package__the_TemplateWrapper_uses_package_from_parameter():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -522,7 +588,9 @@ class TestTemplateWrapper:
assert not template_wrapper.target_without_package
assert template_wrapper.target_package_name == test_package_name
def test_if_template_contains_package_parameter_and_target_file_belongs_to_the_package_from_package_parameter__the_TemplateWrapper_uses_package_from_them(self):
@pytest.mark.template_wrapper
def test_if_template_contains_package_parameter_and_target_file_belongs_to_the_package_from_package_parameter__the_TemplateWrapper_uses_package_from_them():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -539,7 +607,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_package_name == test_package_name
def test_if_template_contains_package_parameter_but_target_file_belongs_to_the_other_package__the_TemplateWrapper_throws_TemplateCollisionError(self):
@pytest.mark.template_wrapper
def test_if_template_contains_package_parameter_but_target_file_belongs_to_the_other_package__the_TemplateWrapper_throws_TemplateCollisionError():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -552,7 +622,9 @@ class TestTemplateWrapper:
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_TemplateWrapper_object_contains_package_value__the_wrapper_can_use_Package_object_for_changing_CONTENTS_file_of_the_package(self):
@pytest.mark.template_wrapper
def test_if_TemplateWrapper_object_contains_package_value__the_wrapper_can_use_Package_object_for_changing_CONTENTS_file_of_the_package():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -568,9 +640,13 @@ class TestTemplateWrapper:
assert '/etc/dir/file.conf' in template_wrapper.target_package
# Тестируем проверку наличия пользовательских изменений.
# Сначала вспомогательные функции.
def test_if_a_target_file_directory_contains_no_cfg_files_but_it_is_necessary_to_create_one__the_first_cfg_file_should_be_named_cfg0001_file(self):
# Тестируем проверку наличия пользовательских изменений.
# Сначала вспомогательные функции.
@pytest.mark.template_wrapper
def test_if_a_target_file_directory_contains_no_cfg_files_but_it_is_necessary_to_create_one__the_first_cfg_file_should_be_named_cfg0001_file():
parameters_object = ParametersContainer({'append': 'join',
'format': 'bind'})
try:
@ -587,7 +663,9 @@ class TestTemplateWrapper:
cfg_name = template_wrapper._get_cfg_path(template_wrapper.target_path)
assert cfg_name == join_paths(CHROOT_PATH, '/etc/dir_0/._cfg0000_file')
def test_if_a_target_file_directory_contains_some_cfg_files_including_the_first_one__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_directory_contains_some_cfg_files_including_the_first_one__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one():
parameters_object = ParametersContainer({'append': 'bind'})
try:
template_wrapper = TemplateWrapper(
@ -605,7 +683,9 @@ class TestTemplateWrapper:
'/etc/dir_1/file'))
assert cfg_name == join_paths(CHROOT_PATH, '/etc/dir_1/._cfg0003_file')
def test_if_a_target_file_directory_contains_some_cfg_files_but_some_of_them_are_missed__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_directory_contains_some_cfg_files_but_some_of_them_are_missed__the_next_cfg_file_should_be_named_with_the_number_following_the_number_of_the_last_one():
parameters_object = ParametersContainer({'append': 'bind'})
try:
template_wrapper = TemplateWrapper(
@ -623,7 +703,9 @@ class TestTemplateWrapper:
'/etc/dir_2/file'))
assert cfg_name == join_paths(CHROOT_PATH, '/etc/dir_2/._cfg0003_file')
def test_if_get_archive_path_method_has_the_file_path_as_its_argument__it_returns_the_path_to_the_archive_version_of_the_input_file(self):
@pytest.mark.template_wrapper
def test_if_get_archive_path_method_has_the_file_path_as_its_argument__it_returns_the_path_to_the_archive_version_of_the_input_file():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -641,8 +723,11 @@ class TestTemplateWrapper:
CONFIG_ARCHIVE_PATH,
'/etc/dir/file.conf')
# Тестируем результат установки флага protected.
def test_if_a_target_file_is_located_in_a_protected_directory__the_TemplateWrapper_object_sets_the_protected_flag_as_True(self):
# Тестируем результат установки флага protected.
@pytest.mark.template_wrapper
def test_if_a_target_file_is_located_in_a_protected_directory__the_TemplateWrapper_object_sets_the_protected_flag_as_True():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -657,7 +742,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.protected
def test_if_a_target_file_is_located_in_a_directory_that_is_not_protected__the_TemplateWrapper_object_sets_the_protected_flag_as_False(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_is_located_in_a_directory_that_is_not_protected__the_TemplateWrapper_object_sets_the_protected_flag_as_False():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -672,7 +759,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.protected
def test_if_a_target_file_is_located_in_a_directory_from_the_protected_mask__the_TemplateWrapper_object_sets_the_protected_flag_as_False(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_is_located_in_a_directory_from_the_protected_mask__the_TemplateWrapper_object_sets_the_protected_flag_as_False():
if os.environ.get('CONFIG_PROTECT', False):
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
@ -694,8 +783,12 @@ class TestTemplateWrapper:
assert not template_wrapper.protected
# Тестируем проверку хэш-сумм и флаг получаемый в результате нее.
def test_if_a_target_file_is_not_protected__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
# Тестируем проверку хэш-сумм и флаг получаемый в результате нее.
@pytest.mark.template_wrapper
def test_if_a_target_file_is_not_protected__the_TemplateWrapper_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'})
try:
@ -710,7 +803,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.contents_matching
def test_if_a_template_contains_the_unbound_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
@pytest.mark.template_wrapper
def test_if_a_template_contains_the_unbound_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba',
'unbound': True})
@ -726,7 +821,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.contents_matching
def test_if_a_target_file_does_not_exist_and_CONTENTS_file_of_the_file_s_package_does_not_contain_this_file__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_does_not_exist_and_CONTENTS_file_of_the_file_s_package_does_not_contain_this_file__the_TemplateWrapper_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'json'})
@ -742,7 +839,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.contents_matching
def test_if_a_target_file_was_deleted_by_a_user__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_was_deleted_by_a_user__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'json'})
@ -758,7 +857,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.contents_matching
def test_if_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'json'})
@ -774,7 +875,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.contents_matching
def test_if_a_template_contains_the_autoupdate_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
@pytest.mark.template_wrapper
def test_if_a_template_contains_the_autoupdate_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'append': 'join',
'format': 'samba',
'autoupdate': True})
@ -790,7 +893,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.contents_matching
def test_if_a_template_contains_the_autoupdate_parameter_and_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
@pytest.mark.template_wrapper
def test_if_a_template_contains_the_autoupdate_parameter_and_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -808,7 +913,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_without_package
assert template_wrapper.contents_matching
def test_if_a_target_file_s_hash_matches_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_True(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_s_hash_matches_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_True():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'json'})
@ -824,7 +931,9 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.contents_matching
def test_if_a_target_file_s_hash_does_not_match_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
@pytest.mark.template_wrapper
def test_if_a_target_file_s_hash_does_not_match_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False():
parameters_object = ParametersContainer({'append': 'join',
'format': 'json'})
try:
@ -839,9 +948,13 @@ class TestTemplateWrapper:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.contents_matching
# Тестируем вывод путей к входному и выходному файлам исполнительного
# модуля.
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_does_not_contain_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self):
# Тестируем вывод путей к входному и выходному файлам исполнительного
# модуля.
@pytest.mark.template_wrapper
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_does_not_contain_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'json'})
@ -860,7 +973,9 @@ class TestTemplateWrapper:
assert template_wrapper.output_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf')
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_does_not_contain_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self):
@pytest.mark.template_wrapper
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_does_not_contain_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path():
parameters_object = ParametersContainer({'append': 'join',
'format': 'json'})
try:
@ -879,7 +994,9 @@ class TestTemplateWrapper:
CHROOT_PATH,
'/etc/dir_0/._cfg0000_file')
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self):
@pytest.mark.template_wrapper
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path():
source = join_paths(CHROOT_PATH, '/etc/file')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
@ -899,7 +1016,9 @@ class TestTemplateWrapper:
assert template_wrapper.output_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf')
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_contains_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self):
@pytest.mark.template_wrapper
def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_contains_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path():
source = join_paths(CHROOT_PATH, '/etc/file')
parameters_object = ParametersContainer({'append': 'join',
'format': 'json',
@ -921,25 +1040,30 @@ class TestTemplateWrapper:
CHROOT_PATH,
'/etc/dir_0/._cfg0000_file')
# Тестируем поведение, если формат исполняемый.
def test_if_a_target_path_is_FILE_and_a_template_is_executable__the_target_path_is_replaced_with_the_path_to_the_cwd_directory_and_there_is_no_package_type_conflicts_and_other_checks(self):
parameters_object = ParametersContainer({'append': 'join',
'format': 'patch'})
try:
template_wrapper = TemplateWrapper(
join_paths(CHROOT_PATH,
'/etc/dir/file.conf'),
parameters_object, FILE,
'/path/to/template',
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.target_path == join_paths(CHROOT_PATH,
'/etc/dir')
assert template_wrapper.target_package is None
# Тестируем поведение, если формат исполняемый.
# @pytest.mark.template_wrapper
# def test_if_a_target_path_is_FILE_and_a_template_is_executable__the_target_path_is_replaced_with_the_path_to_the_cwd_directory_and_there_is_no_package_type_conflicts_and_other_checks():
# parameters_object = ParametersContainer({'append': 'join',
# 'format': 'patch'})
# try:
# template_wrapper = TemplateWrapper(
# join_paths(CHROOT_PATH,
# '/etc/dir/file.conf'),
# parameters_object, FILE,
# '/path/to/template',
# chroot_path=CHROOT_PATH,
# config_archive_path=CONFIG_ARCHIVE_PATH)
# except Exception as error:
# pytest.fail("Unexpected exception: {}".format(str(error)))
# assert template_wrapper.target_path == join_paths(CHROOT_PATH,
# '/etc/dir')
# assert template_wrapper.target_package is None
def test_if_a_target_path_is_DIR_and_a_template_is_executable__the_target_path_is_the_same_and_there_is_no_package_type_conflicts_and_other_checks(self):
@pytest.mark.template_wrapper
def test_if_a_target_path_is_DIR_and_a_template_is_executable__the_target_path_is_the_same_and_there_is_no_package_type_conflicts_and_other_checks():
parameters_object = ParametersContainer({'append': 'join',
'format': 'patch'})
try:
@ -956,7 +1080,9 @@ class TestTemplateWrapper:
'/etc/dir')
assert template_wrapper.target_package is None
def test_if_a_template_is_executable_and_contains_package_parameter__the_template_updates_the_CONTENTS_file_for_package_from_parameter(self):
@pytest.mark.template_wrapper
def test_if_a_template_is_executable_and_contains_package_parameter__the_template_updates_the_CONTENTS_file_for_package_from_parameter():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'patch'})
@ -974,8 +1100,12 @@ class TestTemplateWrapper:
'/etc/dir/')
assert template_wrapper.target_package_name == test_package_name
# Тестируем работу с CONTENTS через объект обертки.
def test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_and_hash_will_be_calculated_automatically(self):
# Тестируем работу с CONTENTS через объект обертки.
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_and_hash_will_be_calculated_automatically():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -993,7 +1123,9 @@ class TestTemplateWrapper:
template_wrapper.add_to_contents()
assert '/etc/file' in template_wrapper.target_package
def test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_with_specified_hash(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized_as_FILE__the_object_can_be_used_for_an_adding_the_current_file_to_its_package_with_specified_hash():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -1013,7 +1145,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_package.\
contents_dictionary['/etc/file']['md5'] == '666'
def test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_a_removing_current_file_from_its_package(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_a_removing_current_file_from_its_package():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba'})
@ -1031,7 +1165,9 @@ class TestTemplateWrapper:
template_wrapper.remove_from_contents()
assert '/etc/dir/file.conf' not in template_wrapper.target_package
def test_if_a_TemplateWrapper_object_successfully_initialized_as_DIR__the_object_can_be_used_for_a_removing_current_directory_and_all_its_contents_from_its_package(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized_as_DIR__the_object_can_be_used_for_a_removing_current_directory_and_all_its_contents_from_its_package():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join'})
try:
@ -1052,7 +1188,9 @@ class TestTemplateWrapper:
assert '/etc/dir/file.conf' not in template_wrapper.target_package
assert '/etc/dir' not in template_wrapper.target_package
def test_if_a_TemplateWrapper_object_successfully_initialized_with_DIR_type__the_object_can_be_used_for_a_removing_all_directory_files_from_its_package(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized_with_DIR_type__the_object_can_be_used_for_a_removing_all_directory_files_from_its_package():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
try:
@ -1073,7 +1211,9 @@ class TestTemplateWrapper:
assert '/etc/dir/file.conf' not in template_wrapper.target_package
assert '/etc/dir' in template_wrapper.target_package
def test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_changing_CONTENTS_using_list_of_changed_files(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_object_successfully_initialized__the_object_can_be_used_for_changing_CONTENTS_using_list_of_changed_files():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'patch'})
@ -1106,7 +1246,9 @@ class TestTemplateWrapper:
assert template_wrapper.target_package.\
contents_dictionary['/etc/dir/subdir/file']['md5'] == new_md5
def test_if_a_TemplateWrapper_was_used_to_change_CONTENTS__it_should_be_saved_using_save_changes_method(self):
@pytest.mark.template_wrapper
def test_if_a_TemplateWrapper_was_used_to_change_CONTENTS__it_should_be_saved_using_save_changes_method():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -1167,7 +1309,9 @@ class TestTemplateWrapper:
assert '/etc/dir/file.conf' in template_wrapper.target_package
assert '/etc/file' not in template_wrapper.target_package
def test_if_after_removing_some_files_thought_TemplateWrapper_some_directories_become_empty__empty_directories_will_be_removed_saving_changes(self):
@pytest.mark.template_wrapper
def test_if_after_removing_some_files_thought_TemplateWrapper_some_directories_become_empty__empty_directories_will_be_removed_saving_changes():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -1199,23 +1343,29 @@ class TestTemplateWrapper:
assert '/etc/dir/dir_1' in template_wrapper.\
target_package
# Тестируем особенности поведения при различных значениях параметров.
# def test_if_mirror_parameter_is_set_and_target_file_does_not_exist__a_TemplateWrapper_object_throws_TemplateExecutorError(self):
# source = join_paths(CHROOT_PATH, '/etc/file')
# parameters_object = ParametersContainer({'package': test_package_name,
# 'append': 'join',
# 'format': 'bind',
# 'source': source,
# 'mirror': True})
# with pytest.raises(TemplateExecutorError):
# TemplateWrapper(join_paths(CHROOT_PATH, '/etc/dir/none'),
# parameters_object, FILE,
# '/path/to/template',
# chroot_path=CHROOT_PATH,
# config_archive_path=CONFIG_ARCHIVE_PATH)
def test_if_mirror_parameter_is_set_and_file_from_the_source_parameter_does_not_exist__a_TemplateWrapper_object_sets_remove_original_flag_as_True(self):
# Тестируем особенности поведения при различных значениях параметров.
# @pytest.mark.template_wrapper
# def test_if_mirror_parameter_is_set_and_target_file_does_not_exist__a_TemplateWrapper_object_throws_TemplateExecutorError():
# source = join_paths(CHROOT_PATH, '/etc/file')
# parameters_object = ParametersContainer({'package': test_package_name,
# 'append': 'join',
# 'format': 'bind',
# 'source': source,
# 'mirror': True})
#
# with pytest.raises(TemplateExecutorError):
# TemplateWrapper(join_paths(CHROOT_PATH, '/etc/dir/none'),
# parameters_object, FILE,
# '/path/to/template',
# chroot_path=CHROOT_PATH,
# config_archive_path=CONFIG_ARCHIVE_PATH)
@pytest.mark.template_wrapper
def test_if_mirror_parameter_is_set_and_file_from_the_source_parameter_does_not_exist__a_TemplateWrapper_object_sets_remove_original_flag_as_True():
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'samba',
@ -1238,7 +1388,9 @@ class TestTemplateWrapper:
assert template_wrapper.remove_original
def test_if_run_parameter_is_set_for_template__no_checks_are_carried_out_while_a_TemplateWrapper_object_initialization(self):
@pytest.mark.template_wrapper
def test_if_run_parameter_is_set_for_template__no_checks_are_carried_out_while_a_TemplateWrapper_object_initialization():
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
try:
@ -1254,7 +1406,9 @@ class TestTemplateWrapper:
assert template_wrapper.parameters.run == '/usr/bin/python'
def test_if_exec_parameter_is_set_for_template__no_checks_are_carried_out_while_a_TemplateWrapper_object_initialization(self):
@pytest.mark.template_wrapper
def test_if_exec_parameter_is_set_for_template__no_checks_are_carried_out_while_a_TemplateWrapper_object_initialization():
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
try:

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

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

@ -0,0 +1,3 @@
{% calculate format = "backgrounds", source = "/etc/picture.jpg", name = "image-" %}
original
300x100

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

@ -0,0 +1,4 @@
{% calculate format = "backgrounds", source = "/etc/picture.jpg", name = "image-",
stretch %}
666x333
220x130

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

@ -0,0 +1,3 @@
{% calculate format = "backgrounds", source = "/etc/picture.jpg", name = "image.png",
stretch, convert = "png" %}
300x200

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

@ -0,0 +1,4 @@
{% calculate format = "backgrounds", source = "/etc/picture.jpg", name = "image-",
stretch %}
original
300x100

@ -3,20 +3,20 @@ from calculate.utils.images import ImageMagick, ImageMagickError
import os
from calculate.utils.files import Process
@pytest.mark.images_utils
def test_imagemagick_initialization():
im = ImageMagick()
assert im.available
assert not im.chroot
assert not im.chrooted
im = ImageMagick(prefix='/mnt/somepath')
im = ImageMagick(chroot='/mnt/somepath')
assert not im.available
assert im.chroot
assert im.chrooted
@pytest.mark.images_utils
@pytest.mark.parametrize('case',
[
@pytest.mark.parametrize('case', [
{
"name": "simple path",
"chroot": "/mnt/install",
@ -42,23 +42,23 @@ def test_imagemagick_initialization():
"result": None,
},
],
ids=lambda x:x["name"])
ids=lambda x: x["name"])
def test_imagemagick_trim_prefix_path(case):
im = ImageMagick(case['chroot'])
assert im.trim_prefix_path(case["source"]) == case["result"]
@pytest.mark.images_utils
@pytest.mark.parametrize('case',
[
@pytest.mark.parametrize('case', [
{
"name": "PNG file",
"image": "tests/utils/testfiles/file.png",
"result": (48,48),
"result": (48, 48),
},
{
"name": "JPEG file",
"image": "tests/utils/testfiles/file.jpg",
"result": (320,180),
"result": (320, 180),
},
{
"name": "No file",
@ -71,11 +71,49 @@ def test_imagemagick_trim_prefix_path(case):
"result": None,
},
],
ids=lambda x:x["name"])
ids=lambda x: x["name"])
def test_imagemagick_get_resolutions(case):
im = ImageMagick()
if case["result"] is None:
with pytest.raises(ImageMagickError):
im.get_image_resolution(case["image"])
else:
assert im.get_image_resolution(case["image"]) == case["result"]
@pytest.mark.images_utils
@pytest.mark.parametrize('case', [
{
"name": "PNG file",
"image": "tests/utils/testfiles/file.png",
"result": "PNG",
},
{
"name": "JPEG file",
"image": "tests/utils/testfiles/file.jpg",
"result": "JPEG",
},
{
"name": "No file",
"image": "tests/utils/testfiles/file2.jpg",
"result": None,
},
{
"name": "Wrong file",
"image": "tests/utils/testfiles/wrong.jpg",
"result": None,
},
],
ids=lambda x: x["name"])
def test_imagemagick_get_image_format(case):
im = ImageMagick()
if case["result"] is None:
with pytest.raises(ImageMagickError):
im.get_image_format(case["image"])
else:
assert im.get_image_format(case["image"]) == case["result"]
@pytest.fixture
def chroot_test():
chrootpath = "/mnt/testchroot"
@ -88,29 +126,37 @@ def chroot_test():
finally:
os.unlink(chrootpath)
@pytest.mark.chroot
@pytest.mark.images_utils
def test_chroot_imagemagick_get_resolution(chroot_test):
im = ImageMagick(chroot_test)
curpath = os.getcwd()
image_path = os.path.join(curpath, "tests/utils/testfiles/file.png")
assert im.get_image_resolution(image_path) == (48,48)
assert im.get_image_resolution(image_path) == (48, 48)
def get_histogram(image, remap_image):
p = Process("/usr/bin/convert", image, "-remap", remap_image, "-format", "%c", "histogram:info:-")
p = Process("/usr/bin/convert", image, "-remap",
remap_image, "-format", "%c", "histogram:info:-")
return p.read()
def get_verbose_image_info(image):
p = Process("/usr/bin/identify", "-verbose", image)
return p.read()
def discard_space(x: str) -> str:
return x.replace(" ", "").replace("\n", "")
@pytest.mark.images_utils
@pytest.mark.parametrize('case',
[
@pytest.mark.parametrize('case', [
{
# проверка, пропорционального уменьшения
"name": "Origin test",
"resize": (16,32),
"resize": (16, 32),
"result": """192: (0,0,0) #000000 black
64: (0,255,0) #00FF00 lime
256: (255,255,255) #FFFFFF white"""
@ -120,22 +166,23 @@ def get_verbose_image_info(image):
# удаляются только части изображения справа и слева
# в исходном изображении на этих частях находится белый фон
"name": "Shrink horizontal",
"resize": (16,16),
"resize": (16, 16),
"result": """192: (0,0,0) #000000 black
64: (0,255,0) #00FF00 lime"""
},
{
# проверка, что при уменьшении изображения первоначально оно сдавливается
# по вертикали а затем обрезаются части слева и справа
# проверка, что при уменьшении изображения первоначально оно
# сдавливается # по вертикали а затем обрезаются части слева и
# справа
"name": "Shrink all",
"resize": (8,8),
"resize": (8, 8),
"result": """48: (0,0,0) #000000 black
16: (0,255,0) #00FF00 lime"""
},
{
# проверка, пропорционального уменьшения
"name": "Shrink proportionately",
"resize": (8,16),
"resize": (8, 16),
"result": """48: (0,0,0) #000000 black
16: (0,255,0) #00FF00 lime
64: (255,255,255) #FFFFFF white"""
@ -143,7 +190,7 @@ def get_verbose_image_info(image):
{
# проверка, пропорционального увеличения
"name": "Increase size proportionately",
"resize": (32,64),
"resize": (32, 64),
"result": """768: (0,0,0) #000000 black
256: (0,255,0) #00FF00 lime
1024: (255,255,255) #FFFFFF white"""
@ -151,7 +198,7 @@ def get_verbose_image_info(image):
{
# проверка увеличения и обрезки по горизонтали
"name": "Increase size and cut",
"resize": (32,32),
"resize": (32, 32),
"result": """768: (0,0,0) #000000 black
256: (0,255,0) #00FF00 lime"""
},
@ -160,24 +207,27 @@ def get_verbose_image_info(image):
# в этом случае будет отрезан верх и низ
# поэтому на выходе нет зелёного цвета
"name": "Increase horizontal size",
"resize": (16,48),
"resize": (16, 48),
"result": """384: (0,0,0) #000000 gray(0)
384: (255,255,255) #FFFFFF gray(255)"""
},
],
ids=lambda x:x["name"])
ids=lambda x: x["name"])
def test_imagemagick_convert(case):
image_path = "tests/utils/testfiles/origin.png"
output_file = "tests/utils/testfiles/test_output5.png"
if os.path.exists(output_file):
os.unlink(output_file)
im = ImageMagick()
im.default_opts = ["-filter","box"]
assert im.convert_resize_crop_center(image_path, output_file, *case["resize"])
im.default_opts = ["-filter", "box"]
assert im.convert_resize_crop_center(image_path, output_file,
*case["resize"])
histogram = get_histogram(output_file, image_path)
discard_space = lambda x: x.replace(" ","").replace("\n","")
assert discard_space(histogram) == discard_space(case["result"])
@pytest.mark.chroot
@pytest.mark.images_utils
def test_chroot_imagemagick_convert_center(chroot_test):
@ -191,12 +241,15 @@ def test_chroot_imagemagick_convert_center(chroot_test):
if os.path.exists(output_file):
os.unlink(output_file)
im = ImageMagick(chroot_test)
im.default_opts = ["-filter","box"]
im.default_opts = ["-filter", "box"]
assert im.convert_resize_crop_center(image_path, output_file, 8, 8)
histogram = get_histogram(output_file, image_path)
discard_space = lambda x: x.replace(" ","").replace("\n","")
assert discard_space(histogram) == discard_space(result)
@pytest.mark.images_utils
def test_imagemagick_convert_gfxboot():
output_file = "tests/utils/testfiles/test_output.jpg"
@ -205,6 +258,7 @@ def test_imagemagick_convert_gfxboot():
im.convert_resize_gfxboot(image_path, output_file, 32, 32)
assert "sampling-factor: 2x2" in get_verbose_image_info(output_file)
@pytest.mark.images_utils
def test_clear_imagemagick_convert():
for output_file in (

Loading…
Cancel
Save