starting multiple nodes with frappy cli

This commit is contained in:
l_samenv 2023-05-16 14:00:11 +02:00
parent 02ca6de3ec
commit e5f7aded92
2 changed files with 36 additions and 47 deletions

View File

@ -103,57 +103,46 @@ class FrappyManager(ServiceManager):
cfgs = {i for i, s in cfginfo if s == service or service is None}
return [i for i in ins_list if i in cfgs]
def check_server(self, ins='', service='main'):
start_dir, env = self.prepare_start(ins, service)
sys.path.insert(0, start_dir)
try:
self.check_running(ins, service)
except ServiceDown as e:
raise UsageError('frappy %s %s is not running' % (ins, service))
return
except KeyError:
if not ins:
def get_nodes(self, ins='', service=None):
start_dir = ServiceManager.prepare_start(self, ins, None)[0]
if start_dir not in sys.path:
sys.path.insert(0, start_dir)
nodes = []
services = self.services if service is None else [service]
for service in services:
try:
self.check_running(ins, service)
nodes.append('localhost:%d' % self.info[ins][service])
except ServiceDown:
if len(services) == 1:
raise UsageError('frappy %s %s is not running' % (ins, service))
except KeyError:
if ins:
raise UsageError('unknown instance %s' % ins)
raise UsageError('missing instance')
raise UsageError('unknown instance %s' % ins)
if not nodes:
raise UsageError(f"frappy {ins}: none of {'/'.join(services)} is running")
return nodes
def do_gui(self, ins='', service='main'):
self.check_server(ins, service)
def do_gui(self, ins='', service=None):
print(f'starting frappy gui {ins} {service or ""}')
nodes = self.get_nodes(ins, service)
print('starting frappy gui %s' % ins)
import mlzlog
if exists(join(self.env[ins].get('FRAPPY_ROOT'), 'frappy')):
import frappy
else:
import secop as frappy
import logging
from frappy.gui.qt import QApplication
from frappy.gui.mainwindow import MainWindow
mlzlog.initLogging('gui', 'info')
app = QApplication([])
win = MainWindow(['localhost:%d' % self.info[ins][service]])
win = MainWindow(nodes, logging.getLogger('gui'))
win.show()
return app.exec_()
def do_cli(self, ins='', service='main'):
self.check_server(ins, service)
import code
if exists(join(self.env[ins].get('FRAPPY_ROOT'), 'frappy')):
import frappy
else:
print('secop!')
import secop as frappy
from frappy.client.interactive import Client
namespace = {}
try:
from frappy.client.interactive import watch
namespace['watch'] = watch
except ImportError:
pass
namespace['client'] = Client('localhost:%d' % self.info[ins][service])
code.interact(banner='', local=namespace)
def do_cli(self, ins='', service=None):
nodes = self.get_nodes(ins, service)
print(f"PP {os.environ['PYTHONPATH']} {sys.path}")
from frappy.client.interactive import init, interact
init(*nodes)
interact()
def all_cfg(self, ins, service, by_dir=False):
result = {}

View File

@ -100,13 +100,13 @@ class NicosManager(ServiceManager):
nicos_conf = join(base, 'nicos.conf')
content = {
'nicos': {
'setup_subdirs': '%s, common, frappy' % ins,
'logging_path': '%s/%s' % (env['NICOS_LOG'], ins),
'pid_path': '%s/%s' % (env['NICOS_LOG'], ins),
'setup_subdirs': '["%s", "common", "frappy_sinq"]' % ins,
'logging_path': '"%s/%s"' % (env['NICOS_LOG'], ins),
'pid_path': '"%s/%s"' % (env['NICOS_LOG'], ins),
},
'environment': {
key: env[key] for key in env if key in ENV_KEYS
}
# 'environment': {
# key: f'"{env[key]}"' for key in env if key in ENV_KEYS
#}
}
try:
cp = ConfigParser()