annotate sat_frontends/jp/cmd_debug.py @ 3254:6cf4bd6972c2

core, frontends: avatar refactoring: /!\ huge commit Avatar logic has been reworked around the IDENTITY plugin: plugins able to handle avatar or other identity related metadata (like nicknames) register to IDENTITY plugin in the same way as for other features like download/upload. Once registered, IDENTITY plugin will call them when suitable in order of priority, and handle caching. Methods to manage those metadata from frontend now use serialised data. For now `avatar` and `nicknames` are handled: - `avatar` is now a dict with `path` + metadata like `media_type`, instead of just a string path - `nicknames` is now a list of nicknames in order of priority. This list is never empty, and `nicknames[0]` should be the preferred nickname to use by frontends in most cases. In addition to contact specified nicknames, user set nickname (the one set in roster) is used in priority when available. Among the side changes done with this commit, there are: - a new `contactGet` bridge method to get roster metadata for a single contact - SatPresenceProtocol.send returns a Deferred to check when it has actually been sent - memory's methods to handle entities data now use `client` as first argument - metadata filter can be specified with `getIdentity` - `getAvatar` and `setAvatar` are now part of the IDENTITY plugin instead of XEP-0054 (and there signature has changed) - `isRoom` and `getBareOrFull` are now part of XEP-0045 plugin - jp avatar/get command uses `xdg-open` first when available for `--show` flag - `--no-cache` has been added to jp avatar/get and identity/get - jp identity/set has been simplified, explicit options (`--nickname` only for now) are used instead of `--field`. `--field` may come back in the future if necessary for extra data. - QuickContactList `SetContact` now handle None as a value, and doesn't use it to delete the metadata anymore - improved cache handling for `metadata` and `nicknames` in quick frontend - new `default` argument in QuickContactList `getCache`
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 21:00:33 +0200
parents 559a625a236b
children 2f0be2b7de68
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
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3047
diff changeset
5 # Copyright (C) 2009-2020 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
2038
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:
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 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
57 "arg", nargs="*", help=_("argument of the method")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
60 async def start(self):
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 method = getattr(self.host.bridge, self.args.method)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
62 import inspect
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 argspec = inspect.getargspec(method)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 kwargs = {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 if 'profile_key' in argspec.args:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 kwargs['profile_key'] = self.profile
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68 elif 'profile' in argspec.args:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 kwargs['profile'] = self.profile
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 args = self.evalArgs()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
72
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 try:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
74 ret = await method(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 *args,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
76 **kwargs,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
79 self.disp(_(f"Error while executing {self.args.method}: {e}"), error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
80 self.host.quit(C.EXIT_ERROR)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 if ret is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 self.disp(str(ret))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 self.host.quit()
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
85
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 class Signal(base.CommandBase, BridgeCommon):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 base.CommandBase.__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
90 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
91 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 BridgeCommon.__init__(self)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
93
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
96 "signal", type=str, help=_("name of the signal to send")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
99 "arg", nargs="*", help=_("argument of the signal")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 )
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):
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 args = self.evalArgs()
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:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
108 await self.host.bridge.debugFakeSignal(self.args.signal, json_args, self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
109 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
110 self.disp(_(f"Can't send fake signal: {e}"), error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
111 self.host.quit(C.EXIT_ERROR)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
112 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
113 self.host.quit()
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
114
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 class Bridge(base.CommandBase):
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 subcommands = (Method, Signal)
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
118
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 super(Bridge, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 host, "bridge", use_profile=False, help=_("bridge s(t)imulation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 )
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
123
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
125 class Monitor(base.CommandBase):
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
126 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 super(Monitor, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 "monitor",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 use_output=C.OUTPUT_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 help=_("monitor XML stream"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
135
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
136 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 "-d",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 "--direction",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 choices=("in", "out", "both"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 default="both",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
142 help=_("stream direction filter"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
144
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 async def printXML(self, direction, xml_data, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 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
147 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 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
149 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
150 verbosity = self.host.verbosity
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
151 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
152 if verbosity <= 2:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
153 return
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
154 whiteping = True
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
155 else:
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
156 whiteping = False
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
157
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
158 if verbosity:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 profile_disp = f" ({profile})" if verbosity > 1 else ""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 if direction == "IN":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 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
164 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
166 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 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
170 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 )
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
172 if whiteping:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 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
174 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
175 try:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
176 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
177 except Exception:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 #  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
179 # in this case we print directly to data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 #  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
181 # 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
182 # 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
183 self.disp(xml_data)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
184 self.disp("")
2417
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
185
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 async def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 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
188
192ae573901a jp (debug): new monitor command to show pretty formatted XML stream
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
189
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
190 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
191 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
192 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
193 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
194 )
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
195
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
196 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
197 pass
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
198
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
199 async def start(self):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
200 for attr in dir(C):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
201 if not attr.startswith('A_'):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
202 continue
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
203 color = getattr(C, attr)
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
204 if attr == 'A_LEVEL_COLORS':
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
205 # This constant contains multiple colors
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
206 self.disp('LEVEL COLORS: ', no_lf=True)
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
207 for idx, c in enumerate(color):
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
208 last = idx == len(color)-1
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
209 self.disp(c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''), no_lf=not last)
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
210 else:
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
211 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
212 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
213 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
214
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
215
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 class Debug(base.CommandBase):
3047
cf843dd7c345 jp (debug): new "theme" command to print colour theme according to `background` value:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
217 subcommands = (Bridge, Monitor, Theme)
2038
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
218
3a5badbb443d jp: added jp/debug commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 super(Debug, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 host, "debug", use_profile=False, help=_("debugging tools")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 )