bug in Attached (fix after change 31470)
An attached property may be defined with mandatory=False. In this case, when no value or an empty string is given, <modobj>.<attached_mod> must return None after initialisation. + remove 'dispatcher' level from the logger hierarchy on modules Change-Id: Icee3ae3f9142cd7a910c579ae1ffaa35f93cee03 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32187 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# *****************************************************************************
|
# *****************************************************************************
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
@ -925,13 +924,18 @@ class Communicator(HasComlog, Module):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
SECoP_BASE_CLASSES = {Readable, Writable, Drivable, Communicator}
|
SECoP_BASE_CLASSES = {Readable, Writable, Drivable, Communicator}
|
||||||
|
|
||||||
|
|
||||||
class Attached(Property):
|
class Attached(Property):
|
||||||
"""a special property, defining an attached module
|
"""a special property, defining an attached module
|
||||||
|
|
||||||
assign a module name to this property in the cfg file,
|
assign a module name to this property in the cfg file,
|
||||||
and the server will create an attribute with this module
|
and the server will create an attribute with this module
|
||||||
|
|
||||||
|
When mandatory is set to False, and there is no value or an empty string
|
||||||
|
given in the config file, the value of the attribute will be None.
|
||||||
"""
|
"""
|
||||||
def __init__(self, basecls=Module, description='attached module', mandatory=True):
|
def __init__(self, basecls=Module, description='attached module', mandatory=True):
|
||||||
self.basecls = basecls
|
self.basecls = basecls
|
||||||
@ -940,13 +944,17 @@ class Attached(Property):
|
|||||||
def __get__(self, obj, owner):
|
def __get__(self, obj, owner):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return self
|
return self
|
||||||
if self.name not in obj.attachedModules:
|
modobj = obj.attachedModules.get(self.name)
|
||||||
modobj = obj.DISPATCHER.get_module(super().__get__(obj, owner))
|
if not modobj:
|
||||||
|
modulename = super().__get__(obj, owner)
|
||||||
|
if not modulename:
|
||||||
|
return None # happens when mandatory=False and modulename is not given
|
||||||
|
modobj = obj.DISPATCHER.get_module(modulename)
|
||||||
if not isinstance(modobj, self.basecls):
|
if not isinstance(modobj, self.basecls):
|
||||||
raise ConfigError(f'attached module {self.name}={modobj.name!r} '\
|
raise ConfigError(f'attached module {self.name}={modobj.name!r} '
|
||||||
f'must inherit from {self.basecls.__qualname__!r}')
|
f'must inherit from {self.basecls.__qualname__!r}')
|
||||||
obj.attachedModules[self.name] = modobj
|
obj.attachedModules[self.name] = modobj
|
||||||
return obj.attachedModules.get(self.name) # return None if not given
|
return modobj
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return Attached(self.basecls, self.description, self.mandatory)
|
return Attached(self.basecls, self.description, self.mandatory)
|
||||||
|
@ -227,7 +227,7 @@ class Dispatcher:
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
modobj = cls(modulename, self.log.getChild(modulename), opts, self.srv)
|
modobj = cls(modulename, self.log.parent.getChild(modulename), opts, self.srv)
|
||||||
except ConfigError as e:
|
except ConfigError as e:
|
||||||
self.errors.append(f'error creating module {modulename}:')
|
self.errors.append(f'error creating module {modulename}:')
|
||||||
for errtxt in e.args[0] if isinstance(e.args[0], list) else [e.args[0]]:
|
for errtxt in e.args[0] if isinstance(e.args[0], list) else [e.args[0]]:
|
||||||
|
@ -28,6 +28,9 @@ from .test_config import direc # pylint: disable=unused-import
|
|||||||
|
|
||||||
|
|
||||||
class LoggerStub:
|
class LoggerStub:
|
||||||
|
def __init__(self):
|
||||||
|
self.parent = self
|
||||||
|
|
||||||
def debug(self, fmt, *args):
|
def debug(self, fmt, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user