comparison sat_frontends/jp/cmd_debug.py @ 3573:813595f88612

merge changes from main branch
author Goffi <goffi@goffi.org>
date Thu, 17 Jun 2021 13:05:58 +0200
parents 04283582966f
children 691dbd78981c
comparison
equal deleted inserted replaced
3541:888109774673 3573:813595f88612
51 51
52 def add_parser_options(self): 52 def add_parser_options(self):
53 self.parser.add_argument( 53 self.parser.add_argument(
54 "method", type=str, help=_("name of the method to execute") 54 "method", type=str, help=_("name of the method to execute")
55 ) 55 )
56 self.parser.add_argument( 56 self.parser.add_argument("arg", nargs="*", help=_("argument of the method"))
57 "arg", nargs="*", help=_("argument of the method")
58 )
59 57
60 async def start(self): 58 async def start(self):
61 method = getattr(self.host.bridge, self.args.method) 59 method = getattr(self.host.bridge, self.args.method)
62 import inspect 60 import inspect
61
63 argspec = inspect.getargspec(method) 62 argspec = inspect.getargspec(method)
64 63
65 kwargs = {} 64 kwargs = {}
66 if 'profile_key' in argspec.args: 65 if "profile_key" in argspec.args:
67 kwargs['profile_key'] = self.profile 66 kwargs["profile_key"] = self.profile
68 elif 'profile' in argspec.args: 67 elif "profile" in argspec.args:
69 kwargs['profile'] = self.profile 68 kwargs["profile"] = self.profile
70 69
71 args = self.evalArgs() 70 args = self.evalArgs()
72 71
73 try: 72 try:
74 ret = await method( 73 ret = await method(
75 *args, 74 *args,
76 **kwargs, 75 **kwargs,
77 ) 76 )
78 except Exception as e: 77 except Exception as e:
79 self.disp(_(f"Error while executing {self.args.method}: {e}"), error=True) 78 self.disp(
79 _("Error while executing {method}: {e}").format(
80 method=self.args.method, e=e
81 ),
82 error=True,
83 )
80 self.host.quit(C.EXIT_ERROR) 84 self.host.quit(C.EXIT_ERROR)
81 else: 85 else:
82 if ret is not None: 86 if ret is not None:
83 self.disp(str(ret)) 87 self.disp(str(ret))
84 self.host.quit() 88 self.host.quit()
90 self, host, "signal", help=_("send a fake signal from backend") 94 self, host, "signal", help=_("send a fake signal from backend")
91 ) 95 )
92 BridgeCommon.__init__(self) 96 BridgeCommon.__init__(self)
93 97
94 def add_parser_options(self): 98 def add_parser_options(self):
95 self.parser.add_argument( 99 self.parser.add_argument("signal", type=str, help=_("name of the signal to send"))
96 "signal", type=str, help=_("name of the signal to send") 100 self.parser.add_argument("arg", nargs="*", help=_("argument of the signal"))
97 )
98 self.parser.add_argument(
99 "arg", nargs="*", help=_("argument of the signal")
100 )
101 101
102 async def start(self): 102 async def start(self):
103 args = self.evalArgs() 103 args = self.evalArgs()
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(self.args.signal, json_args, self.args.profile) 108 await self.host.bridge.debugFakeSignal(
109 self.args.signal, json_args, self.args.profile
110 )
109 except Exception as e: 111 except Exception as e:
110 self.disp(_(f"Can't send fake signal: {e}"), error=True) 112 self.disp(_("Can't send fake signal: {e}").format(e=e), error=True)
111 self.host.quit(C.EXIT_ERROR) 113 self.host.quit(C.EXIT_ERROR)
112 else: 114 else:
113 self.host.quit() 115 self.host.quit()
114 116
115 117
196 def add_parser_options(self): 198 def add_parser_options(self):
197 pass 199 pass
198 200
199 async def start(self): 201 async def start(self):
200 for attr in dir(C): 202 for attr in dir(C):
201 if not attr.startswith('A_'): 203 if not attr.startswith("A_"):
202 continue 204 continue
203 color = getattr(C, attr) 205 color = getattr(C, attr)
204 if attr == 'A_LEVEL_COLORS': 206 if attr == "A_LEVEL_COLORS":
205 # This constant contains multiple colors 207 # This constant contains multiple colors
206 self.disp('LEVEL COLORS: ', end=' ') 208 self.disp("LEVEL COLORS: ", end=" ")
207 for idx, c in enumerate(color): 209 for idx, c in enumerate(color):
208 last = idx == len(color)-1 210 last = idx == len(color) - 1
209 end = '\n' if last else ' ' 211 end = "\n" if last else " "
210 self.disp( 212 self.disp(
211 c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''), 213 c + f"LEVEL_{idx}" + A.RESET + (", " if not last else ""), end=end
212 end=end
213 ) 214 )
214 else: 215 else:
215 text = attr[2:] 216 text = attr[2:]
216 self.disp(A.color(color, text)) 217 self.disp(A.color(color, text))
217 self.host.quit() 218 self.host.quit()