pylint
This commit is contained in:
parent
13b1e9bf54
commit
a6bafd89bd
|
@ -1,4 +1,3 @@
|
||||||
from typing import List
|
|
||||||
from importlib.machinery import SourceFileLoader
|
from importlib.machinery import SourceFileLoader
|
||||||
|
|
||||||
from .variable import CONVERT_OPTION
|
from .variable import CONVERT_OPTION
|
||||||
|
@ -105,13 +104,13 @@ class ConstrainteAnnotator:
|
||||||
del self.objectspace.space.constraints.check[idx]
|
del self.objectspace.space.constraints.check[idx]
|
||||||
|
|
||||||
def check_replace_text(self):
|
def check_replace_text(self):
|
||||||
for check_idx, check in enumerate(self.objectspace.space.constraints.check):
|
for check in self.objectspace.space.constraints.check:
|
||||||
namespace = check.namespace
|
namespace = check.namespace
|
||||||
if hasattr(check, 'param'):
|
if hasattr(check, 'param'):
|
||||||
for idx, param in enumerate(check.param):
|
for param in check.param:
|
||||||
if param.type == 'variable':
|
if param.type == 'variable':
|
||||||
param.text = self.objectspace.paths.get_variable_path(param.text, namespace)
|
param.text = self.objectspace.paths.get_variable_path(param.text, namespace)
|
||||||
check.is_in_leadership = self.objectspace.paths.get_leader(check.target) != None
|
check.is_in_leadership = self.objectspace.paths.get_leader(check.target) is not None
|
||||||
# let's replace the target by the path
|
# let's replace the target by the path
|
||||||
check.target = self.objectspace.paths.get_variable_path(check.target, namespace)
|
check.target = self.objectspace.paths.get_variable_path(check.target, namespace)
|
||||||
|
|
||||||
|
@ -169,9 +168,9 @@ class ConstrainteAnnotator:
|
||||||
raise DictConsistencyError(_(f'target "{target.type}" not allow in condition "{condition.name}" in {xmlfiles}'), 10)
|
raise DictConsistencyError(_(f'target "{target.type}" not allow in condition "{condition.name}" in {xmlfiles}'), 10)
|
||||||
|
|
||||||
def filter_targets(self): # pylint: disable=C0111
|
def filter_targets(self): # pylint: disable=C0111
|
||||||
for condition_idx, condition in enumerate(self.objectspace.space.constraints.condition):
|
for condition in self.objectspace.space.constraints.condition:
|
||||||
namespace = condition.namespace
|
namespace = condition.namespace
|
||||||
for idx, target in enumerate(condition.target):
|
for target in condition.target:
|
||||||
if target.type == 'variable':
|
if target.type == 'variable':
|
||||||
if condition.source == target.name:
|
if condition.source == target.name:
|
||||||
raise DictConsistencyError(_('target name and source name must be different: {}').format(condition.source), 11)
|
raise DictConsistencyError(_('target name and source name must be different: {}').format(condition.source), 11)
|
||||||
|
@ -191,7 +190,7 @@ class ConstrainteAnnotator:
|
||||||
|
|
||||||
def convert_xxxlist_to_variable(self): # pylint: disable=C0111
|
def convert_xxxlist_to_variable(self): # pylint: disable=C0111
|
||||||
# transform *list to variable or family
|
# transform *list to variable or family
|
||||||
for condition_idx, condition in enumerate(self.objectspace.space.constraints.condition):
|
for condition in self.objectspace.space.constraints.condition:
|
||||||
new_targets = []
|
new_targets = []
|
||||||
remove_targets = []
|
remove_targets = []
|
||||||
for target_idx, target in enumerate(condition.target):
|
for target_idx, target in enumerate(condition.target):
|
||||||
|
@ -240,13 +239,13 @@ class ConstrainteAnnotator:
|
||||||
|
|
||||||
remove_targets = []
|
remove_targets = []
|
||||||
# optional
|
# optional
|
||||||
for idx, target in enumerate(condition.target):
|
for index, target in enumerate(condition.target):
|
||||||
if target.optional is True and not self.objectspace.paths.path_is_defined(target.name):
|
if target.optional is True and not self.objectspace.paths.path_is_defined(target.name):
|
||||||
remove_targets.append(idx)
|
remove_targets.append(index)
|
||||||
remove_targets = list(set(remove_targets))
|
remove_targets = list(set(remove_targets))
|
||||||
remove_targets.sort(reverse=True)
|
remove_targets.sort(reverse=True)
|
||||||
for idx in remove_targets:
|
for index in remove_targets:
|
||||||
condition.target.pop(idx)
|
condition.target.pop(index)
|
||||||
remove_conditions = list(set(remove_conditions))
|
remove_conditions = list(set(remove_conditions))
|
||||||
remove_conditions.sort(reverse=True)
|
remove_conditions.sort(reverse=True)
|
||||||
for idx in remove_conditions:
|
for idx in remove_conditions:
|
||||||
|
@ -255,11 +254,11 @@ class ConstrainteAnnotator:
|
||||||
def _get_condition_actions(self, condition_name):
|
def _get_condition_actions(self, condition_name):
|
||||||
if condition_name.startswith('disabled_if_'):
|
if condition_name.startswith('disabled_if_'):
|
||||||
return ['disabled']
|
return ['disabled']
|
||||||
elif condition_name.startswith('hidden_if_'):
|
if condition_name.startswith('hidden_if_'):
|
||||||
return ['hidden', 'frozen', 'force_default_on_freeze']
|
return ['hidden', 'frozen', 'force_default_on_freeze']
|
||||||
elif condition_name.startswith('mandatory_if_'):
|
if condition_name.startswith('mandatory_if_'):
|
||||||
return ['mandatory']
|
return ['mandatory']
|
||||||
elif condition_name == 'auto_hidden_if_not_in':
|
if condition_name == 'auto_hidden_if_not_in':
|
||||||
return ['auto_frozen']
|
return ['auto_frozen']
|
||||||
|
|
||||||
def check_choice_option_condition(self):
|
def check_choice_option_condition(self):
|
||||||
|
@ -275,7 +274,6 @@ class ConstrainteAnnotator:
|
||||||
if suffix:
|
if suffix:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
||||||
raise DictConsistencyError(_(f'the source "{condition.source}" in condition cannot be a dynamic variable in {xmlfiles}'), 20)
|
raise DictConsistencyError(_(f'the source "{condition.source}" in condition cannot be a dynamic variable in {xmlfiles}'), 20)
|
||||||
src_variable = self.objectspace.paths.get_variable_obj(condition.source)
|
|
||||||
valid_enum = None
|
valid_enum = None
|
||||||
# FIXME only string?
|
# FIXME only string?
|
||||||
if condition.source in self.valid_enums and self.valid_enums[condition.source]['type'] == 'string':
|
if condition.source in self.valid_enums and self.valid_enums[condition.source]['type'] == 'string':
|
||||||
|
|
|
@ -6,7 +6,7 @@ from ..error import DictConsistencyError
|
||||||
modes_level = ('basic', 'normal', 'expert')
|
modes_level = ('basic', 'normal', 'expert')
|
||||||
|
|
||||||
|
|
||||||
class Mode(object):
|
class Mode:
|
||||||
def __init__(self, name, level):
|
def __init__(self, name, level):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.level = level
|
self.level = level
|
||||||
|
@ -40,8 +40,8 @@ class FamilyAnnotator:
|
||||||
if hasattr(family, 'family'):
|
if hasattr(family, 'family'):
|
||||||
space = family.family
|
space = family.family
|
||||||
removed_families = []
|
removed_families = []
|
||||||
for family_name, family in space.items():
|
for family_name, sfamily in space.items():
|
||||||
if not hasattr(family, 'variable') or len(family.variable) == 0:
|
if not hasattr(sfamily, 'variable') or len(sfamily.variable) == 0:
|
||||||
removed_families.append(family_name)
|
removed_families.append(family_name)
|
||||||
for family_name in removed_families:
|
for family_name in removed_families:
|
||||||
del space[family_name]
|
del space[family_name]
|
||||||
|
@ -51,9 +51,9 @@ class FamilyAnnotator:
|
||||||
return
|
return
|
||||||
for family in self.objectspace.space.variables.values():
|
for family in self.objectspace.space.variables.values():
|
||||||
if hasattr(family, 'family'):
|
if hasattr(family, 'family'):
|
||||||
for family in family.family.values():
|
for vfamily in family.family.values():
|
||||||
mode = modes_level[-1]
|
mode = modes_level[-1]
|
||||||
for variable in family.variable.values():
|
for variable in vfamily.variable.values():
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
if isinstance(variable, self.objectspace.leadership):
|
||||||
variable_mode = variable.variable[0].mode
|
variable_mode = variable.variable[0].mode
|
||||||
variable.variable[0].mode = None
|
variable.variable[0].mode = None
|
||||||
|
@ -62,24 +62,28 @@ class FamilyAnnotator:
|
||||||
variable_mode = variable.mode
|
variable_mode = variable.mode
|
||||||
if variable_mode is not None and modes[mode] > modes[variable_mode]:
|
if variable_mode is not None and modes[mode] > modes[variable_mode]:
|
||||||
mode = variable_mode
|
mode = variable_mode
|
||||||
family.mode = mode
|
vfamily.mode = mode
|
||||||
|
|
||||||
def dynamic_families(self): # pylint: disable=C0111
|
def dynamic_families(self): # pylint: disable=C0111
|
||||||
if not hasattr(self.objectspace.space, 'variables'):
|
if not hasattr(self.objectspace.space, 'variables'):
|
||||||
return
|
return
|
||||||
for family in self.objectspace.space.variables.values():
|
for family in self.objectspace.space.variables.values():
|
||||||
if hasattr(family, 'family'):
|
if hasattr(family, 'family'):
|
||||||
for family in family.family.values():
|
for vfamily in family.family.values():
|
||||||
if 'dynamic' in vars(family):
|
if 'dynamic' in vars(vfamily):
|
||||||
namespace = self.objectspace.paths.get_variable_namespace(family.dynamic)
|
namespace = self.objectspace.paths.get_variable_namespace(vfamily.dynamic)
|
||||||
varpath = self.objectspace.paths.get_variable_path(family.dynamic, namespace)
|
varpath = self.objectspace.paths.get_variable_path(vfamily.dynamic, namespace)
|
||||||
obj = self.objectspace.paths.get_variable_obj(varpath)
|
obj = self.objectspace.paths.get_variable_obj(varpath)
|
||||||
if not obj.multi:
|
if not obj.multi:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(family.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(vfamily.xmlfiles)
|
||||||
raise DictConsistencyError(_(f'dynamic family "{family.name}" must be linked to multi variable in {xmlfiles}'), 16)
|
raise DictConsistencyError(_(f'dynamic family "{vfamily.name}" must be linked to multi variable in {xmlfiles}'), 16)
|
||||||
family.dynamic = varpath
|
vfamily.dynamic = varpath
|
||||||
|
|
||||||
def annotate_variable(self, variable, family_mode, path, is_follower=False):
|
def annotate_variable(self,
|
||||||
|
variable,
|
||||||
|
family_mode: str,
|
||||||
|
is_follower=False,
|
||||||
|
) -> None:
|
||||||
# if the variable is mandatory and doesn't have any value
|
# if the variable is mandatory and doesn't have any value
|
||||||
# then the variable's mode is set to 'basic'
|
# then the variable's mode is set to 'basic'
|
||||||
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
||||||
|
@ -92,21 +96,16 @@ class FamilyAnnotator:
|
||||||
for value in variable.value:
|
for value in variable.value:
|
||||||
if value.type == 'calculation':
|
if value.type == 'calculation':
|
||||||
has_value = False
|
has_value = False
|
||||||
has_variable = False
|
|
||||||
if hasattr(value, 'param'):
|
if hasattr(value, 'param'):
|
||||||
for param in value.param:
|
for param in value.param:
|
||||||
if param.type == 'variable':
|
if param.type == 'variable':
|
||||||
has_variable = True
|
|
||||||
break
|
break
|
||||||
#if not has_variable:
|
|
||||||
# # if one parameter is a variable, let variable choice if it's mandatory
|
|
||||||
# variable.mandatory = True
|
|
||||||
if has_value:
|
if has_value:
|
||||||
# if has value but without any calculation
|
# if has value but without any calculation
|
||||||
variable.mandatory = True
|
variable.mandatory = True
|
||||||
if variable.mandatory is True and (not hasattr(variable, 'value') or is_follower):
|
if variable.mandatory is True and (not hasattr(variable, 'value') or is_follower):
|
||||||
variable.mode = modes_level[0]
|
variable.mode = modes_level[0]
|
||||||
if variable.mode != None and modes[variable.mode] < modes[family_mode] and (not is_follower or variable.mode != modes_level[0]):
|
if variable.mode is not None and modes[variable.mode] < modes[family_mode] and (not is_follower or variable.mode != modes_level[0]):
|
||||||
variable.mode = family_mode
|
variable.mode = family_mode
|
||||||
if variable.hidden is True:
|
if variable.hidden is True:
|
||||||
variable.frozen = True
|
variable.frozen = True
|
||||||
|
@ -117,7 +116,6 @@ class FamilyAnnotator:
|
||||||
if not hasattr(self.objectspace.space, 'variables'):
|
if not hasattr(self.objectspace.space, 'variables'):
|
||||||
return
|
return
|
||||||
for variables in self.objectspace.space.variables.values():
|
for variables in self.objectspace.space.variables.values():
|
||||||
namespace = variables.name
|
|
||||||
if hasattr(variables, 'family'):
|
if hasattr(variables, 'family'):
|
||||||
for family in variables.family.values():
|
for family in variables.family.values():
|
||||||
family_mode = family.mode
|
family_mode = family.mode
|
||||||
|
@ -125,7 +123,6 @@ class FamilyAnnotator:
|
||||||
for variable in family.variable.values():
|
for variable in family.variable.values():
|
||||||
|
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
if isinstance(variable, self.objectspace.leadership):
|
||||||
mode = modes_level[-1]
|
|
||||||
for idx, follower in enumerate(variable.variable):
|
for idx, follower in enumerate(variable.variable):
|
||||||
if follower.auto_save is True:
|
if follower.auto_save is True:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||||
|
@ -134,8 +131,10 @@ class FamilyAnnotator:
|
||||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||||
raise DictConsistencyError(_(f'leader/followers "{follower.name}" could not be auto_freeze in {xmlfiles}'), 30)
|
raise DictConsistencyError(_(f'leader/followers "{follower.name}" could not be auto_freeze in {xmlfiles}'), 30)
|
||||||
is_follower = idx != 0
|
is_follower = idx != 0
|
||||||
path = '{}.{}.{}'.format(family.path, variable.name, follower.name)
|
self.annotate_variable(follower,
|
||||||
self.annotate_variable(follower, family_mode, path, is_follower)
|
family_mode,
|
||||||
|
is_follower,
|
||||||
|
)
|
||||||
# leader's mode is minimum level
|
# leader's mode is minimum level
|
||||||
if modes[variable.variable[0].mode] > modes[follower.mode]:
|
if modes[variable.variable[0].mode] > modes[follower.mode]:
|
||||||
follower.mode = variable.variable[0].mode
|
follower.mode = variable.variable[0].mode
|
||||||
|
@ -147,6 +146,6 @@ class FamilyAnnotator:
|
||||||
# auto_freeze's variable is set in 'basic' mode if its mode is 'normal'
|
# auto_freeze's variable is set in 'basic' mode if its mode is 'normal'
|
||||||
if variable.auto_freeze is True and variable.mode != modes_level[-1]:
|
if variable.auto_freeze is True and variable.mode != modes_level[-1]:
|
||||||
variable.mode = modes_level[0]
|
variable.mode = modes_level[0]
|
||||||
path = '{}.{}'.format(family.path, variable.name)
|
self.annotate_variable(variable,
|
||||||
self.annotate_variable(variable, family_mode, path)
|
family_mode,
|
||||||
|
)
|
||||||
|
|
|
@ -136,4 +136,3 @@ class GroupAnnotator:
|
||||||
variable.name,
|
variable.name,
|
||||||
leader_name,
|
leader_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class PropertyAnnotator:
|
||||||
properties = []
|
properties = []
|
||||||
for prop in PROPERTIES:
|
for prop in PROPERTIES:
|
||||||
if hasattr(variable, prop):
|
if hasattr(variable, prop):
|
||||||
if getattr(variable, prop) == True:
|
if getattr(variable, prop) is True:
|
||||||
for subprop in CONVERT_PROPERTIES.get(prop, [prop]):
|
for subprop in CONVERT_PROPERTIES.get(prop, [prop]):
|
||||||
properties.append(subprop)
|
properties.append(subprop)
|
||||||
setattr(variable, prop, None)
|
setattr(variable, prop, None)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class ServiceAnnotator:
|
||||||
self.objectspace.space.services.name = 'services'
|
self.objectspace.space.services.name = 'services'
|
||||||
self.objectspace.space.services.doc = 'services'
|
self.objectspace.space.services.doc = 'services'
|
||||||
families = {}
|
families = {}
|
||||||
for idx, service_name in enumerate(self.objectspace.space.services.service.keys()):
|
for service_name in self.objectspace.space.services.service.keys():
|
||||||
service = self.objectspace.space.services.service[service_name]
|
service = self.objectspace.space.services.service[service_name]
|
||||||
new_service = self.objectspace.service(service.xmlfiles)
|
new_service = self.objectspace.service(service.xmlfiles)
|
||||||
for elttype, values in vars(service).items():
|
for elttype, values in vars(service).items():
|
||||||
|
|
|
@ -141,7 +141,7 @@ class VariableAnnotator:
|
||||||
if not hasattr(family, 'separators'):
|
if not hasattr(family, 'separators'):
|
||||||
continue
|
continue
|
||||||
if hasattr(family.separators, 'separator'):
|
if hasattr(family.separators, 'separator'):
|
||||||
for idx, separator in enumerate(family.separators.separator):
|
for separator in family.separators.separator:
|
||||||
option = self.objectspace.paths.get_variable_obj(separator.name)
|
option = self.objectspace.paths.get_variable_obj(separator.name)
|
||||||
if hasattr(option, 'separator'):
|
if hasattr(option, 'separator'):
|
||||||
subpath = self.objectspace.paths.get_variable_path(separator.name,
|
subpath = self.objectspace.paths.get_variable_path(separator.name,
|
||||||
|
@ -151,4 +151,3 @@ class VariableAnnotator:
|
||||||
raise DictConsistencyError(_(f'{subpath} already has a separator in {xmlfiles}'), 35)
|
raise DictConsistencyError(_(f'{subpath} already has a separator in {xmlfiles}'), 35)
|
||||||
option.separator = separator.text
|
option.separator = separator.text
|
||||||
del family.separators
|
del family.separators
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,15 @@ fichier de configuration pour rougail
|
||||||
from os.path import join, abspath, dirname
|
from os.path import join, abspath, dirname
|
||||||
|
|
||||||
|
|
||||||
rougailroot = '/var/rougail'
|
ROUGAILROOT = '/var/rougail'
|
||||||
dtddir = join(dirname(abspath(__file__)), 'data')
|
DTDDIR = join(dirname(abspath(__file__)), 'data')
|
||||||
|
|
||||||
|
|
||||||
Config = {'rougailroot': rougailroot,
|
Config = {'rougailroot': ROUGAILROOT,
|
||||||
'patch_dir': join(rougailroot, 'patches'),
|
'patch_dir': join(ROUGAILROOT, 'patches'),
|
||||||
'manifests_dir': join(rougailroot, 'manifests'),
|
'manifests_dir': join(ROUGAILROOT, 'manifests'),
|
||||||
'templates_dir': join(rougailroot, 'templates'),
|
'templates_dir': join(ROUGAILROOT, 'templates'),
|
||||||
'dtdfilename': join(dtddir, 'rougail.dtd'),
|
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
|
||||||
'dtddir': dtddir,
|
'dtddir': DTDDIR,
|
||||||
# chemin du répertoire source des fichiers templates
|
|
||||||
'patch_dir': '/srv/rougail/patch',
|
|
||||||
'variable_namespace': 'rougail',
|
'variable_namespace': 'rougail',
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ class TemplateError(ConfigError):
|
||||||
class TemplateDisabled(TemplateError):
|
class TemplateDisabled(TemplateError):
|
||||||
"""Template is disabled.
|
"""Template is disabled.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class OperationError(Exception):
|
class OperationError(Exception):
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .xmlreflector import XMLReflector
|
from .xmlreflector import XMLReflector
|
||||||
from .utils import normalize_family
|
from .utils import normalize_family
|
||||||
|
@ -111,7 +108,6 @@ class RougailObjSpace:
|
||||||
if name.endswith('_'):
|
if name.endswith('_'):
|
||||||
name = name[:-1]
|
name = name[:-1]
|
||||||
setattr(self, elt, type(name, (RootRougailObject,), dict()))
|
setattr(self, elt, type(name, (RootRougailObject,), dict()))
|
||||||
self.Leadership = self.leadership
|
|
||||||
|
|
||||||
def display_xmlfiles(self,
|
def display_xmlfiles(self,
|
||||||
xmlfiles: list,
|
xmlfiles: list,
|
||||||
|
@ -165,8 +161,7 @@ class RougailObjSpace:
|
||||||
self.remove(child,
|
self.remove(child,
|
||||||
variableobj,
|
variableobj,
|
||||||
)
|
)
|
||||||
self.set_path(space,
|
self.set_path(child,
|
||||||
child,
|
|
||||||
namespace,
|
namespace,
|
||||||
document,
|
document,
|
||||||
variableobj,
|
variableobj,
|
||||||
|
@ -200,7 +195,7 @@ class RougailObjSpace:
|
||||||
child,
|
child,
|
||||||
namespace,
|
namespace,
|
||||||
)
|
)
|
||||||
elif Atom in obj.__mro__:
|
if Atom in obj.__mro__:
|
||||||
if child.tag in vars(space):
|
if child.tag in vars(space):
|
||||||
# Atom instance has to be a singleton here
|
# Atom instance has to be a singleton here
|
||||||
# we do not re-create it, we reuse it
|
# we do not re-create it, we reuse it
|
||||||
|
@ -368,7 +363,6 @@ class RougailObjSpace:
|
||||||
self.space.constraints.fill.pop(idx)
|
self.space.constraints.fill.pop(idx)
|
||||||
|
|
||||||
def set_path(self,
|
def set_path(self,
|
||||||
space,
|
|
||||||
child,
|
child,
|
||||||
namespace,
|
namespace,
|
||||||
document,
|
document,
|
||||||
|
@ -382,7 +376,7 @@ class RougailObjSpace:
|
||||||
self.paths.add_variable(namespace,
|
self.paths.add_variable(namespace,
|
||||||
child.attrib['name'],
|
child.attrib['name'],
|
||||||
family_name,
|
family_name,
|
||||||
document.attrib.get('dynamic') != None,
|
document.attrib.get('dynamic') is not None,
|
||||||
variableobj,
|
variableobj,
|
||||||
)
|
)
|
||||||
if child.attrib.get('redefine', 'False') == 'True':
|
if child.attrib.get('redefine', 'False') == 'True':
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .utils import normalize_family
|
|
||||||
from .error import OperationError, DictConsistencyError
|
from .error import OperationError, DictConsistencyError
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ class Path:
|
||||||
else:
|
else:
|
||||||
dico = self._get_variable(name)
|
dico = self._get_variable(name)
|
||||||
if not allow_source and dico['namespace'] not in [Config['variable_namespace'], 'services'] and current_namespace != dico['namespace']:
|
if not allow_source and dico['namespace'] not in [Config['variable_namespace'], 'services'] and current_namespace != dico['namespace']:
|
||||||
raise DictConsistencyError(_(f'A variable located in the "{dico["namespace"]}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
raise DictConsistencyError(_(f'A variable located in the "{dico["namespace"]}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
||||||
list_path = [dico['namespace'], dico['family']]
|
list_path = [dico['namespace'], dico['family']]
|
||||||
if dico['leader'] is not None:
|
if dico['leader'] is not None:
|
||||||
list_path.append(dico['leader'])
|
list_path.append(dico['leader'])
|
||||||
|
|
|
@ -18,7 +18,7 @@ from Cheetah.NameMapper import NotFound as CheetahNotFound
|
||||||
try:
|
try:
|
||||||
from tiramisu3 import Config
|
from tiramisu3 import Config
|
||||||
from tiramisu3.error import PropertiesOptionError # pragma: no cover
|
from tiramisu3.error import PropertiesOptionError # pragma: no cover
|
||||||
except: # pragma: no cover
|
except ModuleNotFoundError: # pragma: no cover
|
||||||
from tiramisu import Config
|
from tiramisu import Config
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
|
|
||||||
|
@ -212,8 +212,8 @@ class CreoleTemplateEngine:
|
||||||
if eosfunc_file is not None:
|
if eosfunc_file is not None:
|
||||||
eosfunc = SourceFileLoader('eosfunc', eosfunc_file).load_module()
|
eosfunc = SourceFileLoader('eosfunc', eosfunc_file).load_module()
|
||||||
for func in dir(eosfunc):
|
for func in dir(eosfunc):
|
||||||
if not func.startswith('_'):
|
if not func.startswith('_'):
|
||||||
eos[func] = getattr(eosfunc, func)
|
eos[func] = getattr(eosfunc, func)
|
||||||
self.eosfunc = eos
|
self.eosfunc = eos
|
||||||
self.rougail_variables_dict = {}
|
self.rougail_variables_dict = {}
|
||||||
|
|
||||||
|
@ -238,8 +238,8 @@ class CreoleTemplateEngine:
|
||||||
self.rougail_variables_dict[await option.option.name()] = await option.value.get()
|
self.rougail_variables_dict[await option.option.name()] = await option.value.get()
|
||||||
|
|
||||||
async def load_eole_variables(self,
|
async def load_eole_variables(self,
|
||||||
namespace,
|
optiondescription,
|
||||||
optiondescription):
|
):
|
||||||
families = {}
|
families = {}
|
||||||
for family in await optiondescription.list('all'):
|
for family in await optiondescription.list('all'):
|
||||||
variables = {}
|
variables = {}
|
||||||
|
@ -257,9 +257,7 @@ class CreoleTemplateEngine:
|
||||||
)
|
)
|
||||||
variables[leader_name] = leader
|
variables[leader_name] = leader
|
||||||
else:
|
else:
|
||||||
subfamilies = await self.load_eole_variables(await variable.option.name(),
|
subfamilies = await self.load_eole_variables(variable)
|
||||||
variable,
|
|
||||||
)
|
|
||||||
variables[await variable.option.name()] = subfamilies
|
variables[await variable.option.name()] = subfamilies
|
||||||
else:
|
else:
|
||||||
variables[await variable.option.name()] = await variable.value.get()
|
variables[await variable.option.name()] = await variable.value.get()
|
||||||
|
@ -301,7 +299,6 @@ class CreoleTemplateEngine:
|
||||||
source: str,
|
source: str,
|
||||||
true_destfilename: str,
|
true_destfilename: str,
|
||||||
destfilename: str,
|
destfilename: str,
|
||||||
filevar: Dict,
|
|
||||||
variable: Any,
|
variable: Any,
|
||||||
):
|
):
|
||||||
"""Process a cheetah template
|
"""Process a cheetah template
|
||||||
|
@ -327,7 +324,6 @@ class CreoleTemplateEngine:
|
||||||
|
|
||||||
def instance_file(self,
|
def instance_file(self,
|
||||||
filevar: Dict,
|
filevar: Dict,
|
||||||
service_name: str,
|
|
||||||
tmp_dir: str,
|
tmp_dir: str,
|
||||||
dest_dir: str,
|
dest_dir: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -355,8 +351,8 @@ class CreoleTemplateEngine:
|
||||||
self.process(source,
|
self.process(source,
|
||||||
filename,
|
filename,
|
||||||
destfilename,
|
destfilename,
|
||||||
filevar,
|
var,
|
||||||
var)
|
)
|
||||||
else:
|
else:
|
||||||
copy(source, destfilename)
|
copy(source, destfilename)
|
||||||
|
|
||||||
|
@ -373,13 +369,11 @@ class CreoleTemplateEngine:
|
||||||
if namespace == Config['variable_namespace']:
|
if namespace == Config['variable_namespace']:
|
||||||
await self.load_eole_variables_rougail(option)
|
await self.load_eole_variables_rougail(option)
|
||||||
else:
|
else:
|
||||||
families = await self.load_eole_variables(namespace,
|
families = await self.load_eole_variables(option)
|
||||||
option)
|
|
||||||
self.rougail_variables_dict[namespace] = families
|
self.rougail_variables_dict[namespace] = families
|
||||||
for template in listdir('.'):
|
for template in listdir('.'):
|
||||||
self.prepare_template(template, tmp_dir, patch_dir)
|
self.prepare_template(template, tmp_dir, patch_dir)
|
||||||
for service_obj in await self.config.option('services').list('all'):
|
for service_obj in await self.config.option('services').list('all'):
|
||||||
service_name = await service_obj.option.doc()
|
|
||||||
for fills in await service_obj.list('all'):
|
for fills in await service_obj.list('all'):
|
||||||
if await fills.option.name() in ['files', 'overrides']:
|
if await fills.option.name() in ['files', 'overrides']:
|
||||||
for fill_obj in await fills.list('all'):
|
for fill_obj in await fills.list('all'):
|
||||||
|
@ -389,7 +383,6 @@ class CreoleTemplateEngine:
|
||||||
raise FileNotFound(_(f"File {filename} does not exist."))
|
raise FileNotFound(_(f"File {filename} does not exist."))
|
||||||
if fill.get('activate', False):
|
if fill.get('activate', False):
|
||||||
self.instance_file(fill,
|
self.instance_file(fill,
|
||||||
service_name,
|
|
||||||
tmp_dir,
|
tmp_dir,
|
||||||
dest_dir,
|
dest_dir,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
try:
|
try:
|
||||||
from tiramisu3 import DynOptionDescription
|
from tiramisu3 import DynOptionDescription
|
||||||
except:
|
except ModuleNotFoundError:
|
||||||
from tiramisu import DynOptionDescription
|
from tiramisu import DynOptionDescription
|
||||||
from .utils import normalize_family
|
from .utils import normalize_family
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,6 @@ class ElementStorage:
|
||||||
|
|
||||||
class Common:
|
class Common:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
elt,
|
|
||||||
storage,
|
storage,
|
||||||
is_leader,
|
is_leader,
|
||||||
path,
|
path,
|
||||||
|
@ -206,7 +205,7 @@ class Common:
|
||||||
self.attrib['properties'] += ', '
|
self.attrib['properties'] += ', '
|
||||||
self.attrib['properties'] += prop
|
self.attrib['properties'] += prop
|
||||||
|
|
||||||
def get_attrib(self, attrib):
|
def get_attrib(self):
|
||||||
ret_list = []
|
ret_list = []
|
||||||
for key, value in self.attrib.items():
|
for key, value in self.attrib.items():
|
||||||
if value is None:
|
if value is None:
|
||||||
|
@ -261,8 +260,7 @@ class Variable(Common):
|
||||||
is_leader,
|
is_leader,
|
||||||
path,
|
path,
|
||||||
):
|
):
|
||||||
super().__init__(elt,
|
super().__init__(storage,
|
||||||
storage,
|
|
||||||
is_leader,
|
is_leader,
|
||||||
path,
|
path,
|
||||||
)
|
)
|
||||||
|
@ -283,7 +281,7 @@ class Variable(Common):
|
||||||
self.attrib['opt'] = self.storage.get(self.attrib['opt']).get()
|
self.attrib['opt'] = self.storage.get(self.attrib['opt']).get()
|
||||||
else:
|
else:
|
||||||
self.parse_children()
|
self.parse_children()
|
||||||
attrib = self.get_attrib(self.attrib)
|
attrib = self.get_attrib()
|
||||||
self.option_name = self.storage.get_name(self.path)
|
self.option_name = self.storage.get_name(self.path)
|
||||||
self.storage.text.append(f'{self.option_name} = {self.object_type}({attrib})')
|
self.storage.text.append(f'{self.option_name} = {self.object_type}({attrib})')
|
||||||
self.populate_informations()
|
self.populate_informations()
|
||||||
|
@ -304,7 +302,7 @@ class Variable(Common):
|
||||||
self.attrib[key] = value
|
self.attrib[key] = value
|
||||||
|
|
||||||
def parse_children(self):
|
def parse_children(self):
|
||||||
if not 'default' in self.attrib or self.attrib['multi']:
|
if 'default' not in self.attrib or self.attrib['multi']:
|
||||||
self.attrib['default'] = []
|
self.attrib['default'] = []
|
||||||
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'] = []
|
||||||
|
@ -367,9 +365,9 @@ class Variable(Common):
|
||||||
):
|
):
|
||||||
if param.type == 'string':
|
if param.type == 'string':
|
||||||
return f'ParamValue("{param.text}")'
|
return f'ParamValue("{param.text}")'
|
||||||
elif param.type == 'number':
|
if param.type == 'number':
|
||||||
return f'ParamValue({param.text})'
|
return f'ParamValue({param.text})'
|
||||||
elif param.type == 'variable':
|
if param.type == 'variable':
|
||||||
value = {'option': param.text,
|
value = {'option': param.text,
|
||||||
'notraisepropertyerror': param.notraisepropertyerror,
|
'notraisepropertyerror': param.notraisepropertyerror,
|
||||||
'todict': function in FUNC_TO_DICT,
|
'todict': function in FUNC_TO_DICT,
|
||||||
|
@ -377,10 +375,10 @@ class Variable(Common):
|
||||||
if hasattr(param, 'suffix'):
|
if hasattr(param, 'suffix'):
|
||||||
value['suffix'] = param.suffix
|
value['suffix'] = param.suffix
|
||||||
return self.build_param(value)
|
return self.build_param(value)
|
||||||
elif param.type == 'information':
|
if param.type == 'information':
|
||||||
return f'ParamInformation("{param.text}", None)'
|
return f'ParamInformation("{param.text}", None)'
|
||||||
elif param.type == 'suffix':
|
if param.type == 'suffix':
|
||||||
return f'ParamSuffix()'
|
return 'ParamSuffix()'
|
||||||
raise LoaderError(_('unknown param type {}').format(param.type)) # pragma: no cover
|
raise LoaderError(_('unknown param type {}').format(param.type)) # pragma: no cover
|
||||||
|
|
||||||
def populate_value(self,
|
def populate_value(self,
|
||||||
|
@ -418,8 +416,7 @@ class Family(Common):
|
||||||
is_leader,
|
is_leader,
|
||||||
path,
|
path,
|
||||||
):
|
):
|
||||||
super().__init__(elt,
|
super().__init__(storage,
|
||||||
storage,
|
|
||||||
is_leader,
|
is_leader,
|
||||||
path,
|
path,
|
||||||
)
|
)
|
||||||
|
@ -435,7 +432,7 @@ class Family(Common):
|
||||||
self.parse_children()
|
self.parse_children()
|
||||||
self.option_name = self.storage.get_name(self.path)
|
self.option_name = self.storage.get_name(self.path)
|
||||||
object_name = self.get_object_name()
|
object_name = self.get_object_name()
|
||||||
attrib = self.get_attrib(self.attrib) + ', children=[' + ', '.join([child.get() for child in self.children]) + ']'
|
attrib = self.get_attrib() + ', children=[' + ', '.join([child.get() for child in self.children]) + ']'
|
||||||
self.storage.text.append(f'{self.option_name} = {object_name}({attrib})')
|
self.storage.text.append(f'{self.option_name} = {object_name}({attrib})')
|
||||||
self.populate_informations()
|
self.populate_informations()
|
||||||
return self.option_name
|
return self.option_name
|
||||||
|
@ -461,6 +458,6 @@ class Family(Common):
|
||||||
def get_object_name(self):
|
def get_object_name(self):
|
||||||
if 'suffixes' in self.attrib:
|
if 'suffixes' in self.attrib:
|
||||||
return 'ConvertDynOptionDescription'
|
return 'ConvertDynOptionDescription'
|
||||||
elif not self.is_leader:
|
if not self.is_leader:
|
||||||
return 'OptionDescription'
|
return 'OptionDescription'
|
||||||
return 'Leadership'
|
return 'Leadership'
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
utilitaires créole
|
utilitaires créole
|
||||||
"""
|
"""
|
||||||
from unicodedata import normalize, combining
|
from unicodedata import normalize, combining
|
||||||
from .i18n import _
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_family(family_name: str) -> str:
|
def normalize_family(family_name: str) -> str:
|
||||||
|
|
|
@ -3,13 +3,13 @@ from typing import List
|
||||||
from os.path import join, isfile
|
from os.path import join, isfile
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
|
||||||
from lxml.etree import DTD, parse, tostring, XMLSyntaxError
|
from lxml.etree import DTD, parse, XMLSyntaxError
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .error import DictConsistencyError
|
from .error import DictConsistencyError
|
||||||
|
|
||||||
|
|
||||||
class XMLReflector(object):
|
class XMLReflector:
|
||||||
"""Helper class for loading the Creole XML file,
|
"""Helper class for loading the Creole XML file,
|
||||||
parsing it, validating against the Creole DTD,
|
parsing it, validating against the Creole DTD,
|
||||||
writing the xml result on the disk
|
writing the xml result on the disk
|
||||||
|
|
Loading…
Reference in New Issue