[WIP] include SEA info
This commit is contained in:
parent
a255b9b715
commit
008690fe84
1
base.py
1
base.py
@ -363,7 +363,6 @@ class ServiceManager:
|
||||
logger.info('%sstarted: %s', 're' if restart else '', cmd)
|
||||
break
|
||||
else:
|
||||
logger.info(cmd)
|
||||
logger.error('starting failed: %s', cmd)
|
||||
finally:
|
||||
os.chdir(wd)
|
||||
|
67
frappyman.py
67
frappyman.py
@ -25,7 +25,8 @@ import os
|
||||
from glob import glob
|
||||
from os.path import join, isdir, basename, expanduser, exists
|
||||
from configparser import ConfigParser
|
||||
from servicemanager.base import ServiceManager, ServiceDown, UsageError
|
||||
from .base import ServiceManager, ServiceDown, UsageError
|
||||
from .seaman import SeaManager
|
||||
|
||||
|
||||
def dummy(*args, **kwds):
|
||||
@ -103,6 +104,13 @@ class FrappyManager(ServiceManager):
|
||||
raise UsageError('no wildcards allowed with %s start' % self.group)
|
||||
if cfg and not service and len(self.services) != 1:
|
||||
raise UsageError('need service to start (one of %s)' % ', '.join(self.services))
|
||||
if cfg.startswith('~'):
|
||||
cfg = cfg[1:]
|
||||
seacfg = SeaManager().guess_frappy_cfg(ins).get(service)
|
||||
if seacfg:
|
||||
cfg = seacfg
|
||||
if not cfg:
|
||||
return
|
||||
super().do_start(ins, service, cfg, restart, wait, logger)
|
||||
|
||||
def do_restart(self, ins, service=None, cfg=None, logger=None):
|
||||
@ -154,9 +162,17 @@ class FrappyManager(ServiceManager):
|
||||
init(*nodes)
|
||||
interact()
|
||||
|
||||
def all_cfg(self, ins, service, by_dir=False):
|
||||
def all_cfg(self, ins, service, details=False):
|
||||
"""get available cfg files
|
||||
|
||||
:param ins: instance
|
||||
:param service: service nor None for all services
|
||||
:param details:
|
||||
True: return a dict of <cfgdir> of <cfg> of <description>
|
||||
False: return a set of <cfg>
|
||||
"""
|
||||
result = {}
|
||||
all_cfg = {}
|
||||
all_cfg = set()
|
||||
if not ins:
|
||||
return {}
|
||||
namespace = {k: dummy for k in ('Mod', 'Param', 'Command', 'Group')}
|
||||
@ -169,39 +185,40 @@ class FrappyManager(ServiceManager):
|
||||
cfg_pattern ='*_cfg.py' if exists(join(root, 'frappy')) else '*.cfg'
|
||||
for cfgfile in glob(join(cfgdir, cfg_pattern)):
|
||||
desc = ''
|
||||
try:
|
||||
if cfgfile.endswith('.py'):
|
||||
node.description = ''
|
||||
try:
|
||||
with open(cfgfile, encoding='utf-8') as f:
|
||||
exec(f.read(), namespace)
|
||||
except Exception as e:
|
||||
node.description = repr(e)
|
||||
desc = node.description
|
||||
else:
|
||||
parser = ConfigParser()
|
||||
parser.read(cfgfile)
|
||||
for s in parser.sections():
|
||||
if s == 'NODE' or s.startswith('node '):
|
||||
desc = parser[s].get('description', '').split('\n')[0]
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
if details:
|
||||
try:
|
||||
if cfgfile.endswith('.py'):
|
||||
node.description = ''
|
||||
try:
|
||||
with open(cfgfile, encoding='utf-8') as f:
|
||||
exec(f.read(), namespace)
|
||||
except Exception as e:
|
||||
node.description = repr(e)
|
||||
desc = node.description
|
||||
else:
|
||||
parser = ConfigParser()
|
||||
parser.read(cfgfile)
|
||||
for s in parser.sections():
|
||||
if s == 'NODE' or s.startswith('node '):
|
||||
desc = parser[s].get('description', '').split('\n')[0]
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
cfg = basename(cfgfile)[:1-len(cfg_pattern)]
|
||||
if cfg not in all_cfg:
|
||||
all_cfg[cfg] = desc
|
||||
all_cfg.add(cfg)
|
||||
cfgs[cfg] = desc
|
||||
return result if by_dir else all_cfg
|
||||
return result if details else all_cfg
|
||||
|
||||
def do_listcfg(self, ins='', service='', prt=print):
|
||||
if not ins:
|
||||
raise UsageError('missing instance')
|
||||
if service:
|
||||
all_cfg = self.all_cfg(ins, service, by_dir=True)
|
||||
all_cfg = self.all_cfg(ins, service, True)
|
||||
else:
|
||||
all_cfg = {}
|
||||
for service in self.services:
|
||||
all_cfg.update(self.all_cfg(ins, service, by_dir=True))
|
||||
all_cfg.update(self.all_cfg(ins, service, True))
|
||||
for cfgdir, cfgs in all_cfg.items():
|
||||
if cfgs:
|
||||
prt('')
|
||||
|
20
seaman.py
20
seaman.py
@ -118,6 +118,8 @@ class SeaManager(ServiceManager):
|
||||
"""
|
||||
if service != 'sea': # ignore when service == 'graph'
|
||||
return ''
|
||||
if 'sea' not in self.get_procs().get(ins):
|
||||
return ''
|
||||
try:
|
||||
searoot = self.env[ins].get('SEA_ROOT', '')
|
||||
seastatus = join(searoot, ins, 'status', 'seastatus.tcl')
|
||||
@ -172,3 +174,21 @@ class SeaManager(ServiceManager):
|
||||
else:
|
||||
raise UsageError('unknown argument: %s' % arg)
|
||||
return [argdict.pop('ins', '')] + extra
|
||||
|
||||
def guess_frappy_cfg(self, ins):
|
||||
self.get_info()
|
||||
cfgs = self.get_cfg(ins, 'sea').split('/')
|
||||
result = {}
|
||||
if cfgs[0] and cfgs[0] in self.all_cfg(ins, 'main'):
|
||||
result['main'] = cfgs[0]
|
||||
allsticks = self.all_cfg(ins, 'stick')
|
||||
stick = cfgs[:2][-1]
|
||||
if stick:
|
||||
for s in (stick + 'stick', stick):
|
||||
if s in allsticks:
|
||||
result['stick'] = s
|
||||
break
|
||||
addons = [a for a in cfgs[2:] if a in self.all_cfg(ins, 'addons')]
|
||||
if addons:
|
||||
result['addons'] = ','.join(addons)
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user