added 'export_as' for parameters and commands
the export argument of an accessible allows now to specify an other external name than the attribute used internally. export=True (default, use defined name, or prefix with '_' when name not in predefined list) export=False (do not export) export=<any string> (special cases only) Change-Id: I6c6669cd502d9d6fd3aa40091673e5554fd961bd Reviewed-on: https://forge.frm2.tum.de/review/19664 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
@ -28,12 +28,12 @@ import time
|
||||
|
||||
from secop.datatypes import (EnumType, FloatRange, StringType, TupleOf,
|
||||
get_datatype)
|
||||
from secop.errors import ConfigError
|
||||
from secop.errors import ConfigError, ProgrammingError
|
||||
from secop.lib import (formatException, formatExtendedStack, mkthread,
|
||||
unset_value)
|
||||
from secop.lib.enum import Enum
|
||||
from secop.metaclass import ModuleMeta, add_metaclass
|
||||
from secop.params import Command, Override, Parameter
|
||||
from secop.params import Command, Override, Parameter, PREDEFINED_ACCESSIBLES
|
||||
|
||||
# XXX: connect with 'protocol'-Modules.
|
||||
# Idea: every Module defined herein is also a 'protocol'-Module,
|
||||
@ -41,8 +41,6 @@ from secop.params import Command, Override, Parameter
|
||||
# from these base classes (how to do this?)
|
||||
|
||||
|
||||
|
||||
|
||||
@add_metaclass(ModuleMeta)
|
||||
class Module(object):
|
||||
"""Basic Module
|
||||
@ -74,6 +72,7 @@ class Module(object):
|
||||
'visibility': None, # XXX: ????
|
||||
# what else?
|
||||
}
|
||||
|
||||
# properties, parameter and commands are auto-merged upon subclassing
|
||||
parameters = {}
|
||||
commands = {}
|
||||
@ -126,11 +125,27 @@ class Module(object):
|
||||
# they need to be individual per instance since we use them also
|
||||
# to cache the current value + qualifiers...
|
||||
accessibles = {}
|
||||
for k, v in self.accessibles.items():
|
||||
# conversion from exported names to internal attribute names
|
||||
accessiblename2attr = {}
|
||||
for aname, aobj in self.accessibles.items():
|
||||
# make a copy of the Parameter/Command object
|
||||
accessibles[k] = v.copy()
|
||||
aobj = aobj.copy()
|
||||
if aobj.export:
|
||||
if aobj.export is True:
|
||||
predefined_obj = PREDEFINED_ACCESSIBLES.get(aname, None)
|
||||
if predefined_obj:
|
||||
if isinstance(aobj, predefined_obj):
|
||||
aobj.export = aname
|
||||
else:
|
||||
raise ProgrammingError("can not use '%s' as name of a %s" %
|
||||
(aname, aobj.__class__.__name__))
|
||||
else: # create custom parameter
|
||||
aobj.export = '_' + aname
|
||||
accessiblename2attr[aobj.export] = aname
|
||||
accessibles[aname] = aobj
|
||||
# do not re-use self.accessibles as this is the same for all instances
|
||||
self.accessibles = accessibles
|
||||
self.accessiblename2attr = accessiblename2attr
|
||||
|
||||
# 2) check and apply parameter_properties
|
||||
# specified as '<paramname>.<propertyname> = <propertyvalue>'
|
||||
|
Reference in New Issue
Block a user