pylint
This commit is contained in:
parent
0d87be9d7b
commit
0497698203
|
@ -44,7 +44,7 @@ class PropertyAnnotator:
|
||||||
f'variable "{variable.name}" in {xmlfiles}')
|
f'variable "{variable.name}" in {xmlfiles}')
|
||||||
raise DictConsistencyError(msg, 50)
|
raise DictConsistencyError(msg, 50)
|
||||||
if properties:
|
if properties:
|
||||||
variable.properties = frozenset(properties)
|
variable.properties = set(properties)
|
||||||
|
|
||||||
def convert_services(self) -> None:
|
def convert_services(self) -> None:
|
||||||
"""convert services
|
"""convert services
|
||||||
|
|
|
@ -10,7 +10,8 @@ from ..error import DictConsistencyError
|
||||||
# that shall not be present in the exported (flatened) XML
|
# that shall not be present in the exported (flatened) XML
|
||||||
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
|
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
|
||||||
'remove_condition', 'path', 'instance_mode', 'index', 'is_in_leadership',
|
'remove_condition', 'path', 'instance_mode', 'index', 'is_in_leadership',
|
||||||
'level', 'remove_fill', 'xmlfiles', 'type', 'reflector_name', 'reflector_object',)
|
'level', 'remove_fill', 'xmlfiles', 'type', 'reflector_name',
|
||||||
|
'reflector_object',)
|
||||||
|
|
||||||
|
|
||||||
KEY_TYPE = {'variable': 'symlink',
|
KEY_TYPE = {'variable': 'symlink',
|
||||||
|
|
|
@ -3,6 +3,7 @@ flattened XML specific
|
||||||
"""
|
"""
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .annotator import ERASED_ATTRIBUTES, CONVERT_OPTION
|
from .annotator import ERASED_ATTRIBUTES, CONVERT_OPTION
|
||||||
|
#from .objspace import UnRedefinable, Redefinable, Atom
|
||||||
|
|
||||||
|
|
||||||
FUNC_TO_DICT = []
|
FUNC_TO_DICT = []
|
||||||
|
@ -45,7 +46,7 @@ class TiramisuReflector:
|
||||||
baseelt = BaseElt()
|
baseelt = BaseElt()
|
||||||
self.set_name(baseelt)
|
self.set_name(baseelt)
|
||||||
basefamily = Family(baseelt,
|
basefamily = Family(baseelt,
|
||||||
self,
|
self.text,
|
||||||
)
|
)
|
||||||
for elt in self.reorder_family(space):
|
for elt in self.reorder_family(space):
|
||||||
self.iter_family(basefamily,
|
self.iter_family(basefamily,
|
||||||
|
@ -101,7 +102,7 @@ class TiramisuReflector:
|
||||||
"""
|
"""
|
||||||
self.set_name(elt)
|
self.set_name(elt)
|
||||||
family = Family(elt,
|
family = Family(elt,
|
||||||
self,
|
self.text,
|
||||||
)
|
)
|
||||||
parent_family.add(family)
|
parent_family.add(family)
|
||||||
for children in self.get_children(elt):
|
for children in self.get_children(elt):
|
||||||
|
@ -130,7 +131,7 @@ class TiramisuReflector:
|
||||||
):
|
):
|
||||||
"""Populate variable
|
"""Populate variable
|
||||||
"""
|
"""
|
||||||
if family.is_leader:
|
if family.is_leadership:
|
||||||
is_leader = elt.name == family.elt.variable[0].name
|
is_leader = elt.name == family.elt.variable[0].name
|
||||||
is_follower = not is_leader
|
is_follower = not is_leader
|
||||||
else:
|
else:
|
||||||
|
@ -138,7 +139,7 @@ class TiramisuReflector:
|
||||||
is_follower = False
|
is_follower = False
|
||||||
self.set_name(elt)
|
self.set_name(elt)
|
||||||
family.add(Variable(elt,
|
family.add(Variable(elt,
|
||||||
self,
|
self.text,
|
||||||
is_follower,
|
is_follower,
|
||||||
is_leader,
|
is_leader,
|
||||||
))
|
))
|
||||||
|
@ -146,6 +147,8 @@ class TiramisuReflector:
|
||||||
def set_name(self,
|
def set_name(self,
|
||||||
elt,
|
elt,
|
||||||
):
|
):
|
||||||
|
"""Set name
|
||||||
|
"""
|
||||||
elt.reflector_name = f'option_{self.index}'
|
elt.reflector_name = f'option_{self.index}'
|
||||||
self.index += 1
|
self.index += 1
|
||||||
|
|
||||||
|
@ -167,14 +170,14 @@ class Common:
|
||||||
"""Common function for variable and family
|
"""Common function for variable and family
|
||||||
"""
|
"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
storage,
|
elt,
|
||||||
is_leader,
|
text,
|
||||||
):
|
):
|
||||||
|
self.elt = elt
|
||||||
self.option_name = None
|
self.option_name = None
|
||||||
self.attrib = {}
|
self.attrib = {}
|
||||||
self.informations = {}
|
self.informations = {}
|
||||||
self.storage = storage
|
self.text = text
|
||||||
self.is_leader = is_leader
|
|
||||||
self.elt.reflector_object = self
|
self.elt.reflector_object = self
|
||||||
|
|
||||||
def populate_properties(self, child):
|
def populate_properties(self, child):
|
||||||
|
@ -192,6 +195,14 @@ class Common:
|
||||||
self.attrib['properties'] += ', '
|
self.attrib['properties'] += ', '
|
||||||
self.attrib['properties'] += prop
|
self.attrib['properties'] += prop
|
||||||
|
|
||||||
|
def properties_to_string(self):
|
||||||
|
"""Change properties to string
|
||||||
|
"""
|
||||||
|
if not self.attrib['properties']:
|
||||||
|
self.attrib['properties'] = ''
|
||||||
|
else:
|
||||||
|
self.attrib['properties'] = "'" + "', '".join(sorted(self.attrib['properties'])) + "'"
|
||||||
|
|
||||||
def get_attrib(self):
|
def get_attrib(self):
|
||||||
"""Get attributes
|
"""Get attributes
|
||||||
"""
|
"""
|
||||||
|
@ -216,7 +227,7 @@ class Common:
|
||||||
for key, value in self.informations.items():
|
for key, value in self.informations.items():
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = '"' + value.replace('"', '\"') + '"'
|
value = '"' + value.replace('"', '\"') + '"'
|
||||||
self.storage.text.append(f'{self.option_name}.impl_set_information("{key}", {value})')
|
self.text.append(f'{self.option_name}.impl_set_information("{key}", {value})')
|
||||||
|
|
||||||
def get_attributes(self, space): # pylint: disable=R0201
|
def get_attributes(self, space): # pylint: disable=R0201
|
||||||
"""Get attributes
|
"""Get attributes
|
||||||
|
@ -248,14 +259,12 @@ class Variable(Common):
|
||||||
"""
|
"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
elt,
|
elt,
|
||||||
storage,
|
text,
|
||||||
is_follower,
|
is_follower,
|
||||||
is_leader,
|
is_leader,
|
||||||
):
|
):
|
||||||
self.elt = elt
|
super().__init__(elt, text)
|
||||||
super().__init__(storage,
|
self.is_leader = is_leader
|
||||||
is_leader,
|
|
||||||
)
|
|
||||||
self.is_follower = is_follower
|
self.is_follower = is_follower
|
||||||
convert_option = CONVERT_OPTION[elt.type]
|
convert_option = CONVERT_OPTION[elt.type]
|
||||||
self.object_type = convert_option['opttype']
|
self.object_type = convert_option['opttype']
|
||||||
|
@ -275,7 +284,7 @@ class Variable(Common):
|
||||||
self.parse_children()
|
self.parse_children()
|
||||||
attrib = self.get_attrib()
|
attrib = self.get_attrib()
|
||||||
self.option_name = self.elt.reflector_name
|
self.option_name = self.elt.reflector_name
|
||||||
self.storage.text.append(f'{self.option_name} = {self.object_type}({attrib})')
|
self.text.append(f'{self.option_name} = {self.object_type}({attrib})')
|
||||||
self.populate_informations()
|
self.populate_informations()
|
||||||
return self.option_name
|
return self.option_name
|
||||||
|
|
||||||
|
@ -303,44 +312,55 @@ class Variable(Common):
|
||||||
if self.attrib['multi'] == 'submulti' and self.is_follower:
|
if self.attrib['multi'] == 'submulti' and self.is_follower:
|
||||||
self.attrib['default_multi'] = []
|
self.attrib['default_multi'] = []
|
||||||
choices = []
|
choices = []
|
||||||
if 'properties' in self.attrib:
|
self.properties_to_string()
|
||||||
if self.attrib['properties']:
|
|
||||||
self.attrib['properties'] = "'" + \
|
|
||||||
"', '".join(sorted(list(self.attrib['properties']))) + "'"
|
|
||||||
else:
|
|
||||||
self.attrib['properties'] = ''
|
|
||||||
for tag, children in self.get_children(self.elt):
|
for tag, children in self.get_children(self.elt):
|
||||||
for child in children:
|
for child in children:
|
||||||
if tag == 'property':
|
self.parse_child(tag,
|
||||||
self.populate_properties(child)
|
child,
|
||||||
elif tag == 'value':
|
choices,
|
||||||
if child.type == 'calculation':
|
)
|
||||||
self.attrib['default'] = self.calculation_value(child, [])
|
|
||||||
else:
|
|
||||||
self.populate_value(child)
|
|
||||||
elif tag == 'check':
|
|
||||||
validator = self.calculation_value(child, ['ParamSelfOption()'])
|
|
||||||
self.attrib['validators'].append(validator)
|
|
||||||
elif tag == 'choice':
|
|
||||||
if child.type == 'calculation':
|
|
||||||
value = child.name.reflector_object.get()
|
|
||||||
choices = f"Calculation(func.calc_value, Params((ParamOption({value}))))"
|
|
||||||
else:
|
|
||||||
choices.append(child.name)
|
|
||||||
if choices:
|
if choices:
|
||||||
if isinstance(choices, list):
|
self.attrib['values'] = str(tuple(choices))
|
||||||
self.attrib['values'] = str(tuple(choices))
|
if not self.attrib['default']:
|
||||||
else:
|
|
||||||
self.attrib['values'] = choices
|
|
||||||
if self.attrib['default'] == []:
|
|
||||||
del self.attrib['default']
|
del self.attrib['default']
|
||||||
elif not self.attrib['multi'] and isinstance(self.attrib['default'], list):
|
elif not self.attrib['multi'] and isinstance(self.attrib['default'], list):
|
||||||
self.attrib['default'] = self.attrib['default'][-1]
|
self.attrib['default'] = self.attrib['default'][-1]
|
||||||
if self.attrib['validators'] == []:
|
if not self.attrib['validators']:
|
||||||
del self.attrib['validators']
|
del self.attrib['validators']
|
||||||
else:
|
else:
|
||||||
self.attrib['validators'] = '[' + ', '.join(self.attrib['validators']) + ']'
|
self.attrib['validators'] = '[' + ', '.join(self.attrib['validators']) + ']'
|
||||||
|
|
||||||
|
def parse_child(self,
|
||||||
|
tag,
|
||||||
|
child,
|
||||||
|
choices,
|
||||||
|
) -> None:
|
||||||
|
"""Parse child
|
||||||
|
"""
|
||||||
|
if tag == 'property':
|
||||||
|
self.populate_properties(child)
|
||||||
|
elif tag == 'value':
|
||||||
|
self.populate_value(child)
|
||||||
|
elif tag == 'check':
|
||||||
|
validator = self.calculation_value(child, ['ParamSelfOption()'])
|
||||||
|
self.attrib['validators'].append(validator)
|
||||||
|
elif tag == 'choice':
|
||||||
|
self.calculate_choice(child,
|
||||||
|
choices,
|
||||||
|
)
|
||||||
|
|
||||||
|
def calculate_choice(self,
|
||||||
|
child,
|
||||||
|
choices: list,
|
||||||
|
) -> None:
|
||||||
|
"""Calculating choice
|
||||||
|
"""
|
||||||
|
if child.type == 'calculation':
|
||||||
|
value = child.name.reflector_object.get()
|
||||||
|
self.attrib['values'] = f"Calculation(func.calc_value, Params((ParamOption({value}))))"
|
||||||
|
else:
|
||||||
|
choices.append(child.name)
|
||||||
|
|
||||||
def calculation_value(self,
|
def calculation_value(self,
|
||||||
child,
|
child,
|
||||||
args,
|
args,
|
||||||
|
@ -393,23 +413,25 @@ class Variable(Common):
|
||||||
):
|
):
|
||||||
"""Populate variable's values
|
"""Populate variable's values
|
||||||
"""
|
"""
|
||||||
value = child.name
|
if child.type == 'calculation':
|
||||||
if self.attrib['multi'] == 'submulti':
|
self.attrib['default'] = self.calculation_value(child, [])
|
||||||
self.attrib['default_multi'].append(value)
|
|
||||||
elif self.is_follower:
|
|
||||||
self.attrib['default_multi'] = value
|
|
||||||
elif self.attrib['multi']:
|
|
||||||
self.attrib['default'].append(value)
|
|
||||||
if not self.is_leader:
|
|
||||||
self.attrib['default_multi'] = value
|
|
||||||
elif isinstance(value, (int, float)) or value is None:
|
|
||||||
self.attrib['default'].append(value)
|
|
||||||
else:
|
else:
|
||||||
self.attrib['default'].append("'" + value + "'")
|
value = child.name
|
||||||
|
if self.attrib['multi'] == 'submulti':
|
||||||
|
self.attrib['default_multi'].append(value)
|
||||||
|
elif self.is_follower:
|
||||||
|
self.attrib['default_multi'] = value
|
||||||
|
elif self.attrib['multi']:
|
||||||
|
self.attrib['default'].append(value)
|
||||||
|
if not self.is_leader:
|
||||||
|
self.attrib['default_multi'] = value
|
||||||
|
elif isinstance(value, (int, float)) or value is None:
|
||||||
|
self.attrib['default'].append(value)
|
||||||
|
else:
|
||||||
|
self.attrib['default'].append("'" + value + "'")
|
||||||
|
|
||||||
def build_param(self,
|
@staticmethod
|
||||||
param,
|
def build_param(param) -> str:
|
||||||
):
|
|
||||||
"""build variable parameters
|
"""build variable parameters
|
||||||
"""
|
"""
|
||||||
option_name = param['option'].reflector_object.get()
|
option_name = param['option'].reflector_object.get()
|
||||||
|
@ -425,12 +447,10 @@ class Family(Common):
|
||||||
"""
|
"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
elt,
|
elt,
|
||||||
storage,
|
text,
|
||||||
):
|
):
|
||||||
self.elt = elt
|
super().__init__(elt, text)
|
||||||
super().__init__(storage,
|
self.is_leadership = self.elt.__class__.__name__ == 'Leadership'
|
||||||
elt.__class__.__name__ == 'Leadership',
|
|
||||||
)
|
|
||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
def add(self, child):
|
def add(self, child):
|
||||||
|
@ -448,7 +468,7 @@ class Family(Common):
|
||||||
object_name = self.get_object_name()
|
object_name = self.get_object_name()
|
||||||
attrib = self.get_attrib() + \
|
attrib = self.get_attrib() + \
|
||||||
', children=[' + ', '.join([child.get() for child in self.children]) + ']'
|
', children=[' + ', '.join([child.get() for child in self.children]) + ']'
|
||||||
self.storage.text.append(f'{self.option_name} = {object_name}({attrib})')
|
self.text.append(f'{self.option_name} = {object_name}({attrib})')
|
||||||
self.populate_informations()
|
self.populate_informations()
|
||||||
return self.option_name
|
return self.option_name
|
||||||
|
|
||||||
|
@ -470,17 +490,16 @@ class Family(Common):
|
||||||
"""parse current children
|
"""parse current children
|
||||||
"""
|
"""
|
||||||
if 'properties' in self.attrib:
|
if 'properties' in self.attrib:
|
||||||
self.attrib['properties'] = "'" + \
|
self.properties_to_string()
|
||||||
"', '".join(sorted(list(self.attrib['properties']))) + "'"
|
if hasattr(self.elt, 'property'):
|
||||||
if hasattr(self.elt, 'property'):
|
for child in self.elt.property:
|
||||||
for child in self.elt.property:
|
self.populate_properties(child)
|
||||||
self.populate_properties(child)
|
|
||||||
|
|
||||||
def get_object_name(self):
|
def get_object_name(self):
|
||||||
"""Get family object's name
|
"""Get family object's name
|
||||||
"""
|
"""
|
||||||
if 'suffixes' in self.attrib:
|
if 'suffixes' in self.attrib:
|
||||||
return 'ConvertDynOptionDescription'
|
return 'ConvertDynOptionDescription'
|
||||||
if not self.is_leader:
|
if self.is_leadership:
|
||||||
return 'OptionDescription'
|
return 'Leadership'
|
||||||
return 'Leadership'
|
return 'OptionDescription'
|
||||||
|
|
Loading…
Reference in New Issue