fix access to sea config dir

- removed unused property json_path
- do not take the first directory in config path, but the first
  directory with a sea subdirectory

Change-Id: I4f0d72936ca616134c38568d88c57a33a3397ec6
This commit is contained in:
zolliker 2021-03-11 15:53:57 +01:00
parent 7c0101f6bd
commit 3435107948

View File

@ -35,6 +35,7 @@ rx:bla rx bla /some/rx_a/bla rx bla /some/rx_a
import json import json
import threading import threading
import time import time
import os
from os.path import expanduser, join from os.path import expanduser, join
from secop.client import ProxyClient from secop.client import ProxyClient
@ -66,7 +67,12 @@ remote_paths = .
SEA_DIR = expanduser('~/sea') SEA_DIR = expanduser('~/sea')
confdir = getGeneralConfig()['confdir'].split(':', 1)[0] for confdir in getGeneralConfig()['confdir'].split(os.pathsep):
seaconfdir = join(confdir, 'sea')
if os.exists(seaconfdir):
break
else:
seaconfdir = None
def get_sea_port(instance): def get_sea_port(instance):
@ -87,8 +93,6 @@ def get_sea_port(instance):
class SeaClient(ProxyClient, Module): class SeaClient(ProxyClient, Module):
"""connection to SEA""" """connection to SEA"""
json_path = Property('path to SEA json descriptors', StringType())
uri = Parameter('hostname:portnumber', datatype=StringType(), default='localhost:5000') uri = Parameter('hostname:portnumber', datatype=StringType(), default='localhost:5000')
timeout = Parameter('timeout', datatype=FloatRange(0), default=10) timeout = Parameter('timeout', datatype=FloatRange(0), default=10)
@ -242,11 +246,11 @@ class SeaClient(ProxyClient, Module):
samenv, reply = json.loads(reply) samenv, reply = json.loads(reply)
samenv = samenv.replace('/', '_') samenv = samenv.replace('/', '_')
result = [] result = []
with open(join(confdir, 'sea', samenv + '.cfg'), 'w') as cfp: with open(join(seaconfdir, samenv + '.cfg'), 'w') as cfp:
cfp.write(CFG_HEADER % dict(samenv=samenv)) cfp.write(CFG_HEADER % dict(samenv=samenv))
for filename, obj, descr in reply: for filename, obj, descr in reply:
content = json.dumps([obj, descr]).replace('}, {', '},\n{') content = json.dumps([obj, descr]).replace('}, {', '},\n{')
with open(join(confdir, 'sea', filename + '.json'), 'w') as fp: with open(join(seaconfdir, filename + '.json'), 'w') as fp:
fp.write(content + '\n') fp.write(content + '\n')
if descr[0].get('cmd', '').startswith('run '): if descr[0].get('cmd', '').startswith('run '):
modcls = 'SeaDrivable' modcls = 'SeaDrivable'
@ -291,7 +295,7 @@ class SeaModule(Module):
remote_paths = cfgdict.pop('remote_paths', '') remote_paths = cfgdict.pop('remote_paths', '')
if 'description' not in cfgdict: if 'description' not in cfgdict:
cfgdict['description'] = '%s (remote_paths=%s)' % (json_descr, remote_paths) cfgdict['description'] = '%s (remote_paths=%s)' % (json_descr, remote_paths)
with open(join(confdir, 'sea', json_descr + '.json')) as fp: with open(join(seaconfdir, json_descr + '.json')) as fp:
sea_object, descr = json.load(fp) sea_object, descr = json.load(fp)
remote_paths = remote_paths.split() remote_paths = remote_paths.split()
if remote_paths: if remote_paths: