A number of corrections have been made to the design of the vars code.

packages
Иванов Денис 4 years ago
parent a60ce2317a
commit 5644d8e2c2

@ -69,30 +69,16 @@ class BINDFormat(BaseFormat):
keys = Keyword('keys')
inet = Keyword('inet')
statement = originalTextFor(
Word(alphanums+'_-',
excludeChars='{};')
)
statement_name = originalTextFor(
Word(printables,
excludeChars='{};')
)
statement_class = originalTextFor(
Word(printables,
excludeChars='{};')
)
parameter_value = originalTextFor(
Word(printables,
excludeChars='{};')
)('parameter')
ip_value = originalTextFor(
Word(nums+':./',
excludeChars=';{}')
)
statement = originalTextFor(Word(alphanums+'_-', excludeChars='{};'))
statement_name = originalTextFor(Word(printables, excludeChars='{};'))
statement_class = originalTextFor(Word(printables, excludeChars='{};'))
parameter_value = originalTextFor(Word(printables, excludeChars='{};')
)('parameter')
ip_value = originalTextFor(Word(nums+':./', excludeChars=';{}'))
# Будущий парсер блока.
block = Forward()
@ -122,34 +108,28 @@ class BINDFormat(BaseFormat):
+ Group(allow_group
+ Optional(keys_group)
+ semicolon.suppress())('content')
).setParseAction(
self._add_inet_specline
)
).setParseAction(self._add_inet_specline)
# Для парсинга комментариев.
python_style_comment = originalTextFor(Literal('#') + restOfLine)
comments = (cppStyleComment |
python_style_comment).setParseAction(
self._create_comment_list
)
self._create_comment_list)
# Для парсинга директивы include.
include_line = (Optional(action_symbols, default='')('action')
+ Keyword('include')
+ Word(printables, excludeChars=';{}')
+ Optional(semicolon.suppress())
).setParseAction(
self._add_include_line
)
).setParseAction(self._add_include_line)
# Для парсинга простых директив состоящих из одного
# или двух параметров.
plain_line = (Group(Optional(action_symbols, default='')('action')
+ statement)('name')
+ statement)('name')
+ Optional(parameter_value)
+ Optional(semicolon.suppress())).setParseAction(
self._add_plain_line
)
self._add_plain_line)
# Метод для парсинга IP адресов.
ip_line = (Group(Optional(action_symbols, default='')('action')
@ -164,12 +144,11 @@ class BINDFormat(BaseFormat):
# Парсер блока параметров.
param_block = (Group(Optional(action_symbols, default='')('action')
+ statement + Optional(statement_name)
+ Optional(statement_class))('name')
+ statement + Optional(statement_name)
+ Optional(statement_class))('name')
+ block('content')
+ Optional(semicolon.suppress())).setParseAction(
self._add_param_block
)
self._add_param_block)
# Виды блочных директив.
block_types = (inet_spec | param_block)
@ -180,34 +159,28 @@ class BINDFormat(BaseFormat):
# применение формата после установки флага ignore_comments.
if self._ignore_comments:
param_line_with_comments = (ZeroOrMore(comments).suppress()(
'comments'
)
'comments')
+ param_line('value')
).setParseAction(
self._add_comments_to_paramline
)
self._add_comments_to_paramline)
else:
param_line_with_comments = (ZeroOrMore(comments)('comments')
+ param_line('value')
).setParseAction(
self._add_comments_to_paramline
)
self._add_comments_to_paramline)
# Парсер блока с комментариями.
if self._ignore_comments:
param_block_with_comments = (ZeroOrMore(comments).suppress()(
'comments'
)
'comments')
+ block_types('value')
).setParseAction(
self._add_comments_to_block
)
self._add_comments_to_block)
else:
param_block_with_comments = (ZeroOrMore(comments)('comments')
+ block_types('value')
).setParseAction(
self._add_comments_to_block
)
self._add_comments_to_block)
# Парсер содержимого блоков.
block_item = (param_block_with_comments |

@ -24,6 +24,7 @@ import re
import os
# Наверное временно.
CALCULATE_VERSION = Version('4.0')
@ -75,7 +76,7 @@ class CalculateConfigFile:
"cannot read calculate config file in: {0}. Reason: {1}".
format(self.cl_config_path, str(error)))
# Продумать проверку корректности найденного файла.
# TODO Продумать проверку корректности найденного файла.
for file_line in config_file_lines:
filename, md5_sum = file_line.split(' ')
config_dictionary.update({filename: md5_sum})
@ -207,7 +208,7 @@ class TemplateWrapper:
self.format_class = ParametersProcessor.\
available_formats[self.parameters.format]
else:
# Здесь будет детектор форматов.
# TODO Здесь будет детектор форматов.
pass
# Если по этому пути что-то есть -- проверяем конфликты.
@ -1245,6 +1246,9 @@ class TemplateExecutor:
raise TemplateExecutorError(("can not run template, directory from"
" target path does not exist: {}").
format(template_object.target_path))
elif not os.path.isdir(cwd_path):
raise TemplateExecutorError(("can not exec template, {} is not a"
" directory.").format(cwd_path))
try:
run_process = Process(interpreter, cwd=cwd_path)
@ -1278,12 +1282,13 @@ class TemplateExecutor:
cwd_path = template_object.target_path
if not os.path.exists(cwd_path):
raise TemplateExecutorError(("can not run template, directory from"
" target path does not exist: {}").
format(template_object.target_path))
print('CWD_PATH = {}'.format(cwd_path))
print('TEMPLATE TEXT:')
print(text_to_run)
raise TemplateExecutorError(
("can not exec template, directory from"
" target path does not exist: {}").
format(cwd_path))
elif not os.path.isdir(cwd_path):
raise TemplateExecutorError(("can not exec template, {} is not a"
" directory.").format(cwd_path))
# Получаем путь к директории для хранения файлов .execute.
if (self.chroot_path != '/' and not
@ -1729,6 +1734,8 @@ class DirectoryProcessor:
if self.template_executor.execute_files:
self._run_exec_files()
self.template_executor.save_changes()
def _merge_packages(self):
'''Метод для выполнения шаблонов относящихся к пакетам, указанным во
всех встреченных значениях параметра merge.'''

@ -1,62 +1,74 @@
from pyparsing import (Literal, Word, ZeroOrMore, Group, Dict, Optional,
restOfLine, empty, printables, OneOrMore, oneOf, nums, lineno, line, col,
Keyword, SkipTo, LineEnd, Combine)
from pyparsing import Literal, Word, ZeroOrMore, Group, Dict, Optional,\
restOfLine, empty, printables, OneOrMore, oneOf, nums,\
lineno, line, col, Keyword, SkipTo, LineEnd, Combine
from enum import Enum
class CalculateIniParser:
"""
Парсер формата calculate.ini
"""
'''Класс парсера calculate.ini файлов.'''
class Define(Enum):
Assign = 0
Append = 1
Remove = 2
def __init__(self):
lbrack = Literal("[").suppress()
rbrack = Literal("]").suppress()
comma = Literal(",").suppress()
commentStart = oneOf("; #")
Define = self.Define
valueOp = Literal("=") | Combine(
Literal("+") + Literal("=")) | Combine(
Literal("-") + Literal("="))
comment = commentStart + Optional( restOfLine)
nonrbrack = "".join( [c for c in printables if c != "]" ]) + " \t"
nonvalueop = "".join( [c for c in printables if c not in {"=","-","+"} ]) + " \t"
noncomma = "".join( [c for c in printables if c != "," ])
clearsection = lbrack + Group(empty) + rbrack
sectionDef = Group(OneOrMore(lbrack + Word(nonrbrack) + rbrack)
+ (clearsection | ~lbrack ) + LineEnd().suppress())
unexpected = Group(~sectionDef + SkipTo(LineEnd(), include=True))("error")
lbrack = Literal("[")
rbrack = Literal("]")
# comma = Literal(",").suppress()
comment_symbol = Literal(';') | Literal('#')
# Define = self.Define
value_operation = (Literal("=") | Combine(Literal("+") + Literal("="))
| Combine(Literal("-") + Literal("=")))
comment = comment_symbol + Optional(restOfLine)
section_name = Word(printables+'\t', excludeChars='[]')
value_name = Word(printables+'\t', excludeChars='=-+')
# non_comma = Word(printables+'\t', excludeChars=',')
clear_section = lbrack.suppress() + Group(empty) + rbrack.suppress()
section_start = Group(OneOrMore(lbrack.suppress() + section_name
+ rbrack.suppress())
+ (clear_section | ~lbrack())
+ LineEnd().suppress())
# Если содержимое ini-файла не предваряется заголовком секции,
# значит эта строка ошибочна.
unexpected = Group(~section_start + SkipTo(LineEnd(),
include=True))("error")
unexpected.setParseAction(self._unexpected_token)
keyDef = ~lbrack + Word(nonvalueop) + valueOp + empty + restOfLine + LineEnd().suppress()
key_value = (~lbrack + value_name
+ value_operation + empty
+ restOfLine + LineEnd().suppress())
def stripKeyValue(tokens):
def strip_key_value(tokens):
tokens[0] = tokens[0].strip()
tokens[1] = tokens[1].strip()
keyDef.setParseAction(stripKeyValue)
key_value.setParseAction(strip_key_value)
self.inibnf = sectionDef + Group(ZeroOrMore(Group(keyDef | unexpected))) | unexpected
self.inibnf.ignore( comment )
self.ini_section_parser = (section_start
+ Group(ZeroOrMore(
Group(key_value | unexpected)))
| unexpected)
self.ini_section_parser.ignore(comment)
def _unexpected_token(self, st, locn, tokString):
erline = line(locn,st).strip()
if erline:
self.parseError(erline,
lineno(locn,st),
col(locn,st))
def _unexpected_token(self, string, location, tokens):
'''Метод вызываемый парсером, если обнаружена некорректная строка,
предназначен для получения некорректной строки и ее дальнейшего
разбора.'''
error_line = line(location, string).strip()
if error_line:
self.parseError(error_line, lineno(location, string),
col(location, string))
def parse(self, data):
for tokens,start,end in self.inibnf.scanString(data):
for tokens, start, end in self.ini_section_parser.scanString(data):
if tokens.getName() == "error":
continue
section, defkeys = tokens
@ -69,36 +81,28 @@ class CalculateIniParser:
if defkey.getName() == "error":
continue
mapOp = {"=": self.Define.Assign,
"+=": self.Define.Append,
"-=": self.Define.Remove }
"+=": self.Define.Append,
"-=": self.Define.Remove}
self.defineKey(section.asList(),
defkey[0], defkey[2],
mapOp[defkey[1]])
defkey[0], defkey[2],
mapOp[defkey[1]])
def startSection(self, section):
"""
Начало секции
"""
"""Начало секции"""
pass
def clearSection(self, section):
"""
Очистка значений секции
"""
'''Метод для очистки секций.'''
pass
def defineKey(self, section, defkey, defval, deftype):
"""
Определение ключа
['section','block'] 'varname', 'varval', Define.Assign
"""
'''Метод для определения ключа.
['section','block'], 'varname', 'varval', Define.Assign'''
pass
def parseError(self, line, lineno, col):
"""
Ошибка в формате
line - пример строки
lineno - номер строки
col - номер символа
"""
'''Метод для обработки ошибок, обнаруженных в ini-файле.
line - пример строки;
lineno - номер строки;
col - номер символа.'''
pass

