From 4b988e063396ce85bc796d17eb0152f2d02be67f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 8 Apr 2022 12:29:45 -0400 Subject: [PATCH] Integrate logreader into nodeconsole as a feature --- confluent_client/bin/nodeconsole | 12 +++++++++++ confluent_client/confluent/logreader.py | 28 ++++++++++++------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/confluent_client/bin/nodeconsole b/confluent_client/bin/nodeconsole index b52f0096..be15c733 100755 --- a/confluent_client/bin/nodeconsole +++ b/confluent_client/bin/nodeconsole @@ -25,6 +25,7 @@ if path.startswith('/opt'): sys.path.append(path) import confluent.client as client import confluent.sortutil as sortutil +import confluent.logreader as logreader confettypath = os.path.join(os.path.dirname(sys.argv[0]), 'confetty') argparser = optparse.OptionParser( @@ -35,10 +36,21 @@ argparser = optparse.OptionParser( "console") argparser.add_option('-t', '--tile', action='store_true', default=False, help='Tile console windows in the terminal') +argparser.add_option('-l', '--log', action='store_true', default=False, + help='Enter log replay mode instead of showing a live console') (options, args) = argparser.parse_args() if len(args) != 1: argparser.print_help() sys.exit(1) +if options.log: + logname = args[0] + if not os.path.exists(logname) and logname[0] != '/': + logname = os.path.join('/var/log/confluent/consoles', logname) + if not os.path.exists(logname): + sys.stderr.write('Unable to locate {0} on local system\n'.format(logname)) + sys.exit(1) + logreader.replay_to_console(logname) + sys.exit(0) if options.tile: null = open('/dev/null', 'w') nodes = [] diff --git a/confluent_client/confluent/logreader.py b/confluent_client/confluent/logreader.py index 3185282b..bed32c22 100644 --- a/confluent_client/confluent/logreader.py +++ b/confluent_client/confluent/logreader.py @@ -174,7 +174,7 @@ class LogReplay(object): return output, 0 -def main(txtfile, binfile): +def _replay_to_console(txtfile, binfile): replay = LogReplay(txtfile, binfile) oldtcattr = termios.tcgetattr(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno()) @@ -275,19 +275,17 @@ def main(txtfile, binfile): termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr) writeout('\x1b[m\x1b[?25h\n') -if __name__ == '__main__': - txtfile = sys.argv[1] - if len(sys.argv) > 2: - binfile = sys.argv[2] +def replay_to_console(txtfile): + if os.path.exists(txtfile + '.cbl'): + binfile = txtfile + '.cbl' else: - if os.path.exists(txtfile + '.cbl'): - binfile = txtfile + '.cbl' - else: - fileparts = txtfile.split('.') - prefix = '.'.join(fileparts[:-1]) - binfile = prefix + '.cbl.' + fileparts[-1] - if not os.path.exists(binfile): - sys.stderr.write('Unable to locate cbl file\n') - sys.exit(1) - main(txtfile, binfile) + fileparts = txtfile.split('.') + prefix = '.'.join(fileparts[:-1]) + binfile = prefix + '.cbl.' + fileparts[-1] + if not os.path.exists(binfile): + sys.stderr.write('Unable to locate cbl file\n') + sys.exit(1) + _replay_to_console(txtfile, binfile) +if __name__ == '__main__': + replay_to_console(sys.argv[1]) \ No newline at end of file