support to start sea automatically from SeaClient (with -q arg)

This commit is contained in:
l_samenv
2021-05-07 16:34:10 +02:00
parent 5a1bdbf9a2
commit 0be8ae7fe1

View File

@ -25,7 +25,7 @@ import time
import termios import termios
import subprocess import subprocess
import os import os
from servicemanager.base import ServiceManager, ServiceDown from servicemanager.base import ServiceManager, ServiceDown, UsageError
from servicemanager.sicsclient import sics_client from servicemanager.sicsclient import sics_client
@ -73,7 +73,10 @@ class SeaManager(ServiceManager):
self.do_help() self.do_help()
run_command('six -sea %s' % ins, wait=True) run_command('six -sea %s' % ins, wait=True)
def do_gui(self, ins=''): def do_gui(self, ins='', *args):
if ins:
args = (ins,) + args
if '-q' not in args:
try: try:
self.check_running(ins, 'sea') self.check_running(ins, 'sea')
except ServiceDown as e: except ServiceDown as e:
@ -82,8 +85,8 @@ class SeaManager(ServiceManager):
return return
except KeyError: # running on an other machine? except KeyError: # running on an other machine?
self.do_help() self.do_help()
run_command('SeaClient %s' % ins) run_command('SeaClient %s' % ' '.join(args))
print('starting sea gui %s' % ins) print('starting sea gui %s' % ' '.join(args))
time.sleep(5) time.sleep(5)
def get_cfg(self, ins, service): def get_cfg(self, ins, service):
@ -100,13 +103,19 @@ class SeaManager(ServiceManager):
return repr(e) return repr(e)
def treat_args(self, argdict, unknown=(), extra=()): def treat_args(self, argdict, unknown=(), extra=()):
if len(unknown) == 1: extra = list(extra)
for arg in unknown:
if arg == '-q' and arg not in extra:
extra.append(arg)
continue
if argdict.get('ins'):
raise UsageError('superflous argument: %s' % arg)
insts = set() insts = set()
filename = os.environ.get('InstrumentHostList') filename = os.environ.get('InstrumentHostList')
if filename: if filename:
with open(filename) as fil: with open(filename) as fil:
for line in fil: for line in fil:
inst = None inst = ''
sea = False sea = False
for item in line.split(): for item in line.split():
key, _, value = item.partition('=') key, _, value = item.partition('=')
@ -116,7 +125,8 @@ class SeaManager(ServiceManager):
sea = True sea = True
if inst and sea: if inst and sea:
insts.add(inst) insts.add(inst)
if unknown[0] in insts: if arg in insts:
argdict['ins'] = unknown[0] argdict['ins'] = arg
return super().treat_args(argdict) else:
return super().treat_args(argdict, unknown, extra) raise UsageError('unknown argument: %s' % arg)
return [argdict.pop('ins', '')] + extra