@ -1,49 +1,55 @@
import site
import os
# import site
# import os
import re
import sys
# import sys
import types
import functools
# import functools
from contextlib import contextmanager
_ = lambda x:x
_ = lambda x: x
class BaseClass:
BASE_CLASS = "BaseClass"
@classmethod
def isImplementation(cls, check_class):
"""
Проверить, что класс является производным базового класса, а
не самим базовым, используется в автозагрузке переменных из модулей
"""
'''Метод для проверки того, что класс является производным базового
класса, а не самим базовым. Используется в автозагрузке переменных из
модулей.'''
if isinstance(check_class, type) and issubclass(check_class, cls):
if check_class.BASE_CLASS == cls.BASE_CLASS and \
check_class.__name__ != cls.BASE_CLASS:
check_class.__name__ != cls.BASE_CLASS:
return True
return False
class VariableError(Exception):
pass
class VariableNotFoundError(VariableError):
pass
class CyclicVariableError(VariableError):
def __init__(self, *queue):
self.queue = queue
def __str__(self):
return _("Cyclic dependence in variables: %s") % ", ".join(self.queue[:-1])
return _("Cyclic dependence in variables: {}").format(", ".join(
self.queue[:-1]))
class VariableProperty:
def __init__(self, parent):
self.parent = parent
class StringVariable(VariableProperty):
pass
class ListVariable(VariableProperty):
def setValue(self, value, force=False):
if isinstance(value, (list, tuple)):
@ -58,13 +64,16 @@ class ListVariable(VariableProperty):
def post_get(self, value):
return value
class ReadonlyVariable(VariableProperty):
def setValue(self, value, force=False):
if not force:
raise VariableError(
_("Attempting to rewrite readonly variable %s")%self.parent.name)
_("Attempting to rewrite readonly variable {}").format(
self.parent.name))
return value
class IntegerVariable(VariableProperty):
reMatch = re.compile(r"^-?\d+$")
@ -77,29 +86,31 @@ class IntegerVariable(VariableProperty):
def post_get(self, value):
return int(value)
class BooleanVariable(VariableProperty):
def post_get(self, value):
return value == "true"
class ChoiceVariable(VariableProperty):
def check(self, value):
choices = self.parent.choice()
if value and value not in choices:
raise VariableError(
_("The value for variable '{varname}' may be "
"{vartype}").format(
varname=self.parent.name,
vartype=",".join(choices)))
"{vartype}").format(varname=self.parent.name,
vartype=",".join(choices)))
def choice(self):
if self.parent.__class__.choice == Variable.choice and \
self.parent.__class__.choiceComment == Variable.choiceComment:
raise VariableError(_("Wrong choice variable %s")
% self.parent.name)
raise VariableError(_("Wrong choice variable {}").format(
self.parent.name))
return [x[0] for x in self.parent.choiceComment()]
def choiceComment(self):
return [(x,x) for x in self.parent.choice()]
return [(x, x) for x in self.parent.choice()]
class DefaultValue(VariableProperty):
def __init__(self, value):
@ -111,9 +122,11 @@ class DefaultValue(VariableProperty):
self.parent._unsubscribe_depends()
self.parent._value = self.value
class IniCreated(DefaultValue):
pass
class Variable(BaseClass):
BASE_CLASS = "Variable"
@ -143,7 +156,7 @@ class Variable(BaseClass):
@property
def fullname(self):
return "%s.%s" % (self.vars.getFullname(), self.name)
return "{}.{}".format(self.vars.getFullname(), self.name)
def addProperty(self, prop):
prop.parent = self
@ -165,14 +178,14 @@ class Variable(BaseClass):
dependvar.update_unsubscribe(self.invalidate)
self.depends = set()
def update_subscribe(self, f_or_var):
def update_subscribe(self, f_or_var):
if isinstance(f_or_var, Variable):
f_or_var.depends.add(self)
self.invalidate_subs.add(f_or_var.invalidate)
else:
self.invalidate_subs.add(f_or_var)
def update_unsubscribe(self, f):
def update_unsubscribe(self, f):
if f in self.invalidate_subs:
self.invalidate_subs.remove(f)
@ -236,45 +249,33 @@ class Variable(BaseClass):
self._unsubscribe_depends()
def check(self, value):
"""
Функция проверки значения устанавливаемого значения
"""
'''Метод для проверки значения устанавливаемого значения.'''
for f in self.callProperties("check"):
f(value)
def get(self):
"""
Функция заполнения переменной
"""
'''Метод для заполнения переменной.'''
return self.value
def getCommentValue(self, invalidate_sub=None):
"""
Этот метод вызывается внутри методов get
"""
val = self.getComment()
'''Этот метод вызывается внутри методов get.'''
val = self.getComment()
if invalidate_sub is not None:
self.update_subscribe(invalidate_sub)
return val
return val
def getComment(self):
"""
Комментарий к значению
"""
'''Комментарий к значению.'''
for f in self.callProperties("getComment"):
return f()
return self.getValue()
def set(self, value):
"""
Функция модификации переменной
"""
'''Метод для модификации переменной.'''
return value
def choice(self):
"""
Функция возвращет список доступных значений для переменной
"""
'''Метод возвращет список доступных значений для переменной.'''
for f in self.callProperties("choice"):
return f()
return []
@ -302,7 +303,7 @@ class Namespace(BaseClass):
def getFullname(self):
if self.parent is not self and self.parent.parent is not self.parent:
return "%s.%s" % (self.parent.getFullname(), self._name)
return "{}.{}".format(self.parent.getFullname(), self._name)
else:
return self._name
@ -314,7 +315,8 @@ class Namespace(BaseClass):
else:
raise VariableNotFoundError(
_("Variable or namespace {varname} not found").format(
varname="%s.%s" % (self.getFullname(), name)))
varname="{}.{}".format(self.getFullname(),
name)))
def clearChilds(self):
for child in self.childs.values():
@ -328,16 +330,14 @@ class Namespace(BaseClass):
return getattr(self, str(name)).setValue(value)
def __iter__(self):
"""
Сортировка: вначале числовые ключи потом прочие
"""
'''Сортировка: вначале числовые ключи потом прочие.'''
def sortkey(x):
k,v = x
k, v = x
if k.isdigit():
return (0,int(k),k)
return (0, int(k), k)
else:
return (1,0,k)
for k,v in sorted(self.childs.items(), key=sortkey):
return (1, 0, k)
for k, v in sorted(self.childs.items(), key=sortkey):
yield v
def __contains__(self, name):
@ -373,6 +373,7 @@ class Namespace(BaseClass):
namespace.root = self.root
return namespace
class HashVariable(Namespace):
"""
Переменная представляет собой словарь
@ -381,7 +382,7 @@ class HashVariable(Namespace):
class HashValue(Variable):
BASE_CLASS = "HashValue"
def __init__(self, name, master_variable):
super().__init__(name)
self.parent = None
@ -398,13 +399,15 @@ class HashVariable(Namespace):
class Data(Variable):
BASE_CLASS = "Data"
def getHashValue(self, name, invalidate_sub=None):
return self.getValue(invalidate_sub)[name]
def setHashValue(self, name, value, force):
if name in self.readonly_vars and not force:
raise VariableError(
_("Attempting to rewrite readonly variable %s")%name)
_("Attempting to rewrite readonly variable {}").
format(name))
data = self.getValue().copy()
data[name] = value
self.setValue(data, force)
@ -423,9 +426,8 @@ class HashVariable(Namespace):
self.parent = parent
if not self.hash_vars:
raise VariableError(
_("Missed '{attrname}' attribute for hash variable {varname}"
).format(attrname = "hash_vars",
varname=self.getFullname()))
_("Missed '{attrname}' attribute for hash variable {varname}").
format(attrname="hash_vars", varname=self.getFullname()))
self.master_variable = self.Data(name)
self.master_variable.setParent(parent)
self.master_variable.readonly_vars = self.readonly_vars
@ -436,9 +438,6 @@ class HashVariable(Namespace):
def invalidate(self):
self.master_variable.invalidate()
def getValue(self, invalidate_sub=None):
return self.master_variable.getValue(invalidate_sub)
class TableVariable(Namespace):
"""
@ -456,11 +455,13 @@ class TableVariable(Namespace):
class Data(HashVariable.Data):
def getHashValue(self, name, invalidate_sub=None):
return self.vars.master_variable.getTableValue(name, self._index,
invalidate_sub)
return self.vars.master_variable.getTableValue(name,
self._index,
invalidate_sub)
def setHashValue(self, name, value, force):
self.vars.master_variable.setTableValue(name, self._index, value, force)
self.vars.master_variable.setTableValue(name, self._index,
value, force)
class Data(Variable):
BASE_CLASS = "Data"
@ -472,7 +473,8 @@ class TableVariable(Namespace):
def setTableValue(self, name, index, value, force):
if name in self.readonly_vars and not force:
raise VariableError(
_("Attempting to rewrite readonly variable %s")%name)
_("Attempting to rewrite readonly variable {}").format(
name))
data = [x.copy() for x in self.getValue()]
rowdata = data[index]
rowdata[name] = value
@ -480,19 +482,20 @@ class TableVariable(Namespace):
@property
def childs(self):
if self._childs is None:
value = self.master_variable.getValue()
self._childs = {}
for i, row in enumerate(value):
hashvar = self.TableHashVariable(self.master_variable.name,
self, self.hash_vars, self.master_variable, i)
self._childs[str(i)] = hashvar
return self._childs
if self._childs is None:
value = self.master_variable.getValue()
self._childs = {}
for i, row in enumerate(value):
hashvar = self.TableHashVariable(self.master_variable.name,
self, self.hash_vars,
self.master_variable, i)
self._childs[str(i)] = hashvar
return self._childs
@childs.setter
def childs(self, value):
self._childs = value
def getValue(self, invalidate_sub=None):
return self.master_variable.getValue(invalidate_sub)
@ -519,9 +522,9 @@ class TableVariable(Namespace):
self.parent = parent
if not self.hash_vars:
raise VariableError(
_("Missed '{attrname}' attribute for table variable {varname}"
).format(attrname = "hash_vars",
varname=self.getFullname()))
_("Missed '{attrname}' attribute for table variable {varname}").
format(attrname="hash_vars",
varname=self.getFullname()))
self.master_variable = self.Data(name)
self.master_variable.setParent(parent)
self.master_variable.readonly_vars = self.readonly_vars

