# HG changeset patch # User Goffi # Date 1509829905 -3600 # Node ID 192ae573901a5db2164578016cc3e6ad9a3bc318 # Parent e2cbd449c0028f7e6acff91267751b12a930452b jp (debug): new monitor command to show pretty formatted XML stream diff -r e2cbd449c002 -r 192ae573901a frontends/src/jp/cmd_debug.py --- a/frontends/src/jp/cmd_debug.py Sat Nov 04 22:11:01 2017 +0100 +++ b/frontends/src/jp/cmd_debug.py Sat Nov 04 22:11:45 2017 +0100 @@ -21,6 +21,7 @@ import base from sat.core.i18n import _ from sat_frontends.jp.constants import Const as C +from sat.tools.common.ansi import ANSI as A import json __commands__ = ["Debug"] @@ -101,8 +102,50 @@ super(Bridge, self).__init__(host, 'bridge', use_profile=False, help=_('bridge s(t)imulation')) +class Monitor(base.CommandBase): + + def __init__(self, host): + super(Monitor, self).__init__(host, + 'monitor', + use_verbose=True, + use_profile=False, + use_output=C.OUTPUT_XML, + help=_('monitor XML stream')) + self.need_loop = True + + def add_parser_options(self): + self.parser.add_argument("-d", "--direction", choices=('in', 'out', 'both'), default='both', help=_(u"stream direction filter")) + + def printXML(self, direction, xml_data, profile): + if self.args.direction == 'in' and direction != 'IN': + return + if self.args.direction == 'out' and direction != 'OUT': + return + verbosity = self.host.verbosity + if not xml_data.strip(): + if verbosity <= 2: + return + whiteping = True + else: + whiteping = False + + if verbosity: + profile_disp = u' ({})'.format(profile) if verbosity>1 else u'' + if direction == 'IN': + self.disp(A.color(A.BOLD, A.FG_YELLOW, '<<<===== IN ====', A.FG_WHITE, profile_disp)) + else: + self.disp(A.color(A.BOLD, A.FG_CYAN, '==== OUT ====>>>', A.FG_WHITE, profile_disp)) + if whiteping: + self.disp('[WHITESPACE PING]') + else: + self.output(xml_data) + + def start(self): + self.host.bridge.register_signal('xmlLog', self.printXML, 'plugin') + + class Debug(base.CommandBase): - subcommands = (Bridge,) + subcommands = (Bridge, Monitor) def __init__(self, host): super(Debug, self).__init__(host, 'debug', use_profile=False, help=_('debugging tools'))