2021-01-17 18:00:29 +01:00
|
|
|
"""Fill annotator
|
2021-01-30 08:15:26 +01:00
|
|
|
|
|
|
|
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
|
2021-01-17 18:00:29 +01:00
|
|
|
"""
|
2021-01-19 19:05:07 +01:00
|
|
|
from ..utils import load_modules
|
2021-01-17 18:00:29 +01:00
|
|
|
from ..i18n import _
|
|
|
|
from ..error import DictConsistencyError
|
|
|
|
|
2021-02-08 17:46:58 +01:00
|
|
|
from .target import TargetAnnotator
|
|
|
|
from .param import ParamAnnotator
|
2021-01-17 18:00:29 +01:00
|
|
|
|
2021-02-08 17:46:58 +01:00
|
|
|
|
|
|
|
class FillAnnotator(TargetAnnotator, ParamAnnotator):
|
2021-01-17 18:00:29 +01:00
|
|
|
"""Fill annotator
|
|
|
|
"""
|
|
|
|
def __init__(self,
|
|
|
|
objectspace,
|
|
|
|
eosfunc_file,
|
|
|
|
):
|
|
|
|
self.objectspace = objectspace
|
|
|
|
if not hasattr(objectspace.space, 'constraints') or \
|
|
|
|
not hasattr(self.objectspace.space.constraints, 'fill'):
|
|
|
|
return
|
2021-01-19 19:05:07 +01:00
|
|
|
self.functions = dir(load_modules(eosfunc_file))
|
2021-02-08 17:46:58 +01:00
|
|
|
self.target_is_uniq = True
|
|
|
|
self.only_variable = True
|
|
|
|
self.convert_target(self.objectspace.space.constraints.fill)
|
|
|
|
self.convert_param(self.objectspace.space.constraints.fill)
|
|
|
|
self.fill_to_value()
|
|
|
|
del self.objectspace.space.constraints.fill
|
2021-01-17 18:00:29 +01:00
|
|
|
|
2021-02-08 17:46:58 +01:00
|
|
|
def fill_to_value(self) -> None:
|
2021-01-17 18:00:29 +01:00
|
|
|
"""valid and manage <fill>
|
|
|
|
"""
|
|
|
|
for fill in self.objectspace.space.constraints.fill:
|
2021-02-08 17:46:58 +01:00
|
|
|
for target in fill.target:
|
|
|
|
# test if the function exists
|
|
|
|
if fill.name not in self.functions:
|
|
|
|
msg = _(f'cannot find fill function "{fill.name}"')
|
|
|
|
raise DictConsistencyError(msg, 25, fill.xmlfiles)
|
2021-01-17 18:00:29 +01:00
|
|
|
|
2021-02-08 17:46:58 +01:00
|
|
|
# create an object value
|
|
|
|
value = self.objectspace.value(fill.xmlfiles)
|
|
|
|
value.type = 'calculation'
|
|
|
|
value.name = fill.name
|
|
|
|
if target.name.namespace == 'services':
|
|
|
|
target.name.default = value
|
|
|
|
else:
|
|
|
|
target.name.value = [value]
|
2021-01-17 18:00:29 +01:00
|
|
|
|
2021-02-08 17:46:58 +01:00
|
|
|
# manage params
|
|
|
|
if hasattr(fill, 'param') and fill.param:
|
|
|
|
value.param = fill.param
|