better args checking, sea list: cfg shown only on single items

This commit is contained in:
l_samenv 2021-12-06 11:54:19 +01:00
parent e7c1fce854
commit bb3c72acc9
3 changed files with 33 additions and 13 deletions

View File

@ -50,6 +50,10 @@ class SewebManager(ServiceManager):
all = NicosManager, FrappyManager, SeaManager, SewebManager
ACTION = 1
INS = 2
SERVICE = 3
def run(group, arglist):
try:
@ -59,19 +63,34 @@ def run(group, arglist):
serv = managers[group]
args = dict(action='gui', ins=serv.main_ins)
extra = []
pos = 0
unorder = False
for arg in arglist:
if hasattr(serv, 'do_' + arg):
args['action'] = arg
if pos >= ACTION:
unorder = True
pos = ACTION
elif arg in serv.services:
args['service'] = arg
elif arg in serv.info:
if pos >= SERVICE:
unorder = True
pos = SERVICE
elif arg in serv.info or arg == 'all':
args['ins'] = arg
if pos >= INS:
unorder = True
pos = INS
else:
extra.append(arg)
try:
serv.action(args['action'], *serv.treat_args(args, extra))
except AttributeError:
raise
if unorder:
print('do you mean:\n %s %s %s %s %s' %
(group, args.get('action', ''), args.get('ins', ''), args.get('service', ''), ' '.join(extra)))
else:
try:
serv.action(args['action'], *serv.treat_args(args, extra))
except AttributeError:
raise
except UsageError as e:
serv.do_help()
print('ERROR:', str(e))

16
base.py
View File

@ -119,8 +119,7 @@ class ServiceManager:
def get_info(self):
"""returns port numbers,commands and environment variables
the result is a dict[<service>] of dict(ins=.., port= ..., cmd= ...)
if ins is omitted, return a list of above for all ins
the result is a dict[<ins>] of dict[<service>] of port or None
"""
result = OrderedDict()
parser = get_config()
@ -319,7 +318,7 @@ class ServiceManager:
continue
print_wait = True
for i in range(10): # total 10 * 9 / 2 * 0.1 = 4.5 sec
for i in range(15): # total 15 * 14 / 2 * 0.1 = 10.5 sec
returnvalue = process.poll()
if returnvalue is not None:
logger.info('started process failed, try to find out why')
@ -388,22 +387,25 @@ class ServiceManager:
for serv, port in info_grp.items():
plist = procs_dict.get(serv)
if plist:
cfg = cfginfo.get((ins_i, serv), '') or sm.get_cfg(ins_i, serv)
if ins is None:
cfg = ''
else:
cfg = cfginfo.get((ins_i, serv), '') or sm.get_cfg(ins_i, serv)
if sm == self:
show_ins = True
gs = '%s %s' % (group, serv)
port = str(port or '')
run_info.append(('', gs, port, cfg))
if len(plist) > 1:
rows.append(['', ' WARNING: multiple processes %s'
% ', '.join(str(p.pid) for p in plist)])
run_info.append(['', ' WARNING: multiple processes %s'
% ', '.join(str(p.pid) for p in plist)])
extra = sm.extra_info(ins_i)
if extra and show_ins:
run_info.append(['', extra])
if show_ins:
rows.extend(run_info)
print('')
printTable(('inst', 'service', 'port', 'cfg'), rows, print)
printTable(('inst', 'service', 'port', '' if ins is None else 'cfg'), rows, print)
@staticmethod
def extra_info(ins):

View File

@ -99,7 +99,6 @@ class SeaManager(ServiceManager):
try:
return sics_client(('localhost', self.info[ins]['sea']), 'samenv name')
except Exception as e:
print(self.info)
return repr(e)
def treat_args(self, argdict, unknown=(), extra=()):