accept module properties without leading '.' in config files

as module properties and parameters anyway share the same namespace,
there is no need to distinguish in config files.

+ a parameter default value may be overriden just with a class
  attribute.

Both improvements help to switch between parameters and properties
more easily.

Change-Id: Ieb5cf3121f37c7c04e63345d3e95dfaf42726455
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22054
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2019-12-19 09:39:43 +01:00
parent a876eba5f6
commit f06fa9faa2
2 changed files with 20 additions and 2 deletions

View File

@ -25,7 +25,7 @@
import time
from collections import OrderedDict
from secop.errors import ProgrammingError
from secop.errors import ProgrammingError, BadValueError
from secop.params import Command, Override, Parameter
from secop.datatypes import EnumType
from secop.properties import PropertyMeta
@ -103,6 +103,16 @@ class ModuleMeta(PropertyMeta):
# 2) for the describing message
newtype.accessibles = OrderedDict(sorted(accessibles.items(), key=lambda item: item[1].ctr))
# check for attributes overriding parameter values
for pname, pobj in newtype.accessibles.items():
if pname in attrs:
try:
value = pobj.datatype(attrs[pname])
except BadValueError:
raise ProgrammingError('parameter %s can not be set to %r'
% (pname, attrs[pname]))
newtype.accessibles[pname] = Override(default=value).apply(pobj)
# check validity of Parameter entries
for pname, pobj in newtype.accessibles.items():
# XXX: create getters for the units of params ??

View File

@ -100,6 +100,7 @@ class Module(HasProperties, metaclass=ModuleMeta):
# 2) check and apply properties specified in cfgdict
# specified as '.<propertyname> = <propertyvalue>'
# (this is for legacy config files only)
for k, v in list(cfgdict.items()): # keep list() as dict may change during iter
if k[0] == '.':
if k[1:] in self.__class__.properties:
@ -108,6 +109,12 @@ class Module(HasProperties, metaclass=ModuleMeta):
raise ConfigError('Module %r has no property %r' %
(self.name, k[1:]))
# 3) check and apply properties specified in cfgdict as
# '<propertyname> = <propertyvalue>' (without '.' prefix)
for k in self.__class__.properties:
if k in cfgdict:
self.setProperty(k, cfgdict.pop(k))
# 4) set automatic properties
mycls = self.__class__
myclassname = '%s.%s' % (mycls.__module__, mycls.__name__)
@ -175,7 +182,8 @@ class Module(HasProperties, metaclass=ModuleMeta):
raise ConfigError(
'Module %s:config Parameter %r '
'not understood! (use one of %s)' %
(self.name, k, ', '.join(self.parameters.keys())))
(self.name, k, ', '.join(list(self.parameters) +
list(self.__class__.properties))))
# 4) complain if a Parameter entry has no default value and
# is not specified in cfgdict and deal with parameters to be written.