[WIP] use get_server_state instead of propose_cfgs
This commit is contained in:
35
devices.py
35
devices.py
@ -174,11 +174,11 @@ class FrappyConfig(Device):
|
||||
|
||||
for a potential "please consider calling frappy(...)" message
|
||||
"""
|
||||
proposed, overview = FrappyManager().propose_cfgs(config.instrument, cfgs)
|
||||
error, proposed, state, info = FrappyManager().get_server_state(config.instrument, cfgs)
|
||||
for service, guess in list(proposed.items()):
|
||||
if guess is True:
|
||||
proposed.pop(service)
|
||||
return proposed, overview
|
||||
return proposed, state, info
|
||||
|
||||
def check_services(self):
|
||||
cfgs = {}
|
||||
@ -308,18 +308,29 @@ class FrappyConfig(Device):
|
||||
raise TypeError('refuse to override plugged device')
|
||||
self.show_config(self.start_services(main, stick, addons))
|
||||
|
||||
def show_config(self, allcfg, show_server_state=False):
|
||||
proposed, overview = self.to_consider(allcfg)
|
||||
def show_config(self, allcfg, show_server_state=False, giventitle='nicos'):
|
||||
proposed, state, info = self.to_consider(allcfg)
|
||||
if show_server_state == 'auto':
|
||||
show_server_state = overview != self._previous_shown
|
||||
show_server_state = state != self._previous_shown
|
||||
if show_server_state:
|
||||
for line in overview:
|
||||
session.log.info('%s', line)
|
||||
givencfgs, remarks = info
|
||||
frappycfgs, seacfgs = state
|
||||
rows = [['', giventitle, 'frappy', 'sea', '']]
|
||||
for key, remark in remarks.items():
|
||||
rows.append([key if key in ('main', 'stick') else 'addon',
|
||||
givencfgs.get(key, ''), frappycfgs.get(key, ''),
|
||||
seacfgs.get(key, ''), remark])
|
||||
wid = [max(len(v) for v in column) for column in zip(*rows)]
|
||||
# insert title underlines
|
||||
rows.insert(1, [''] + ['-' * w for w in wid[1:-1]] + [''])
|
||||
for row in rows:
|
||||
session.log.info('%s', ' '.join(v.ljust(w) for w, v in zip(wid, row)))
|
||||
session.log.info('')
|
||||
# remove 'frappy.has_changed()' commands in script queue
|
||||
controller = session.daemon_device._controller
|
||||
controller.block_requests(r['reqid'] for r in controller.get_queue()
|
||||
if r['script'].startswith('frappy.has_changed()'))
|
||||
self._previous_shown = overview
|
||||
self._previous_shown = state
|
||||
session.log.info(all_info(allcfg))
|
||||
|
||||
if proposed:
|
||||
@ -359,10 +370,10 @@ class FrappyConfig(Device):
|
||||
cfgs['stick'] = running_stick
|
||||
else:
|
||||
cfgs.pop('stick', None)
|
||||
proposed, overview = fm.propose_cfgs(config.instrument, cfgs)
|
||||
self._initial_config = proposed or {}
|
||||
if proposed is not None:
|
||||
self._previous_shown = overview # otherwise the server state will be shown on startup
|
||||
error, proposed, state, info = fm.get_server_state(config.instrument, cfgs, True)
|
||||
if not error:
|
||||
self._initial_config = proposed
|
||||
self._previous_shown = state # otherwise the server state will be shown on startup
|
||||
return self._initial_config.get(service)
|
||||
|
||||
def has_changed(self, show_server_state='auto'):
|
||||
|
Reference in New Issue
Block a user