comparison frontends/src/jp/cmd_debug.py @ 2417:192ae573901a

jp (debug): new monitor command to show pretty formatted XML stream
author Goffi <goffi@goffi.org>
date Sat, 04 Nov 2017 22:11:45 +0100
parents 8b37a62336c3
children e86dc8cb4345
comparison
equal deleted inserted replaced
2416:e2cbd449c002 2417:192ae573901a
19 19
20 20
21 import base 21 import base
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat.tools.common.ansi import ANSI as A
24 import json 25 import json
25 26
26 __commands__ = ["Debug"] 27 __commands__ = ["Debug"]
27 28
28 29
99 100
100 def __init__(self, host): 101 def __init__(self, host):
101 super(Bridge, self).__init__(host, 'bridge', use_profile=False, help=_('bridge s(t)imulation')) 102 super(Bridge, self).__init__(host, 'bridge', use_profile=False, help=_('bridge s(t)imulation'))
102 103
103 104
105 class Monitor(base.CommandBase):
106
107 def __init__(self, host):
108 super(Monitor, self).__init__(host,
109 'monitor',
110 use_verbose=True,
111 use_profile=False,
112 use_output=C.OUTPUT_XML,
113 help=_('monitor XML stream'))
114 self.need_loop = True
115
116 def add_parser_options(self):
117 self.parser.add_argument("-d", "--direction", choices=('in', 'out', 'both'), default='both', help=_(u"stream direction filter"))
118
119 def printXML(self, direction, xml_data, profile):
120 if self.args.direction == 'in' and direction != 'IN':
121 return
122 if self.args.direction == 'out' and direction != 'OUT':
123 return
124 verbosity = self.host.verbosity
125 if not xml_data.strip():
126 if verbosity <= 2:
127 return
128 whiteping = True
129 else:
130 whiteping = False
131
132 if verbosity:
133 profile_disp = u' ({})'.format(profile) if verbosity>1 else u''
134 if direction == 'IN':
135 self.disp(A.color(A.BOLD, A.FG_YELLOW, '<<<===== IN ====', A.FG_WHITE, profile_disp))
136 else:
137 self.disp(A.color(A.BOLD, A.FG_CYAN, '==== OUT ====>>>', A.FG_WHITE, profile_disp))
138 if whiteping:
139 self.disp('[WHITESPACE PING]')
140 else:
141 self.output(xml_data)
142
143 def start(self):
144 self.host.bridge.register_signal('xmlLog', self.printXML, 'plugin')
145
146
104 class Debug(base.CommandBase): 147 class Debug(base.CommandBase):
105 subcommands = (Bridge,) 148 subcommands = (Bridge, Monitor)
106 149
107 def __init__(self, host): 150 def __init__(self, host):
108 super(Debug, self).__init__(host, 'debug', use_profile=False, help=_('debugging tools')) 151 super(Debug, self).__init__(host, 'debug', use_profile=False, help=_('debugging tools'))