annotate sat_frontends/jp/cmd_debug.py @ 3013:860c550028d6

memory (sqlite): properly wait for messages to be writen in database: the deferreds of the queries writing message to databases where not gathered and returned, so the caller was not waiting for them to continue its workflow. This was resulting in messages not always written when database was read just after the write (a case common with MUC implementation), and message was appearing empty when sent to bridge. fix 328
author Goffi <goffi@goffi.org>
date Thu, 18 Jul 2019 21:58:34 +0200
parents 003b8b4b56a7
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
24 from sat.tools.common.ansi import ANSI as A
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import json
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 __commands__ = ["Debug"]
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 class BridgeCommon(object):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def evalArgs(self):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 if self.args.arg:
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 return eval(u"[{}]".format(u",".join(self.args.arg)))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 except SyntaxError as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 u"Can't evaluate arguments: {mess}\n{text}\n{offset}^".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 mess=e, text=e.text.decode("utf-8"), offset=u" " * (e.offset - 1)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.host.quit(C.EXIT_BAD_ARG)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 else:
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 return []
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 class Method(base.CommandBase, BridgeCommon):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 base.CommandBase.__init__(self, host, "method", help=_(u"call a bridge method"))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 BridgeCommon.__init__(self)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 self.need_loop = True
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 "method", type=str, help=_(u"name of the method to execute")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 "arg", type=base.unicode_decoder, nargs="*", help=_(u"argument of the method")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
2053
a3c2866841f7 jp (debug): method callback now handles methods without return value
Goffi <goffi@goffi.org>
parents: 2041
diff changeset
61 def method_cb(self, ret=None):
a3c2866841f7 jp (debug): method callback now handles methods without return value
Goffi <goffi@goffi.org>
parents: 2041
diff changeset
62 if ret is not None:
a3c2866841f7 jp (debug): method callback now handles methods without return value
Goffi <goffi@goffi.org>
parents: 2041
diff changeset
63 self.disp(unicode(ret))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.host.quit()
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def method_eb(self, failure):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 _(u"Error while executing {}: {}".format(self.args.method, failure)),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.host.quit(C.EXIT_ERROR)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def start(self):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 method = getattr(self.host.bridge, self.args.method)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 args = self.evalArgs()
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 method(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 *args,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 profile=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 callback=self.method_cb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 errback=self.method_eb
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 except TypeError:
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 # maybe the method doesn't need a profile ?
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 try:
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 method(*args, callback=self.method_cb, errback=self.method_eb)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 except TypeError:
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.method_eb(_(u"bad arguments"))
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 class Signal(base.CommandBase, BridgeCommon):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 self, host, "signal", help=_(u"send a fake signal from backend")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 BridgeCommon.__init__(self)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 "signal", type=str, help=_(u"name of the signal to send")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 "arg", type=base.unicode_decoder, nargs="*", help=_(u"argument of the signal")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def start(self):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 args = self.evalArgs()
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 json_args = json.dumps(args)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 # XXX: we use self.args.profile and not self.profile
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 # because we want the raw profile_key (so plugin handle C.PROF_KEY_NONE)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.host.bridge.debugFakeSignal(self.args.signal, json_args, self.args.profile)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 class Bridge(base.CommandBase):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 subcommands = (Method, Signal)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 super(Bridge, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 host, "bridge", use_profile=False, help=_("bridge s(t)imulation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
122
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
123 class Monitor(base.CommandBase):
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
124 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 super(Monitor, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 "monitor",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 use_output=C.OUTPUT_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 help=_("monitor XML stream"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
133 self.need_loop = True
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
134
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
135 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 "-d",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 "--direction",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 choices=("in", "out", "both"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 default="both",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 help=_(u"stream direction filter"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
143
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
144 def printXML(self, direction, xml_data, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 if self.args.direction == "in" and direction != "IN":
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
146 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
147 if self.args.direction == "out" and direction != "OUT":
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
148 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
149 verbosity = self.host.verbosity
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
150 if not xml_data.strip():
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
151 if verbosity <= 2:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
152 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
153 whiteping = True
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
154 else:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
155 whiteping = False
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
156
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
157 if verbosity:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 profile_disp = u" ({})".format(profile) if verbosity > 1 else u""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 if direction == "IN":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 A.BOLD, A.FG_YELLOW, "<<<===== IN ====", A.FG_WHITE, profile_disp
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
165 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 A.BOLD, A.FG_CYAN, "==== OUT ====>>>", A.FG_WHITE, profile_disp
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
171 if whiteping:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 self.disp("[WHITESPACE PING]")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
173 else:
2441
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
174 try:
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
175 self.output(xml_data)
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
176 except Exception:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 #  initial stream is not valid XML,
2441
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
178 # in this case we print directly to data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 #  FIXME: we should test directly lxml.etree.XMLSyntaxError
2441
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
180 # but importing lxml directly here is not clean
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
181 # should be wrapped in a custom Exception
e86dc8cb4345 jp (debug/monitor): if data can't be parsed (happen at beginning/end of stream because it's not complete XML), it is printed directly.
Goffi <goffi@goffi.org>
parents: 2417
diff changeset
182 self.disp(xml_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 self.disp(u"")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
184
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
185 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 self.host.bridge.register_signal("xmlLog", self.printXML, "plugin")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
187
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
188
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 class Debug(base.CommandBase):
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
190 subcommands = (Bridge, Monitor)
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 super(Debug, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 host, "debug", use_profile=False, help=_("debugging tools")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 )