pylint path.py
This commit is contained in:
parent
f0ba368f2a
commit
0aba66b8b5
|
@ -36,7 +36,8 @@ class PropertyAnnotator:
|
|||
if hasattr(variable, 'mode') and variable.mode:
|
||||
properties.append(variable.mode)
|
||||
variable.mode = None
|
||||
if 'force_store_value' in properties and 'force_default_on_freeze' in properties:
|
||||
if 'force_store_value' in properties and 'force_default_on_freeze' in properties: # pragma: no cover
|
||||
# should not appened
|
||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||
msg = _('cannot have auto_freeze or auto_store with the hidden '
|
||||
f'variable "{variable.name}" in {xmlfiles}')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Manage path to find objects
|
||||
"""
|
||||
from .i18n import _
|
||||
from .error import DictConsistencyError
|
||||
from .config import Config
|
||||
|
@ -22,12 +24,15 @@ class Path:
|
|||
name: str,
|
||||
variableobj: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Add a new family
|
||||
"""
|
||||
if namespace == Config['variable_namespace']:
|
||||
full_name = '.'.join([namespace, name])
|
||||
self.full_paths_families[name] = full_name
|
||||
else:
|
||||
if '.' not in name:
|
||||
raise DictConsistencyError(_(f'Variable "{name}" in namespace "{namespace}" must have dot'), 39)
|
||||
if '.' not in name: # pragma: no cover
|
||||
msg = _(f'Variable "{name}" in namespace "{namespace}" must have dot')
|
||||
raise DictConsistencyError(msg, 39)
|
||||
full_name = name
|
||||
if full_name in self.families and \
|
||||
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
|
||||
|
@ -43,6 +48,8 @@ class Path:
|
|||
path: str,
|
||||
variableobj: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""add a new leadership
|
||||
"""
|
||||
self.families[path] = dict(name=path,
|
||||
namespace=namespace,
|
||||
variableobj=variableobj,
|
||||
|
@ -53,14 +60,19 @@ class Path:
|
|||
name: str,
|
||||
current_namespace: str,
|
||||
) -> 'Family': # pylint: disable=C0111
|
||||
"""Get a family
|
||||
"""
|
||||
name = '.'.join([normalize_family(subname) for subname in name.split('.')])
|
||||
if name not in self.families and name in self.full_paths_families:
|
||||
name = self.full_paths_families[name]
|
||||
if name not in self.families:
|
||||
raise DictConsistencyError(_('unknown option {}').format(name), 42)
|
||||
dico = self.families[name]
|
||||
if current_namespace not in [Config['variable_namespace'], 'services'] and current_namespace != dico['namespace']:
|
||||
raise DictConsistencyError(_(f'A family located in the "{dico["namespace"]}" namespace shall not be used in the "{current_namespace}" namespace'), 38)
|
||||
if current_namespace not in [Config['variable_namespace'], 'services'] and \
|
||||
current_namespace != dico['namespace']:
|
||||
msg = _(f'A family located in the "{dico["namespace"]}" namespace '
|
||||
f'shall not be used in the "{current_namespace}" namespace')
|
||||
raise DictConsistencyError(msg, 38)
|
||||
return dico['variableobj']
|
||||
|
||||
# Leadership
|
||||
|
@ -70,6 +82,8 @@ class Path:
|
|||
leadership_name: str,
|
||||
name: str,
|
||||
) -> None: # pylint: disable=C0111
|
||||
"""set a variable a leadership member
|
||||
"""
|
||||
# need rebuild path and move object in new path
|
||||
old_path = leader_family_name + '.' + name
|
||||
leadership_path = leader_family_name + '.' + leadership_name
|
||||
|
@ -82,9 +96,13 @@ class Path:
|
|||
self.full_paths_variables[name] = new_path
|
||||
|
||||
def is_in_leadership(self, name):
|
||||
"""Is the variable is in a leadership
|
||||
"""
|
||||
return self._get_variable(name)['leader'] is not None
|
||||
|
||||
def is_leader(self, path): # pylint: disable=C0111
|
||||
"""Is the variable is a leader
|
||||
"""
|
||||
variable = self._get_variable(path)
|
||||
if not variable['leader']:
|
||||
return False
|
||||
|
@ -99,6 +117,8 @@ class Path:
|
|||
is_dynamic: bool,
|
||||
variableobj,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Add a new variable (with path)
|
||||
"""
|
||||
if '.' not in name:
|
||||
full_path = '.'.join([family, name])
|
||||
if namespace == Config['variable_namespace']:
|
||||
|
@ -116,6 +136,8 @@ class Path:
|
|||
def get_variable(self,
|
||||
name: str,
|
||||
) -> 'Variable': # pylint: disable=C0111
|
||||
"""Get variable object from a path
|
||||
"""
|
||||
variable, suffix = self._get_variable(name, with_suffix=True)
|
||||
if suffix:
|
||||
raise DictConsistencyError(_(f"{name} is a dynamic variable"), 36)
|
||||
|
@ -124,30 +146,41 @@ class Path:
|
|||
def get_variable_family_path(self,
|
||||
name: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""Get the full path of a family
|
||||
"""
|
||||
return self._get_variable(name)['family']
|
||||
|
||||
def get_variable_path(self,
|
||||
name: str,
|
||||
current_namespace: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
"""get full path of a variable
|
||||
"""
|
||||
dico, suffix = self._get_variable(name,
|
||||
with_suffix=True,
|
||||
)
|
||||
namespace = dico['variableobj'].namespace
|
||||
if namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace:
|
||||
raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41)
|
||||
if namespace not in [Config['variable_namespace'], 'services'] and \
|
||||
current_namespace != namespace:
|
||||
msg = _(f'A variable located in the "{namespace}" namespace shall not be used '
|
||||
f'in the "{current_namespace}" namespace')
|
||||
raise DictConsistencyError(msg, 41)
|
||||
return dico['variableobj'].path, suffix
|
||||
|
||||
def path_is_defined(self,
|
||||
name: str,
|
||||
path: str,
|
||||
) -> str: # pylint: disable=C0111
|
||||
if '.' not in name and name not in self.variables and name in self.full_paths_variables:
|
||||
"""The path is a valid path
|
||||
"""
|
||||
if '.' not in path and path not in self.variables and path in self.full_paths_variables:
|
||||
return True
|
||||
return name in self.variables
|
||||
return path in self.variables
|
||||
|
||||
def variable_is_dynamic(self,
|
||||
name: str,
|
||||
) -> bool:
|
||||
"""This variable is in dynamic family
|
||||
"""
|
||||
return self._get_variable(name)['is_dynamic']
|
||||
|
||||
def _get_variable(self,
|
||||
|
|
|
@ -12,6 +12,4 @@
|
|||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
<constraints>
|
||||
</constraints>
|
||||
</rougail>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<variables>
|
||||
<family name="général">
|
||||
<variable name="mode_conteneur_actif" type="string" description="No change" auto_freeze="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="activer_ejabberd" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="module_instancie" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<rougail>
|
||||
<variables>
|
||||
<family name='ejabberd'>
|
||||
<variable name="description" type="string">
|
||||
<value>Exportation de la base de ejabberd</value>
|
||||
</variable>
|
||||
<variable name="day" type="schedule"></variable>
|
||||
<variable name="mode" type="schedulemod">
|
||||
<value>pre</value>
|
||||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
</rougail>
|
|
@ -0,0 +1 @@
|
|||
{"rougail.general.mode_conteneur_actif": "non", "rougail.general.activer_ejabberd": "non", "rougail.general.module_instancie": "non", "extra.ejabberd.description": "Exportation de la base de ejabberd", "extra.ejabberd.day": "none", "extra.ejabberd.mode": "pre"}
|
|
@ -0,0 +1,21 @@
|
|||
from importlib.machinery import SourceFileLoader
|
||||
func = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py').load_module()
|
||||
for key, value in dict(locals()).items():
|
||||
if key != ['SourceFileLoader', 'func']:
|
||||
setattr(func, key, value)
|
||||
try:
|
||||
from tiramisu3 import *
|
||||
except:
|
||||
from tiramisu import *
|
||||
from rougail.tiramisu import ConvertDynOptionDescription
|
||||
option_5 = StrOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='module_instancie', doc='No change', multi=False, default='non')
|
||||
option_3 = StrOption(properties=frozenset({'auto_freeze', 'basic', 'force_store_value', 'mandatory', Calculation(calc_value, Params(ParamValue('auto_frozen'), kwargs={'condition': ParamOption(option_5, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}), name='mode_conteneur_actif', doc='No change', multi=False, default='non')
|
||||
option_4 = StrOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='activer_ejabberd', doc='No change', multi=False, default='non')
|
||||
option_2 = OptionDescription(name='general', doc='général', properties=frozenset({'basic'}), children=[option_3, option_4, option_5])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||
option_8 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='description', doc='description', multi=False, default='Exportation de la base de ejabberd')
|
||||
option_9 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='day', doc='day', multi=False, default='none', values=('none', 'daily', 'weekly', 'monthly'))
|
||||
option_10 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode', doc='mode', multi=False, default='pre', values=('pre', 'post'))
|
||||
option_7 = OptionDescription(name='ejabberd', doc='ejabberd', properties=frozenset({'normal'}), children=[option_8, option_9, option_10])
|
||||
option_6 = OptionDescription(name='extra', doc='extra', children=[option_7])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_6])
|
Loading…
Reference in New Issue