75 lines
3.5 KiB
Python
75 lines
3.5 KiB
Python
|
"""Param annotator
|
||
|
|
||
|
Created by:
|
||
|
EOLE (http://eole.orion.education.fr)
|
||
|
Copyright (C) 2005-2018
|
||
|
|
||
|
Forked by:
|
||
|
Cadoles (http://www.cadoles.com)
|
||
|
Copyright (C) 2019-2021
|
||
|
|
||
|
distribued with GPL-2 or later license
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
"""
|
||
|
from ..i18n import _
|
||
|
from ..error import DictConsistencyError
|
||
|
|
||
|
|
||
|
class ParamAnnotator:
|
||
|
def convert_param(self, objects) -> None:
|
||
|
""" valid and convert param
|
||
|
"""
|
||
|
for obj in objects:
|
||
|
if not hasattr(obj, 'param'):
|
||
|
continue
|
||
|
param_to_delete = []
|
||
|
for param_idx, param in enumerate(obj.param):
|
||
|
if param.type == 'suffix':
|
||
|
if hasattr(param, 'text'):
|
||
|
msg = _(f'"{param.type}" parameter must not have a value')
|
||
|
raise DictConsistencyError(msg, 28, obj.xmlfiles)
|
||
|
for target in obj.target:
|
||
|
if not self.objectspace.paths.variable_is_dynamic(target.name.path):
|
||
|
msg = _(f'"suffix" parameter cannot be set with target "{target.name}"'
|
||
|
f' which is not a dynamic variable')
|
||
|
raise DictConsistencyError(msg, 53, obj.xmlfiles)
|
||
|
elif not hasattr(param, 'text'):
|
||
|
if not param.type == 'nil':
|
||
|
msg = _(f'"{param.type}" parameter must have a value')
|
||
|
raise DictConsistencyError(msg, 27, obj.xmlfiles)
|
||
|
elif param.type == 'nil':
|
||
|
msg = _(f'"{param.type}" parameter must not have a value')
|
||
|
raise DictConsistencyError(msg, 40, obj.xmlfiles)
|
||
|
if param.type == 'variable':
|
||
|
try:
|
||
|
path, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||
|
obj.namespace,
|
||
|
)
|
||
|
param.text = self.objectspace.paths.get_variable(path)
|
||
|
if suffix:
|
||
|
param.suffix = suffix
|
||
|
family_path = self.objectspace.paths.get_variable_family_path(path)
|
||
|
param.family = self.objectspace.paths.get_family(family_path,
|
||
|
param.text.namespace,
|
||
|
)
|
||
|
except DictConsistencyError as err:
|
||
|
if err.errno != 42 or not param.optional:
|
||
|
raise err
|
||
|
param_to_delete.append(param_idx)
|
||
|
param_to_delete.sort(reverse=True)
|
||
|
for param_idx in param_to_delete:
|
||
|
obj.param.pop(param_idx)
|