annotate libervia/cli/cmd_debug.py @ 4268:51d004e50786

docker (backend): set `+use_local_shared_tmp` in conf.
author Goffi <goffi@goffi.org>
date Thu, 13 Jun 2024 13:22:41 +0200
parents 4ed8de94c926
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3407
diff changeset
5 # Copyright (C) 2009-2021 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
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from . import base
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.i18n import _
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
23 from libervia.cli.constants import Const as C
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.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):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
31 def eval_args(self):
2038
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:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 return eval("[{}]".format(",".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(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
37 "Can't evaluate arguments: {mess}\n{text}\n{offset}^".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
38 mess=e, text=e.text, offset=" " * (e.offset - 1)
2624
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):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
49 base.CommandBase.__init__(self, host, "method", help=_("call a bridge method"))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 BridgeCommon.__init__(self)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 "method", type=str, help=_("name of the method to execute")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 )
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
56 self.parser.add_argument("arg", nargs="*", help=_("argument of the method"))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
58 async def start(self):
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 method = getattr(self.host.bridge, self.args.method)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
60 import inspect
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
61
4101
4ed8de94c926 cli (debug): fix deprecated method call
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
62 argspec = inspect.getfullargspec(method)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 kwargs = {}
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
65 if "profile_key" in argspec.args:
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
66 kwargs["profile_key"] = self.profile
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
67 elif "profile" in argspec.args:
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
68 kwargs["profile"] = self.profile
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
70 args = self.eval_args()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
71
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 try:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
73 ret = await method(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 *args,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
75 **kwargs,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
77 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
78 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
79 _("Error while executing {method}: {e}").format(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
80 method=self.args.method, e=e
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
81 ),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
82 error=True,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
83 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 self.host.quit(C.EXIT_ERROR)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
86 if ret is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
87 self.disp(str(ret))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
88 self.host.quit()
2038
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__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
94 self, host, "signal", help=_("send a fake signal from backend")
2624
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):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 self.parser.add_argument("signal", type=str, help=_("name of the signal to send"))
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
100 self.parser.add_argument("arg", nargs="*", help=_("argument of the signal"))
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
102 async def start(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
103 args = self.eval_args()
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 json_args = json.dumps(args)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 # XXX: we use self.args.profile and not self.profile
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 # because we want the raw profile_key (so plugin handle C.PROF_KEY_NONE)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
107 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
108 await self.host.bridge.debug_signal_fake(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
109 self.args.signal, json_args, self.args.profile
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
110 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
111 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
112 self.disp(_("Can't send fake signal: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
113 self.host.quit(C.EXIT_ERROR)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
114 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
115 self.host.quit()
2038
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
118 class bridge(base.CommandBase):
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 subcommands = (Method, Signal)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 def __init__(self, host):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
122 super(bridge, self).__init__(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 host, "bridge", use_profile=False, help=_("bridge s(t)imulation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
127 class Monitor(base.CommandBase):
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
128 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 super(Monitor, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 "monitor",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 use_output=C.OUTPUT_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 help=_("monitor XML stream"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
137
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
138 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 "-d",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 "--direction",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 choices=("in", "out", "both"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 default="both",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
144 help=_("stream direction filter"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
146
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
147 async def print_xml(self, direction, xml_data, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 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
149 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 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
151 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
152 verbosity = self.host.verbosity
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
153 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
154 if verbosity <= 2:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
155 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
156 whiteping = True
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
157 else:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
158 whiteping = False
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
159
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
160 if verbosity:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 profile_disp = f" ({profile})" if verbosity > 1 else ""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 if direction == "IN":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 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
166 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
168 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 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
172 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
174 if whiteping:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 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
176 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
177 try:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
178 await self.output(xml_data)
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
179 except Exception:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 #  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
181 # in this case we print directly to data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 #  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
183 # 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
184 # 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
185 self.disp(xml_data)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
186 self.disp("")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
187
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
188 async def start(self):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
189 self.host.bridge.register_signal("xml_log", self.print_xml, "plugin")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
190
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
191
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
192 class Theme(base.CommandBase):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
193 def __init__(self, host):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
194 base.CommandBase.__init__(
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
195 self, host, "theme", help=_("print colours used with your background")
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
196 )
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
197
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
198 def add_parser_options(self):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
199 pass
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
200
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
201 async def start(self):
3705
691dbd78981c cli (debug/theme): display currently used background
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
202 print(f"background currently used: {A.BOLD}{self.host.background}{A.RESET}\n")
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
203 for attr in dir(C):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 if not attr.startswith("A_"):
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
205 continue
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
206 color = getattr(C, attr)
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
207 if attr == "A_LEVEL_COLORS":
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
208 # This constant contains multiple colors
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
209 self.disp("LEVEL COLORS: ", end=" ")
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
210 for idx, c in enumerate(color):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
211 last = idx == len(color) - 1
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
212 end = "\n" if last else " "
3407
2f0be2b7de68 jp: replace `no_lf` argument by `end` in `disp` (same as in `print`)
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
213 self.disp(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
214 c + f"LEVEL_{idx}" + A.RESET + (", " if not last else ""), end=end
3407
2f0be2b7de68 jp: replace `no_lf` argument by `end` in `disp` (same as in `print`)
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
215 )
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
216 else:
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
217 text = attr[2:]
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
218 self.disp(A.color(color, text))
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
219 self.host.quit()
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
220
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
221
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 class Debug(base.CommandBase):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3705
diff changeset
223 subcommands = (bridge, Monitor, Theme)
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 super(Debug, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 host, "debug", use_profile=False, help=_("debugging tools")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 )