moved creation parameters + commands to Module.__init__
- <module>.parameters should contain live parameters on the instance level, not on the class level - simplified code in Module.__init__, as self.parameters are available - accessibles on instance level must be OrderedDict, as this is used by describe Change-Id: Idf507cde5a8f755317e566107214b9a92f3534f7 Reviewed-on: https://forge.frm2.tum.de/review/20302 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
parent
3eaa32d514
commit
d702bea7a6
@ -216,9 +216,5 @@ class ModuleMeta(type):
|
|||||||
raise ProgrammingError('%r: command %r has to be specified '
|
raise ProgrammingError('%r: command %r has to be specified '
|
||||||
'explicitly!' % (name, attrname[3:]))
|
'explicitly!' % (name, attrname[3:]))
|
||||||
|
|
||||||
# provide properties to 'filter' out the parameters/commands
|
|
||||||
newtype.parameters = dict((k,v) for k,v in newtype.accessibles.items() if isinstance(v, Parameter))
|
|
||||||
newtype.commands = dict((k,v) for k,v in newtype.accessibles.items() if isinstance(v, Command))
|
|
||||||
|
|
||||||
attrs['__constructed__'] = True
|
attrs['__constructed__'] = True
|
||||||
return newtype
|
return newtype
|
||||||
|
@ -25,6 +25,7 @@ from __future__ import division, print_function
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from secop.datatypes import EnumType, FloatRange, \
|
from secop.datatypes import EnumType, FloatRange, \
|
||||||
StringType, TupleOf, get_datatype
|
StringType, TupleOf, get_datatype
|
||||||
@ -124,7 +125,7 @@ class Module(object):
|
|||||||
# 1) make local copies of parameter objects
|
# 1) make local copies of parameter objects
|
||||||
# they need to be individual per instance since we use them also
|
# they need to be individual per instance since we use them also
|
||||||
# to cache the current value + qualifiers...
|
# to cache the current value + qualifiers...
|
||||||
accessibles = {}
|
accessibles = OrderedDict()
|
||||||
# conversion from exported names to internal attribute names
|
# conversion from exported names to internal attribute names
|
||||||
accessiblename2attr = {}
|
accessiblename2attr = {}
|
||||||
for aname, aobj in self.accessibles.items():
|
for aname, aobj in self.accessibles.items():
|
||||||
@ -146,6 +147,9 @@ class Module(object):
|
|||||||
# do not re-use self.accessibles as this is the same for all instances
|
# do not re-use self.accessibles as this is the same for all instances
|
||||||
self.accessibles = accessibles
|
self.accessibles = accessibles
|
||||||
self.accessiblename2attr = accessiblename2attr
|
self.accessiblename2attr = accessiblename2attr
|
||||||
|
# provide properties to 'filter' out the parameters/commands
|
||||||
|
self.parameters = dict((k,v) for k,v in accessibles.items() if isinstance(v, Parameter))
|
||||||
|
self.commands = dict((k,v) for k,v in accessibles.items() if isinstance(v, Command))
|
||||||
|
|
||||||
# 2) check and apply parameter_properties
|
# 2) check and apply parameter_properties
|
||||||
# specified as '<paramname>.<propertyname> = <propertyvalue>'
|
# specified as '<paramname>.<propertyname> = <propertyvalue>'
|
||||||
@ -153,6 +157,7 @@ class Module(object):
|
|||||||
if '.' in k[1:]:
|
if '.' in k[1:]:
|
||||||
paramname, propname = k.split('.', 1)
|
paramname, propname = k.split('.', 1)
|
||||||
paramobj = self.accessibles.get(paramname, None)
|
paramobj = self.accessibles.get(paramname, None)
|
||||||
|
# paramobj might also be a command (not sure if this is needed)
|
||||||
if paramobj:
|
if paramobj:
|
||||||
if propname == 'datatype':
|
if propname == 'datatype':
|
||||||
paramobj.datatype = get_datatype(cfgdict.pop(k))
|
paramobj.datatype = get_datatype(cfgdict.pop(k))
|
||||||
@ -165,17 +170,15 @@ class Module(object):
|
|||||||
# 3) check config for problems:
|
# 3) check config for problems:
|
||||||
# only accept remaining config items specified in parameters
|
# only accept remaining config items specified in parameters
|
||||||
for k, v in cfgdict.items():
|
for k, v in cfgdict.items():
|
||||||
if k not in self.accessibles:
|
if k not in self.parameters:
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
'Module %s:config Parameter %r '
|
'Module %s:config Parameter %r '
|
||||||
'not unterstood! (use one of %s)' %
|
'not understood! (use one of %s)' %
|
||||||
(self.name, k, ', '.join(n for n,o in self.accessibles if isinstance(o, Parameter))))
|
(self.name, k, ', '.join(self.parameters.keys())))
|
||||||
|
|
||||||
# 4) complain if a Parameter entry has no default value and
|
# 4) complain if a Parameter entry has no default value and
|
||||||
# is not specified in cfgdict
|
# is not specified in cfgdict
|
||||||
for k, v in self.accessibles.items():
|
for k, v in self.parameters.items():
|
||||||
if not isinstance(v, Parameter):
|
|
||||||
continue
|
|
||||||
if k not in cfgdict:
|
if k not in cfgdict:
|
||||||
if v.default is unset_value and k != 'value':
|
if v.default is unset_value and k != 'value':
|
||||||
# unset_value is the one single value you can not specify....
|
# unset_value is the one single value you can not specify....
|
||||||
@ -189,10 +192,10 @@ class Module(object):
|
|||||||
# pass values through the datatypes and store as attributes
|
# pass values through the datatypes and store as attributes
|
||||||
for k, v in cfgdict.items():
|
for k, v in cfgdict.items():
|
||||||
# apply datatype, complain if type does not fit
|
# apply datatype, complain if type does not fit
|
||||||
datatype = self.accessibles[k].datatype
|
datatype = self.parameters[k].datatype
|
||||||
try:
|
try:
|
||||||
v = datatype.validate(v)
|
v = datatype.validate(v)
|
||||||
self.accessibles[k].default = v
|
self.parameters[k].default = v
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
self.log.exception(formatExtendedStack())
|
self.log.exception(formatExtendedStack())
|
||||||
raise
|
raise
|
||||||
@ -205,11 +208,9 @@ class Module(object):
|
|||||||
cfgdict.pop(k)
|
cfgdict.pop(k)
|
||||||
|
|
||||||
# Modify units AFTER applying the cfgdict
|
# Modify units AFTER applying the cfgdict
|
||||||
for k, v in self.accessibles.items():
|
for k, v in self.parameters.items():
|
||||||
if not isinstance(v, Parameter):
|
|
||||||
continue
|
|
||||||
if '$' in v.unit:
|
if '$' in v.unit:
|
||||||
v.unit = v.unit.replace('$', self.accessibles['value'].unit)
|
v.unit = v.unit.replace('$', self.parameters['value'].unit)
|
||||||
|
|
||||||
def isBusy(self):
|
def isBusy(self):
|
||||||
'''helper function for treating substates of BUSY correctly'''
|
'''helper function for treating substates of BUSY correctly'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user