Fixed creation of the group variables

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

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

@ -474,6 +474,9 @@ class PackageAtomParser:
package_name_regex = re.compile(package_name_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',
chroot_path='/'):
self.chroot_path = chroot_path

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

@ -1,10 +1,23 @@
from calculate.variables.datavars import Variable, StringType, ListType
from calculate.variables.datavars import (
Variable,
StringType,
ListType,
)
'''
main:
chroot -> 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_root_path', type=StringType.readonly, source='/')

@ -1,5 +1,8 @@
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