From 0be8ae7fe132d0fb2f8752505b7158831d7f7dd3 Mon Sep 17 00:00:00 2001 From: l_samenv Date: Fri, 7 May 2021 16:34:10 +0200 Subject: [PATCH] support to start sea automatically from SeaClient (with -q arg) --- seaman.py | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/seaman.py b/seaman.py index 0858c62..c84362f 100644 --- a/seaman.py +++ b/seaman.py @@ -25,7 +25,7 @@ import time import termios import subprocess import os -from servicemanager.base import ServiceManager, ServiceDown +from servicemanager.base import ServiceManager, ServiceDown, UsageError from servicemanager.sicsclient import sics_client @@ -73,17 +73,20 @@ class SeaManager(ServiceManager): self.do_help() run_command('six -sea %s' % ins, wait=True) - def do_gui(self, ins=''): - try: - self.check_running(ins, 'sea') - except ServiceDown as e: - self.do_help() - print(str(e)) - return - except KeyError: # running on an other machine? - self.do_help() - run_command('SeaClient %s' % ins) - print('starting sea gui %s' % ins) + def do_gui(self, ins='', *args): + if ins: + args = (ins,) + args + if '-q' not in args: + try: + self.check_running(ins, 'sea') + except ServiceDown as e: + self.do_help() + print(str(e)) + return + except KeyError: # running on an other machine? + self.do_help() + run_command('SeaClient %s' % ' '.join(args)) + print('starting sea gui %s' % ' '.join(args)) time.sleep(5) def get_cfg(self, ins, service): @@ -100,13 +103,19 @@ class SeaManager(ServiceManager): return repr(e) 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() filename = os.environ.get('InstrumentHostList') if filename: with open(filename) as fil: for line in fil: - inst = None + inst = '' sea = False for item in line.split(): key, _, value = item.partition('=') @@ -116,7 +125,8 @@ class SeaManager(ServiceManager): sea = True if inst and sea: insts.add(inst) - if unknown[0] in insts: - argdict['ins'] = unknown[0] - return super().treat_args(argdict) - return super().treat_args(argdict, unknown, extra) + if arg in insts: + argdict['ins'] = arg + else: + raise UsageError('unknown argument: %s' % arg) + return [argdict.pop('ins', '')] + extra