comparison sat_frontends/jp/cmd_debug.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 691dbd78981c
children 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
26 26
27 __commands__ = ["Debug"] 27 __commands__ = ["Debug"]
28 28
29 29
30 class BridgeCommon(object): 30 class BridgeCommon(object):
31 def evalArgs(self): 31 def eval_args(self):
32 if self.args.arg: 32 if self.args.arg:
33 try: 33 try:
34 return eval("[{}]".format(",".join(self.args.arg))) 34 return eval("[{}]".format(",".join(self.args.arg)))
35 except SyntaxError as e: 35 except SyntaxError as e:
36 self.disp( 36 self.disp(
65 if "profile_key" in argspec.args: 65 if "profile_key" in argspec.args:
66 kwargs["profile_key"] = self.profile 66 kwargs["profile_key"] = self.profile
67 elif "profile" in argspec.args: 67 elif "profile" in argspec.args:
68 kwargs["profile"] = self.profile 68 kwargs["profile"] = self.profile
69 69
70 args = self.evalArgs() 70 args = self.eval_args()
71 71
72 try: 72 try:
73 ret = await method( 73 ret = await method(
74 *args, 74 *args,
75 **kwargs, 75 **kwargs,
98 def add_parser_options(self): 98 def add_parser_options(self):
99 self.parser.add_argument("signal", type=str, help=_("name of the signal to send")) 99 self.parser.add_argument("signal", type=str, help=_("name of the signal to send"))
100 self.parser.add_argument("arg", nargs="*", help=_("argument of the signal")) 100 self.parser.add_argument("arg", nargs="*", help=_("argument of the signal"))
101 101
102 async def start(self): 102 async def start(self):
103 args = self.evalArgs() 103 args = self.eval_args()
104 json_args = json.dumps(args) 104 json_args = json.dumps(args)
105 # XXX: we use self.args.profile and not self.profile 105 # XXX: we use self.args.profile and not self.profile
106 # because we want the raw profile_key (so plugin handle C.PROF_KEY_NONE) 106 # because we want the raw profile_key (so plugin handle C.PROF_KEY_NONE)
107 try: 107 try:
108 await self.host.bridge.debugFakeSignal( 108 await self.host.bridge.debug_signal_fake(
109 self.args.signal, json_args, self.args.profile 109 self.args.signal, json_args, self.args.profile
110 ) 110 )
111 except Exception as e: 111 except Exception as e:
112 self.disp(_("Can't send fake signal: {e}").format(e=e), error=True) 112 self.disp(_("Can't send fake signal: {e}").format(e=e), error=True)
113 self.host.quit(C.EXIT_ERROR) 113 self.host.quit(C.EXIT_ERROR)
114 else: 114 else:
115 self.host.quit() 115 self.host.quit()
116 116
117 117
118 class Bridge(base.CommandBase): 118 class bridge(base.CommandBase):
119 subcommands = (Method, Signal) 119 subcommands = (Method, Signal)
120 120
121 def __init__(self, host): 121 def __init__(self, host):
122 super(Bridge, self).__init__( 122 super(bridge, self).__init__(
123 host, "bridge", use_profile=False, help=_("bridge s(t)imulation") 123 host, "bridge", use_profile=False, help=_("bridge s(t)imulation")
124 ) 124 )
125 125
126 126
127 class Monitor(base.CommandBase): 127 class Monitor(base.CommandBase):
142 choices=("in", "out", "both"), 142 choices=("in", "out", "both"),
143 default="both", 143 default="both",
144 help=_("stream direction filter"), 144 help=_("stream direction filter"),
145 ) 145 )
146 146
147 async def printXML(self, direction, xml_data, profile): 147 async def print_xml(self, direction, xml_data, profile):
148 if self.args.direction == "in" and direction != "IN": 148 if self.args.direction == "in" and direction != "IN":
149 return 149 return
150 if self.args.direction == "out" and direction != "OUT": 150 if self.args.direction == "out" and direction != "OUT":
151 return 151 return
152 verbosity = self.host.verbosity 152 verbosity = self.host.verbosity
184 # should be wrapped in a custom Exception 184 # should be wrapped in a custom Exception
185 self.disp(xml_data) 185 self.disp(xml_data)
186 self.disp("") 186 self.disp("")
187 187
188 async def start(self): 188 async def start(self):
189 self.host.bridge.register_signal("xmlLog", self.printXML, "plugin") 189 self.host.bridge.register_signal("xml_log", self.print_xml, "plugin")
190 190
191 191
192 class Theme(base.CommandBase): 192 class Theme(base.CommandBase):
193 def __init__(self, host): 193 def __init__(self, host):
194 base.CommandBase.__init__( 194 base.CommandBase.__init__(
218 self.disp(A.color(color, text)) 218 self.disp(A.color(color, text))
219 self.host.quit() 219 self.host.quit()
220 220
221 221
222 class Debug(base.CommandBase): 222 class Debug(base.CommandBase):
223 subcommands = (Bridge, Monitor, Theme) 223 subcommands = (bridge, Monitor, Theme)
224 224
225 def __init__(self, host): 225 def __init__(self, host):
226 super(Debug, self).__init__( 226 super(Debug, self).__init__(
227 host, "debug", use_profile=False, help=_("debugging tools") 227 host, "debug", use_profile=False, help=_("debugging tools")
228 ) 228 )