@ -5,16 +5,16 @@ import os
import importlib
import importlib.util
import site
from calculate.vars.datavars import Variable, Namespace, HashVariable, TableVariable, IniCreated, DefaultValue
from calculate.vars.datavars import Variable, Namespace, HashVariable,\
TableVariable, IniCreated, DefaultValue
from calculate.utils.gentoo import ProfileWalker
from calculate.utils.fs import readFile
from calculate.utils.files import listDirectory
class NamespaceIniFiller(CalculateIniParser):
"""
Объект используемый для наполения Namespace объекта переменными
из calculate.ini файла
"""
'''Класс, предназначенный для наполнения Namespace объекта переменными
из calculate.ini файла.'''
def error(self, lineno, s):
self.errors.append(lineno, s)
@ -51,7 +51,7 @@ class NamespaceIniFiller(CalculateIniParser):
for v in vlist:
if v not in l:
l.append(v)
self.changeValue(key,",".join(l))
self.changeValue(key, ",".join(l))
def removeValue(self, key, value):
l = self.curns[key].getValue().split(",")
@ -59,7 +59,7 @@ class NamespaceIniFiller(CalculateIniParser):
for v in vlist:
if v in l:
l.remove(v)
self.changeValue(key,",".join(l))
self.changeValue(key, ",".join(l))
def defineKey(self, section, key, value, optype):
Define = CalculateIniParser.Define
@ -82,6 +82,7 @@ class NamespaceIniFiller(CalculateIniParser):
def parseError(self, line, lineno, col):
self.error(lineno, _("Syntax error: %s") % line)
class NamespaceIniFillerStrict(NamespaceIniFiller):
"""
Объект используемый для наполения Namespace объекта переменными
@ -116,7 +117,6 @@ class NamespaceIniFillerStrict(NamespaceIniFiller):
# curns = curns[section]
# curns.clearChilds()
def defineVariable(self, key, value):
if not self.canCreate:
pass
@ -139,6 +139,7 @@ class NamespaceIniFillerStrict(NamespaceIniFiller):
var.addProperty(DefaultValue(value))
var.invalidate()
class VariableLoader:
"""
Объект используемый для загрузки переменных из python модуля

