Fixed creation of the group variables

master
Иванов Денис 3 years ago
parent e8d9ddd9e7
commit fd22b6062a

@ -34,6 +34,7 @@ from calculate.variables.datavars import (
NamespaceNode, NamespaceNode,
VariableNode, VariableNode,
TableType, TableType,
VariableNotFoundError
) )
from calculate.variables.loader import Datavars from calculate.variables.loader import Datavars
from .format.base_format import Format from .format.base_format import Format
@ -2049,7 +2050,7 @@ class DirectoryProcessor:
package_atom: str) -> None: package_atom: str) -> None:
try: try:
groups_namespace = self.datavars_module.main.cl.groups groups_namespace = self.datavars_module.main.cl.groups
except Exception: except VariableNotFoundError:
namespaces = ['cl', 'groups'] namespaces = ['cl', 'groups']
groups_namespace = self.datavars_module.main groups_namespace = self.datavars_module.main
for namespace in namespaces: for namespace in namespaces:
@ -2072,7 +2073,7 @@ class DirectoryProcessor:
source=[atom_dict]) source=[atom_dict])
else: else:
group_var = groups_namespace[group_name] group_var = groups_namespace[group_name]
group_table = group_var.get_table() group_table = group_var.get_value().get_table()
if not self.check_existance_in_group(atom_dict, group_table): if not self.check_existance_in_group(atom_dict, group_table):
group_table.append(atom_dict) group_table.append(atom_dict)
group_var.source = group_table group_var.source = group_table
@ -2095,7 +2096,6 @@ class DirectoryProcessor:
def _make_current_template_var(self) -> None: def _make_current_template_var(self) -> None:
var_path = ['main', 'cl'] var_path = ['main', 'cl']
namespace = self.datavars_module namespace = self.datavars_module
print("namespace:", namespace)
for field in var_path: for field in var_path:
if field not in namespace: if field not in namespace:

@ -474,6 +474,9 @@ class PackageAtomParser:
package_name_regex = re.compile(package_name_pattern) package_name_regex = re.compile(package_name_pattern)
version_regex = re.compile(_version_pattern) version_regex = re.compile(_version_pattern)
atom_dict_fields = ['category', 'name', 'version', 'slot', 'use_flags',
'with_slot', 'condition']
def __init__(self, pkg_path='/var/db/pkg', def __init__(self, pkg_path='/var/db/pkg',
chroot_path='/'): chroot_path='/'):
self.chroot_path = chroot_path self.chroot_path = chroot_path

@ -302,7 +302,7 @@ class Table:
self.columns = set() self.columns = set()
if fields is not None: if fields is not None:
self.columns.update(self.fields) self.columns.update(fields)
else: else:
self.columns = set(values[0].keys()) self.columns = set(values[0].keys())
@ -380,7 +380,11 @@ class TableType(VariableType):
else: else:
if isinstance(value, Table): if isinstance(value, Table):
return value return value
return Table(value, variable)
if variable.fields:
return Table(value, variable, fields=variable.fields)
else:
return Table(value, variable)
class Static: class Static:
@ -563,8 +567,9 @@ class DependenceSource:
class VariableNode: class VariableNode:
'''Класс ноды соответствующей переменной в дереве переменных.''' '''Класс ноды соответствующей переменной в дереве переменных.'''
def __init__(self, name, namespace, variable_type=VariableType, def __init__(self, name: str, namespace: "NamespaceNode",
source=None): variable_type=VariableType,
source=None, fields: list = []):
self.name = name self.name = name
if issubclass(variable_type, VariableType): if issubclass(variable_type, VariableType):
self.variable_type = variable_type self.variable_type = variable_type
@ -572,6 +577,7 @@ class VariableNode:
raise VariableTypeError('variable_type must be VariableType' raise VariableTypeError('variable_type must be VariableType'
', but not {}'.format(type(variable_type))) ', but not {}'.format(type(variable_type)))
self.calculating = False self.calculating = False
self.fields = fields
self.namespace = namespace self.namespace = namespace
self.namespace.add_variable(self) self.namespace.add_variable(self)
@ -633,7 +639,10 @@ class VariableNode:
else: else:
value = self._source value = self._source
self.value = self.variable_type.process_value(value, self) if self.variable_type is TableType:
self.value = self.variable_type.process_value(value, self)
else:
self.value = self.variable_type.process_value(value, self)
self._invalidated = False self._invalidated = False
def set_variable_type(self, variable_type: VariableType, def set_variable_type(self, variable_type: VariableType,
@ -681,9 +690,6 @@ class VariableNode:
# Если источники не совпадают или текущее значение переменной было # Если источники не совпадают или текущее значение переменной было
# установлено пользователем, то инвалидируем переменную и меняем # установлено пользователем, то инвалидируем переменную и меняем
# источник. # источник.
if self.name == "machine":
print('self.source =', self.source)
print('source =', source)
if self._source != source or self.set_by_user: if self._source != source or self.set_by_user:
self.set_by_user = False self.set_by_user = False
self._invalidate() self._invalidate()
@ -950,19 +956,13 @@ class VariableAPI(metaclass=Singleton):
self.errors = [] self.errors = []
def __call__(self, name: str, source=None, type=VariableType, def __call__(self, name: str, source=None, type=VariableType,
readonly=False, fixed=False, force=False): readonly=False, fixed=False, force=False, fields=None):
'''Метод для создания переменных внутри with Namespace('name').''' '''Метод для создания переменных внутри with Namespace('name').'''
if name == "machine":
print("creating var...")
if name not in self.current_namespace._variables: if name not in self.current_namespace._variables:
variable = VariableNode(name, self.current_namespace) variable = VariableNode(name, self.current_namespace)
else: else:
variable = self.current_namespace[name] variable = self.current_namespace[name]
if name == "machine":
print('using dependence')
if isinstance(source, DependenceSource): if isinstance(source, DependenceSource):
try: try:
source.check() source.check()
@ -974,12 +974,16 @@ class VariableAPI(metaclass=Singleton):
else: else:
variable.source = source variable.source = source
if fields:
variable.fields = fields
if readonly: if readonly:
variable.set_variable_type(type, readonly=True) variable.set_variable_type(type, readonly=True)
elif fixed: elif fixed:
variable.set_variable_type(type, fixed=True) variable.set_variable_type(type, fixed=True)
else: else:
variable.set_variable_type(type) variable.set_variable_type(type)
return variable return variable

@ -1,10 +1,23 @@
from calculate.variables.datavars import Variable, StringType, ListType from calculate.variables.datavars import (
Variable,
StringType,
ListType,
)
''' '''
main: main:
chroot -> string chroot -> string
cl_template_path -> string cl_template_path -> string
''' '''
# class A:
# @classmethod
# def test(cls):
# return "test"
# Variable("test", type=StringType, source=Calculate(A.test))
Variable('cl_chroot_path', type=StringType.readonly, source='/') Variable('cl_chroot_path', type=StringType.readonly, source='/')
Variable('cl_root_path', type=StringType.readonly, source='/') Variable('cl_root_path', type=StringType.readonly, source='/')

@ -1,5 +1,8 @@
from calculate.variables.datavars import Variable, TableType from calculate.variables.datavars import Variable, TableType
from calculate.utils.package import PackageAtomParser
Variable('build', type=TableType, source=[]) Variable('build', type=TableType, source=[],
fields=PackageAtomParser.atom_dict_fields)
Variable('unistall', type=TableType, source=[]) Variable('unistall', type=TableType, source=[],
fields=PackageAtomParser.atom_dict_fields)

Loading…
Cancel
Save