jp (debug): new monitor command to show pretty formatted XML stream

This commit is contained in:
Goffi 2017-11-04 22:11:45 +01:00
commit 3629bb5c03

View file

@ -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 @@ class Bridge(base.CommandBase):
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'))