fixes in sea

- call explicitely __set_name__ on produced parameters
- as Parameters.override has changed, do not use it
This commit is contained in:
l_samenv 2021-11-04 12:56:42 +01:00
parent 7d2eacfe5c
commit 3d9e9c59d6

View File

@ -41,7 +41,7 @@ from secop.client import ProxyClient
from secop.datatypes import ArrayOf, BoolType, \
EnumType, FloatRange, IntRange, StringType
from secop.errors import ConfigError, HardwareError, secop_error, NoSuchModuleError
from secop.lib import getGeneralConfig, mkthread
from secop.lib import getGeneralConfig, mkthread, formatExtendedStack
from secop.lib.asynconn import AsynConn, ConnectionClosed
from secop.modules import Attached, Command, Done, Drivable, \
Module, Parameter, Property, Readable, Writable
@ -124,6 +124,7 @@ class SeaClient(ProxyClient, Module):
if config:
self.default_json_file[name] = config.split()[0] + '.json'
self.io = None
self.asyncio = None
ProxyClient.__init__(self)
Module.__init__(self, name, log, opts, srv)
@ -153,7 +154,7 @@ class SeaClient(ProxyClient, Module):
"""send a request and wait for reply"""
with self._write_lock:
if not self.io or not self.io.connection:
if not self.asyncio.connection:
if not self.asyncio or not self.asyncio.connection:
self._connect(None)
self.io = AsynConn(self.uri)
assert self.io.readline() == b'OK'
@ -314,12 +315,14 @@ class SeaConfigCreator(SeaClient):
stripped, _, ext = filename.rpartition('.')
service = SERVICE_NAMES[ext]
seaconn = 'sea_' + service
with open(join(seaconfdir, stripped + '.cfg'), 'w') as fp:
cfgfile = join(seaconfdir, stripped + '.cfg')
with open(cfgfile, 'w') as fp:
fp.write(CFG_HEADER % dict(config=filename, seaconn=seaconn, service=service,
nodedescr=description.get(filename, filename)))
for obj in descr:
fp.write(CFG_MODULE % dict(modcls=modcls[obj], module=obj, seaconn=seaconn))
content = json.dumps(descr).replace('}, {', '},\n{').replace('[{', '[\n{').replace('}]}, ', '}]},\n\n')
result.append('%s\n' % cfgfile)
with open(join(seaconfdir, filename + '.json'), 'w') as fp:
fp.write(content + '\n')
result.append('%s: %s' % (filename, ','.join(n for n in descr)))
@ -495,7 +498,8 @@ class SeaModule(Module):
if key in cls.accessibles:
if key == 'target':
kwds['readonly'] = False
pobj = cls.accessibles[key].override(**kwds)
pobj = cls.accessibles[key]
pobj.init(kwds)
datatype = kwds.get('datatype', cls.accessibles[key].datatype)
else:
pobj = Parameter(**kwds)
@ -542,12 +546,17 @@ class SeaModule(Module):
# create standard parameters like value and status, if not yet there
for pname, pobj in cls.accessibles.items():
if pname == 'pollinterval':
attributes[pname] = pobj.override(export=False)
pobj.export = False
attributes[pname] = pobj
pobj.__set_name__(cls, pname)
elif pname not in attributes and isinstance(pobj, Parameter):
attributes[pname] = pobj.override(poll=False, needscfg=False)
pobj.poll = False
pobj.needscfg = False
attributes[pname] = pobj
pobj.__set_name__(cls, pname)
classname = '%s_%s' % (cls.__name__, sea_object)
# print(name, attributes)
attributes['pollerClass'] = None
newcls = type(classname, (cls,), attributes)
return Module.__new__(newcls)
@ -640,5 +649,6 @@ class SeaDrivable(SeaModule, Drivable):
if value is not None:
self.target = value
@Command()
def stop(self):
self._iodev.query('%s is_running 0' % self.sea_object)