Skip to content

Commit 9f034c7

Browse files
committed
Update I-CLI to work with current server/client
1 parent 7a4cd8f commit 9f034c7

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

hyperion/user_interfaces/interactiveCLI.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import urwid
22
import threading
33
import re
4-
from time import sleep
54
from os.path import isfile
65
import hyperion.manager
76
import hyperion.lib.util.exception as exceptions
@@ -109,7 +108,7 @@ def __init__(self, cc, event_queue):
109108
self.logger = logging.getLogger(__name__)
110109
self.logger.setLevel(logging.DEBUG)
111110
self.event_queue = event_queue
112-
self.log_viewer = LogTextWalker('%s/info.log' % config.TMP_LOG_PATH)
111+
self.log_viewer = LogTextWalker('%s/client.debug' % config.TMP_LOG_PATH)
113112
self.tail_log = True
114113
self.states = {}
115114
self.host_stats = None
@@ -281,10 +280,9 @@ def fetch_host_items(self):
281280
282281
:return None
283282
"""
284-
285283
hosts = []
286284
for host in self.cc.host_list:
287-
host_object = SimpleButton(host)
285+
host_object = SimpleButton(host, self.handle_host_clicked, user_data=host)
288286
if self.cc.host_list[host]:
289287
host_object = urwid.AttrMap(host_object, 'host', focus_map='reversed')
290288
else:
@@ -305,7 +303,6 @@ def fetch_group_items(self):
305303
306304
:return: None
307305
"""
308-
309306
groups = []
310307
for g in self.cc.config['groups']:
311308

@@ -466,6 +463,17 @@ def handle_stop(self, button, comp):
466463
name='stop_comp_%s' % comp['id'],
467464
).start()
468465

466+
def handle_host_clicked(self, button, host):
467+
self.logger.info("Clicked host '%s'" % host)
468+
if self.cc.host_list[host]:
469+
self.logger.debug("Showing non-component log NIY")
470+
# TODO show server or slave log
471+
elif not self.cc.is_localhost(host):
472+
threading.Thread(
473+
target=self.cc.reconnect_with_host, args=[host],
474+
name='reconnect_%s' % host,
475+
).start()
476+
469477
def stop_component(self, comp):
470478
"""Stop component and run a component check right afterwards to update the ui status.
471479
@@ -495,11 +503,10 @@ def handle_check(self, button, comp):
495503

496504
def handle_log(self, button, comp):
497505
self.logger.info("Clicked log %s" % comp['id'])
498-
499506
local_file_path = '%s/%s/latest.log' % (config.TMP_LOG_PATH, comp['id'])
500507

501508
try:
502-
on_localhost = self.cc.run_on_localhost(comp)
509+
on_localhost = self.cc.run_on_localhost(comp)
503510
except exceptions.HostUnknownException:
504511
self.logger.warn("Host '%s' is unknown and therefore not reachable!" % comp['host'])
505512
return
@@ -529,7 +536,27 @@ def handle_log(self, button, comp):
529536
else:
530537
self.logger.error("Log file '%s' does not exist!" % local_file_path)
531538
else:
532-
self.logger.warning("Remote log display NIY!")
539+
self.logger.info("Opening remote log '%s'" % comp['id'])
540+
log = self.comp_log_map.get(comp['id'], None)
541+
if log:
542+
self.logger.info("Closing '%s' log" % comp['id'])
543+
self.additional_content_grid.contents.remove((log, self.additional_content_grid.options()))
544+
self.comp_log_map[comp['id']] = None
545+
else:
546+
self.logger.info("Opening '%s' log" % comp['id'])
547+
log = urwid.AttrMap(
548+
urwid.LineBox(urwid.BoxAdapter(
549+
urwid.ListBox(
550+
LogTextWalker('%s/debug.log' % config.TMP_LOG_PATH, comp)),
551+
10
552+
), '%s Log' % comp['id']
553+
),
554+
None,
555+
focus_map='simple_button'
556+
)
557+
self.comp_log_map[comp['id']] = log
558+
#self.comp_log_map[comp['id']] = True
559+
self.additional_content_grid.contents.append((log, self.additional_content_grid.options()))
533560

534561
def handle_shutdown(self, button, full=False):
535562
self.full_shutdown = full
@@ -702,6 +729,10 @@ def refresh(_loop, state_controller, _data=None):
702729
logger.debug("Got disconnect event - comp %s" % event.host_name)
703730
logger.warning("Lost connection to host '%s'" % event.host_name)
704731
state_controller.fetch_host_items()
732+
elif isinstance(event, events.ReconnectEvent):
733+
logger.debug("Got reconnect event - comp %s" % event.host_name)
734+
logger.warning("Connection to host '%s' established" % event.host_name)
735+
state_controller.fetch_host_items()
705736
elif isinstance(event, events.StartReportEvent):
706737
logger.debug("Got start report event!")
707738
state_controller.start_report_popup(event)

0 commit comments

Comments
 (0)