@ -49,7 +49,6 @@ other_package_name = PackageAtomName(
class TestTemplateExecutor:
def test_function_to_copy_testfiles(self):
TemplateWrapper._protected_is_set = False
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
os.path.join(CHROOT_PATH, 'etc'),
symlinks=True)
@ -2464,7 +2463,7 @@ class TestTemplateExecutor:
assert template_executor._get_file_owner(target_path) == chown_value
assert template_executor._get_file_mode(target_path) == chmod_value
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_empty__the_method_does_nothing(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_file_from_an_existing_directory_and_its_text_is_empty__the_method_does_nothing(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_0')
@ -2476,7 +2475,7 @@ class TestTemplateExecutor:
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_correct__the_method_runs_a_template_text_in_the_target_directory_and_returns_the_object_with_its_stdout(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_correct__the_method_runs_a_template_text_in_the_target_directory_and_returns_the_object_with_its_stdout(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_0/file_0')
@ -2492,10 +2491,10 @@ print(os.getcwd())'''
'/path/to/template',
template_text=template_text,
save_changes=False)
assert output['stdout'].strip() == target_path
assert output['stdout'].strip() == os.path.dirname(target_path)
assert output['stderr'] is None
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_directory_from_a_target_path_does_not_exist__the_method_throws_TemplateExecutorError_exception(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_directory_from_a_target_path_does_not_exist__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_1/file_0')
@ -2508,7 +2507,7 @@ print(os.getcwd())'''
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_correct__the_method_runs_a_template_text_in_a_directory_that_contains_a_file_from_a_target_path_and_returns_the_object_with_its_stdout(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_correct__the_method_runs_a_template_text_in_a_directory_that_contains_a_file_from_a_target_path_and_returns_the_object_with_its_stdout(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/file_0')
@ -2527,10 +2526,10 @@ print(os.getcwd())'''
assert output['stdout'].strip() == os.path.dirname(target_path)
assert output['stderr'] is None
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_and_a_target_path_to_an_unexisting_file__the_method_throws_TemplateExecutorError_exception(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_file_from_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/file_1')
'/etc/run_parameter_testfiles/dir_1/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
@ -2540,10 +2539,49 @@ print(os.getcwd())'''
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_with_the_run_parameter_a_target_path_to_an_existing_directory_and_its_text_is_not_correct__the_method_runs_a_template_text_and_returns_the_object_with_its_stderr(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_file_from_an_directory_that_replaced_to_a_file__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_0')
'/etc/run_parameter_testfiles/dir_2/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
FILE,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_run_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_1')
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
DIR,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_run_parameter_and_a_target_path_to_an_existing_file__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_2')
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
DIR,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_run_parameter_a_target_path_to_an_unexisting_file_from_an_existing_directory_and_its_text_is_not_correct__the_method_runs_a_template_text_and_returns_the_object_with_its_stderr(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_0/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'run': '/usr/bin/python'})
traceback_text = '''Traceback (most recent call last):
@ -2581,10 +2619,14 @@ print(os.getcwd())'''
template_text=template_text,
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_empty__the_method_creates_an_empty_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_existing_directory_and_its_text_is_empty__the_method_creates_an_empty_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
target_path = join_paths(
CHROOT_PATH,
'/etc/exec_parameter_testfiles/dir_0')
'/etc/exec_parameter_testfiles/dir_0/file_0')
interpreter = '/usr/bin/python'
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
parameters_object = ParametersContainer({'package': test_package_name,
@ -2598,19 +2640,20 @@ print(os.getcwd())'''
assert template_executor.execute_files[execute_file_path][
'interpreter'] == interpreter
assert template_executor.execute_files[execute_file_path][
'cwd_path'] == target_path
'cwd_path'] == os.path.dirname(target_path)
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
'exec_0001'), 'r') as exec_file:
exec_file_text = exec_file.read()
assert exec_file_text == ''
os.remove(execute_file_path)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_an_existing_directory_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_directory_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_target_path_as_cwd_path(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/exec_parameter_testfiles/dir_0')
'/etc/exec_parameter_testfiles/dir_0/file_0')
interpreter = '/usr/bin/python'
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
parameters_object = ParametersContainer({'package': test_package_name,
@ -2628,19 +2671,52 @@ print(os.getcwd())'''
assert template_executor.execute_files[execute_file_path][
'interpreter'] == interpreter
assert template_executor.execute_files[execute_file_path][
'cwd_path'] == target_path
'cwd_path'] == os.path.dirname(target_path)
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
'exec_0001'), 'r') as exec_file:
exec_file_text = exec_file.read()
assert exec_file_text == template_text
os.remove(execute_file_path)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
target_path = join_paths(CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_1')
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
DIR,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_DIR_type_with_the_exec_parameter_and_a_target_path_to_an_existing_file__the_method_throws_TemplateExecutorError_exception(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_1')
'/etc/exec_parameter_testfiles/dir_4')
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
DIR,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_in_the_directory_that_replaced_to_a_file__the_method_throws_TemplateExecutorError_exception(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
target_path = join_paths(CHROOT_PATH,
'/etc/run_parameter_testfiles/dir_4/file_1')
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
@ -2650,7 +2726,28 @@ print(os.getcwd())'''
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_path_to_a_file_from_a_target_path_as_cwd_path(self):
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_unexisting_directory__the_method_throws_TemplateExecutorError_exception(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
target_path = join_paths(
CHROOT_PATH,
'/etc/exec_parameter_testfiles/dir_1/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
DIR,
'/path/to/template',
save_changes=False)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_existing_file_and_its_text_is_not_empty__the_method_creates_an_exec_file_and_saves_a_path_to_exec_file_interpreter_and_a_path_to_a_file_from_a_target_path_as_cwd_path(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
target_path = join_paths(CHROOT_PATH,
'/etc/exec_parameter_testfiles/file_0')
interpreter = '/usr/bin/python'
@ -2676,23 +2773,42 @@ print(os.getcwd())'''
exec_file_text = exec_file.read()
assert exec_file_text == template_text
os.remove(execute_file_path)
def test_if_the_execute_template_method_s_input_is_a_template_of_the_FILE_type_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file_from_the_existing_directory__the_method_saves_the_exec_file_and_sets_cwd_path_to_a_file_s_directory(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
def test_if_the_execute_template_method_s_input_is_a_template_with_the_exec_parameter_and_a_target_path_to_an_unexisting_file__the_method_throws_TemplateExecutorError_exception(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/exec_parameter_testfiles/file_1')
interpreter = '/usr/bin/python'
execute_file_path = os.path.join(EXECUTE_ARCHIVE_PATH, 'exec_0001')
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
with pytest.raises(TemplateExecutorError):
template_executor.execute_template(target_path,
parameters_object,
FILE,
'/path/to/template',
save_changes=False)
template_text = '''
import os
print(os.getcwd())'''
template_executor.execute_template(target_path,
parameters_object,
FILE,
'/path/to/template',
template_text=template_text,
save_changes=False)
assert os.path.exists(execute_file_path)
assert template_executor.execute_files[execute_file_path][
'interpreter'] == interpreter
assert template_executor.execute_files[execute_file_path][
'cwd_path'] == os.path.dirname(target_path)
with open(os.path.join(EXECUTE_ARCHIVE_PATH,
'exec_0001'), 'r') as exec_file:
exec_file_text = exec_file.read()
assert exec_file_text == template_text
def test_if_the_execute_template_method_s_input_is_a_several_templates_with_the_exec_parameter_and_a_target_paths_to_an_existing_directories_and_files_and_its_text_is_not_empty__the_method_creates_some_exec_files_and_saves_a_paths_to_exec_files_its_interpreters_and_paths_to_a_directories_from_a_target_path_as_cwd_path(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
interpreter = '/usr/bin/python'
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
@ -2705,12 +2821,13 @@ print(os.getcwd())'''
'/etc/exec_parameter_testfiles/dir_2'),
join_paths(CHROOT_PATH,
'/etc/exec_parameter_testfiles/dir_3')]
template_types = [FILE, DIR, DIR]
counter = 1
for target_path in target_paths:
for target_path, template_type in zip(target_paths, template_types):
template_text = "print('{}')".format(counter)
template_executor.execute_template(target_path,
parameters_object,
FILE,
template_type,
'/path/to/template',
template_text=template_text,
save_changes=False)
@ -2731,12 +2848,11 @@ print(os.getcwd())'''
assert exec_file_text == "print('{}')".format(counter)
counter += 1
for exec_path in execute_file_paths:
os.remove(exec_path)
def test_if_some_exec_files_is_saved_and_contains_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_the_returns_its_stdout_and_stderr(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
def test_if_some_exec_files_is_saved_and_contains_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_the_returns_its_stdout_and_stderr(self):
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
target_path = join_paths(
@ -2746,7 +2862,7 @@ print(os.getcwd())'''
template_text = "print('{}')".format(number)
template_executor.execute_template(target_path,
parameters_object,
FILE,
DIR,
'/path/to/template',
template_text=template_text,
save_changes=False)
@ -2756,19 +2872,21 @@ print(os.getcwd())'''
output = template_executor.execute_file(
template_executor.execute_files[exec_file_path]['interpreter'],
exec_file_path,
template_executor.execute_files[exec_file_path]['cwd_path'] )
template_executor.execute_files[exec_file_path]['cwd_path'])
assert output['stdout'].strip() == str(counter)
assert output['stderr'] is None
counter += 1
def test_if_some_exec_files_is_saved_and_contains_not_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_returns_its_stderr_and_stdout(self):
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(EXECUTE_ARCHIVE_PATH)
template_executor.execute_files = OrderedDict()
def test_if_some_exec_files_is_saved_and_contains_not_correct_scripts__the_execute_file_method_can_be_used_for_executing_this_exec_files_and_returns_its_stderr_and_stdout(self):
parameters_object = ParametersContainer({'package': test_package_name,
'exec': '/usr/bin/python'})
target_path = join_paths(
CHROOT_PATH,
'/etc/run_exec_testfiles/dir_0')
'/etc/run_exec_testfiles/dir_0/template_name')
template_text = '''
import os
print(os.suspicious_attribute)'''
@ -2794,8 +2912,6 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
assert output['stderr'] == stderr_text
counter += 1
template_executor.execute_files = OrderedDict()
def test_for_mirror(self):
pass
@ -2804,4 +2920,5 @@ AttributeError: module 'os' has no attribute 'suspicious_attribute'
shutil.rmtree(os.path.join(CHROOT_PATH, 'unprotected'))
shutil.rmtree(os.path.join(CHROOT_PATH,
'var/lib/calculate/config-archive'))
shutil.rmtree(os.path.join(EXECUTE_ARCHIVE_PATH))
if os.path.exists(EXECUTE_ARCHIVE_PATH):
shutil.rmtree(os.path.join(EXECUTE_ARCHIVE_PATH))

@ -1,2 +0,0 @@
{% calculate append = 'skip', name = 'test_root', chown = 'divanov:guest',
action = 'install', path = test.test_root %}

@ -1,15 +0,0 @@
{% calculate format = 'kde', action = 'install',
package = 'xfce-base/xfce4-session' -%}
{% set file_path = test.test_root + '/test_root/conf_dir'%}
{% calculate path = file_path %}
{% calculate merge = 'xfce-base/xfconf' %}
[section][parts][of][section name]
parameter 1 = {{ variables.variable_1 }}
parameter 2 = {{ variables.variable_2 }}
# Random comment.
parameter 3 = very important and veery interesting value
{% for num in variables.group.list -%}
statement {{ num }} = {{ num * 2 - 1 }}
{% endfor -%}

@ -1,4 +0,0 @@
{% calculate name = 'subdir_1_folder', env='merge', chmod = 'rwxr-xr-x', action = 'install' -%}
{% calculate package = 'xfce-base/xfce4-panel', merge = 'xfce-base/xfce4-session' -%}
{% calculate append = 'join' %}
{% calculate not install.boolean -%}

@ -1 +0,0 @@
{% calculate env = 'install', name = 'template_1_folder' %}

@ -1,5 +0,0 @@
{% calculate format = 'json', append = 'join', force -%}
{
"!parameter_1": "important_value",
"parameter_2": {{ os_disk_dev }}
}

@ -1,11 +0,0 @@
{% calculate format='xml_xfce', mirror -%}
{% calculate merge='xfce-base/xfconf' %}
{% save custom.group.parameter = 'DoubleClickTime' -%}
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="{{ version }}">
<property name="Net" type="empty">
<property name="ThemeName" type="string" value="Calculate"/>
<property name="IconThemeName" type="string" value="Calculate"/>
<property name="{{ custom.group.parameter }}" type="int" value="400"/>
</property>
</channel>

@ -1,10 +0,0 @@
{% calculate format='xml_xfce', force -%}
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="{{ version }}">
<property name="Gtk" type="empty">
<property name="FontName" type="string" value="Droid Sans 10"/>
<property name="CursorThemeName" type="string" value="Calculate"/>
<property name="{{ custom.group.parameter }}" type="bool" value="false"/>
</property>
<property name="!Xft" type="empty"/>
</channel>

@ -1,4 +0,0 @@
{% calculate name = 'important_dir', path = '/etc/folder/in_folder', action = 'install',
package = 'media-sound/alsa-utils' -%}
{% calculate install.version > 1.4 %}
{% calculate merge.version < 1.2 -%}

@ -1 +0,0 @@
{% calculate name = "template_3_folder", append='skip', autoupdate %}

@ -1,11 +0,0 @@
{% calculate format = 'kde', path = '/etc/folder/in_folder', name = 'filename.conf' -%}
{% calculate merge = 'xfce-base/xfce4-panel' -%}
# KDE or Plasma config file.
# Part from Plasma
[PlasmaViews][Panel 69][Horizontal1024]
alignment={{ install.number }}
length={{ merge.var_1 }}
maxLength={{ merge.var_1 }}
minLength={{ merge.var_1 }}
panelVisibility=1
thickness={{ merge.var_2 }}

@ -1,3 +0,0 @@
{% calculate name = 'directory', path = '/etc/important_dir',
package = 'xfce-base/xfconf' %}
{% calculate action = 'install' %}

@ -1,4 +0,0 @@
{% calculate name = 'settings.conf', mirror, format = 'postfix' -%}
queue_directory = /var/spool/postfix
command_directory = {{ install.path }}

@ -1,6 +0,0 @@
{% calculate name = 'important.conf', merge = 'xfce-base/xfce4-panel', autoupdate -%}
relay_domains = {{ merge.calculate_domains }}
#Для создания базы используется postmap
transport_maps = hash:/etc/postfix/transport_maps
relay_recipient_maps = hash:/etc/postfix/valid_recipients

@ -1 +0,0 @@
{% calculate append = 'skip', action = 'install', chown = 'divanov:guest' %}

@ -1 +0,0 @@
{% calculate append = 'join', name = 'test_root', path = test.test_root %}

@ -1,2 +0,0 @@
{% calculate name = 'configuration_1', path = '/etc',
package = 'xfce-extra/xfce4-clipman-plugin' %}

@ -1,8 +0,0 @@
{% calculate name = 'template', format = 'bind', append = 'before' -%}
{% calculate merge = 'xfce-base/xfce4-panel' -%}
acl "trusted" {
{{ merge.ip_value }};
10.0.0.0/8;
192.168.1.0/24;
::1/128;
};

@ -1,2 +0,0 @@
{% calculate name = 'config.d', path = '/etc/dir',
package = 'xfce-extra/xfce4-screenshooter' %}

@ -1,10 +0,0 @@
{% calculate name = 'wow_file.conf', force, format = 'samba',
merge = 'media-sound/alsa-utils, xfce-extra/xfce4-clipman-plugin' -%}
[global]
server role = standalone server
hosts allow = 192.168.1. 192.168.2. 127.
log file = /var/log/samba/log.%m
workgroup = {{ variables.variable_1 }}
netbios name = {{ variables.variable_2 }}
server string = Calculate Directory Server
directory mask = 0755

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
section-name {
parameter-1 yes;
parameter-2 no;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_8/root/file_2
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_9/root/etc/file_3
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_28/root/file_12
#-------------------------------------------------------------------------------
section-name {
parameter-1 yes;
parameter-3 10;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_14/root/dir_10/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_16/root/dir_12/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_17/root/dir_13/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_3/root/dir_2/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_5/root/dir_4/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_5/root/dir_5/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_7/root/dir_6/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/dir_7/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 no;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_14/root/dir_9/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_1/root/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_6/root/file_1
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/file_4
#-------------------------------------------------------------------------------
options {
parameter-0 no;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/file_5
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_12/root_0/etc/file_6
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_13/root/etc/dir_9/file_8
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,66 +0,0 @@
root::0:root
bin::1:root,bin,daemon
daemon::2:root,bin,daemon
sys::3:root,bin,adm
adm::4:root,adm,daemon
tty::5:
disk::6:root,adm,haldaemon
lp::7:lp,guest
mem::8:
kmem::9:
wheel::10:root,guest
floppy::11:root,haldaemon
mail::12:mail
news::13:news
uucp::14:uucp,guest
man::15:man
console::17:
audio::18:guest
cdrom::19:haldaemon,guest
dialout::20:root
tape::26:root
video::27:root,guest
cdrw::80:haldaemon,guest
usb::85:haldaemon,guest
users::100:games,guest
nofiles:x:200:
smmsp:x:209:smmsp
portage::250:portage
utmp:x:406:
nogroup::65533:
nobody::65534:
sshd:x:22:
games:x:35:guest
plugdev:x:440:haldaemon,usbmux,guest
scanner:x:441:guest
ldap:x:439:
messagebus:x:199:
lpadmin:x:106:
polkituser:x:105:
cron:x:16:
ntp:x:123:
rpc:x:111:
fingerprint:x:104:
ssmtp:x:103:
crontab:x:102:
gdm:x:101:
haldaemon:x:999:haldaemon
openvpn:x:998:
vnstat:x:997:
dnsmasq:x:996:
polkitd:x:995:
locate:x:994:
input:x:993:
dhcp:x:992:
mysql:x:60:
netdev:x:991:
avahi:x:990:
avahi-autoipd:x:989:
nm-openvpn:x:988:
deluge:x:987:
postgres:x:70:
nullmail:x:88:
sudo:x:443:
kvm:x:78:
render:x:28:
guest:!:1000:

@ -1,42 +0,0 @@
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/false
daemon:x:2:2:daemon:/sbin:/bin/false
adm:x:3:4:adm:/var/adm:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:Mail program user:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/bin/false
uucp:x:10:14:uucp:/var/spool/uucppublic:/bin/false
operator:x:11:0:operator:/root:/bin/bash
man:x:13:15:man:/usr/share/man:/bin/false
postmaster:x:14:12:Postmaster user:/var/spool/mail:/sbin/nologin
portage:x:250:250:portage:/var/tmp/portage:/bin/false
nobody:x:65534:65534:nobody:/:/bin/false
sshd:x:22:22:added by portage for openssh:/var/empty:/sbin/nologin
ldap:x:439:439:added by portage for openldap:/usr/lib64/openldap:/sbin/nologin
messagebus:x:101:199:System user; messagebus:/dev/null:/sbin/nologin
polkituser:x:102:105:added by portage for polkit:/dev/null:/sbin/nologin
cron:x:16:16:added by portage for cronbase:/var/spool/cron:/sbin/nologin
ntp:x:123:123:added by portage for ntp:/dev/null:/sbin/nologin
rpc:x:111:111:added by portage for portmap:/dev/null:/sbin/nologin
gdm:x:103:101:added by portage for gdm:/var/lib/gdm:/sbin/nologin
haldaemon:x:104:999:added by portage for hal:/dev/null:/sbin/nologin
openvpn:x:105:998:added by portage for openvpn:/dev/null:/sbin/nologin
usbmux:x:106:85:added by portage for usbmuxd:/dev/null:/sbin/nologin
vnstat:x:107:997:added by portage for vnstat:/dev/null:/sbin/nologin
dnsmasq:x:108:996:added by portage for dnsmasq:/dev/null:/sbin/nologin
polkitd:x:109:995:added by portage for polkit:/var/lib/polkit-1:/sbin/nologin
saned:x:110:441:added by portage for sane-backends:/dev/null:/sbin/nologin
dhcp:x:112:992:added by portage for dhcp:/var/lib/dhcp:/sbin/nologin
mysql:x:60:60:added by portage for mysql:/dev/null:/sbin/nologin
avahi:x:113:990:added by portage for avahi:/dev/null:/sbin/nologin
avahi-autoipd:x:114:989:added by portage for avahi:/dev/null:/sbin/nologin
nm-openvpn:x:115:988:added by portage for networkmanager-openvpn:/dev/null:/sbin/nologin
games:x:36:35:added by portage for games-envd:/usr/games:/bin/bash
deluge:x:116:987:added by portage for deluge:/var/lib/deluge:/sbin/nologin
postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/sh
nullmail:x:88:88:added by portage for nullmailer:/var/nullmailer:/sbin/nologin
divanov:x:1427:1000::/home/denis:/bin/bash
guest:x:1000:1000::/home/guest:/bin/bash

@ -1,12 +0,0 @@
dir /etc
obj /etc/file_1 823bb8dc6fdf14449714181a729374a9 1594219444
obj /etc/file_2 178094df387d2f5c2a3516a81fe760de 1594219445
obj /etc/file_3 ed2b41fe5b2e68ad3a974e0b8f9cc99a 1594219445
obj /etc/file_4 da04b7769f94c9702c0edcb8bba4770c 1594219445
dir /etc/dir_6
obj /etc/dir_6/file_0 e6977bce3e6edd818bb72f324a2a74f3 1594219444
obj /etc/dir_7/file_0 664c77aaf2d358d227db03545b083ea3 1594219446
dir /etc/dir_12
obj /etc/dir_12/file_0 a9109c66e7ec71c12bb2d45273f2c46d 1594219447
obj /etc/file_5 916eec267d08950072369b69c10a99ae 1594219445
dir /etc/dir_7

@ -1,3 +0,0 @@
dir /etc
dir /etc/dir_9
obj /etc/dir_9/file_0 78373bda3f7f86f54ca25724291a5492 1594219446

@ -1,18 +0,0 @@
dir /etc
dir /etc/dir_17
obj /etc/dir_17/file_0 c585be6f171462940b44af994a54040d 1593525253
dir /etc/dir_17/dir_0
obj /etc/dir_17/dir_0/file_0 c585be6f171462940b44af994a54040d 1593525253
obj /etc/file_12 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/file_0 d8047d1de0f84955782fb17d9172c283 1594219443
dir /etc/dir_2
obj /etc/dir_2/file_0 4d87707225fe92339257baad74d26220 1594219443
dir /etc/dir_4
obj /etc/dir_4/file_0 2760f4fa242d649cc32b7c27926b5bf9 1594219444
dir /etc/dir_5
dir /etc/dir_5/dir_6
obj /etc/dir_5/dir_6/file_0 c5f1a785f8e5f4af46c74afcb7c2efcc 1594219444
obj /etc/file_6 8ad8eb73b5f86ee77c2f4a89f61a5899 1594219446
obj /etc/file_8 ada08a4f77c8181fa33cac4aa39b2843 1594219446
dir /etc/dir_10
obj /etc/dir_10/file_0 454438a905c36213ec67d2a61b855daa 1594219447

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_14/root/dir_10/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_16/root/dir_12/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_3/root/dir_2/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_5/root/dir_4/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_5/root/dir_5/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_7/root/dir_6/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/dir_7/file_0
#-------------------------------------------------------------------------------
options {
parameter-0 no;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_14/root/dir_9/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_1/root/file_0
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_6/root/file_1
#-------------------------------------------------------------------------------
options {
parameter-0 yes;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,10 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/file_4
#-------------------------------------------------------------------------------
options {
parameter-0 no;
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_10/root/etc/file_5
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_12/root_0/etc/file_6
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -1,9 +0,0 @@
#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /home/divanov/Home/development/calculate-lib/tests/templates/testfiles/test_dir_processor_root/templates_13/root/etc/dir_9/file_8
#-------------------------------------------------------------------------------
options {
parameter-1 value_1;
parameter-2 value_2;
};

@ -4,12 +4,13 @@ from calculate.utils.calculateini import CalculateIniParser
Define = CalculateIniParser.Define
@pytest.mark.vars
@pytest.mark.calculateini
class TestCalculateIni:
def test_empty_calculate_ini(self):
pass
#ns = Namespace(varPath=None)
#assert ns.varPath is None
# ns = Namespace(varPath=None)
# assert ns.varPath is None
def test_section_values(self, mocker):
cip = CalculateIniParser()
@ -23,7 +24,8 @@ class TestCalculateIni:
spy_error.assert_not_called()
spy_section.assert_has_calls([call(['section'])])
spy_def_key.assert_has_calls([
call(['section'],'varval1', 'value1', Define.Assign),])
call(['section'], 'varval1', 'value1', Define.Assign),
])
def test_simple_calculate_ini_with_comments(self, mocker):
cip = CalculateIniParser()
@ -39,11 +41,10 @@ class TestCalculateIni:
spy_error.assert_not_called()
spy_section.assert_has_calls([call(['section'])])
spy_def_key.assert_has_calls([
call(['section'],'varval1', 'value1', Define.Assign),
call(['section'],'varval2', 'value2', Define.Append),
call(['section'],'varval3', 'value3', Define.Remove),
])
call(['section'], 'varval1', 'value1', Define.Assign),
call(['section'], 'varval2', 'value2', Define.Append),
call(['section'], 'varval3', 'value3', Define.Remove),
])
def test_some_complex_section_calculate_ini(self, mocker):
cip = CalculateIniParser()
@ -58,18 +59,17 @@ class TestCalculateIni:
"varval1 = value1\n"
"\n"
"[section2]\n"
"varval1 = value1\n"
)
"varval1 = value1\n")
spy_error.assert_not_called()
spy_section.assert_has_calls([call(['section','sub'])])
spy_section.assert_has_calls([call(['section','sub2'])])
spy_section.assert_has_calls([call(['section', 'sub'])])
spy_section.assert_has_calls([call(['section', 'sub2'])])
spy_section.assert_has_calls([call(['section2'])])
spy_def_key.assert_has_calls([
call(['section', 'sub'],'varval1','value1', Define.Assign),
call(['section', 'sub'],'varval2','value2', Define.Assign),
call(['section', 'sub2'],'varval1','value1', Define.Assign),
call(['section2'],'varval1','value1', Define.Assign),
call(['section', 'sub'], 'varval1', 'value1', Define.Assign),
call(['section', 'sub'], 'varval2', 'value2', Define.Assign),
call(['section', 'sub2'], 'varval1', 'value1', Define.Assign),
call(['section2'], 'varval1', 'value1', Define.Assign),
])
def test_error(self, mocker):
@ -89,16 +89,16 @@ class TestCalculateIni:
"varval4 = value4\n"
"[section][]\n"
"[section][][sub]\n"
"[section][][sub][]\n"
)
"[section][][sub][]\n")
# проверяем, что расозналась только одна секция
spy_section.assert_has_calls([call(['section','sub2'])])
spy_section.assert_has_calls([call(['section', 'sub2'])])
# проверяем, что значение из криво определённой section2 попало
# в section.sub2
spy_def_key.assert_has_calls([
call(['section', 'sub2'],'varval1','value1', Define.Assign),
call(['section', 'sub2'],'varval4','value4', Define.Assign),
])
call(['section', 'sub2'], 'varval1', 'value1', Define.Assign),
call(['section', 'sub2'], 'varval4', 'value4', Define.Assign),
])
# проверяем, все нераспознанные строки попали в ошибки
# криво объявленная первая секция
# её переменные
@ -111,9 +111,9 @@ class TestCalculateIni:
call('eee', 6, 1),
call('[section2', 8, 1),
call('[section][][sub]', 11, 1),
call('[section][][sub][]', 12, 1)
])
call('[section][][sub][]', 12, 1),
])
def test_clear_section(self, mocker):
cip = CalculateIniParser()
spy_section = mocker.spy(cip, 'startSection')
@ -122,9 +122,9 @@ class TestCalculateIni:
spy_clear_sec = mocker.spy(cip, 'clearSection')
cip.parse("[section][test][]\n")
spy_error.assert_not_called()
spy_def_key.assert_not_called()
spy_section.assert_not_called()
spy_clear_sec.assert_has_calls([call(['section','test'])])
spy_clear_sec.assert_has_calls([call(['section', 'test'])])

Loading…
Cancel
Save