comparison libervia/cli/cmd_input.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 47401850dec6
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
192 self.disp( 192 self.disp(
193 _("arguments in input data and in arguments sequence don't match"), 193 _("arguments in input data and in arguments sequence don't match"),
194 error=True, 194 error=True,
195 ) 195 )
196 self.host.quit(C.EXIT_DATA_ERROR) 196 self.host.quit(C.EXIT_DATA_ERROR)
197 end = '\n' if self.args.debug else ' ' 197 end = "\n" if self.args.debug else " "
198 self.disp( 198 self.disp(
199 A.color(C.A_HEADER, _("command {idx}").format(idx=self.idx)), 199 A.color(C.A_HEADER, _("command {idx}").format(idx=self.idx)),
200 end = end, 200 end=end,
201 ) 201 )
202 stdin = "".join(self._stdin) 202 stdin = "".join(self._stdin)
203 if self.args.debug: 203 if self.args.debug:
204 self.disp( 204 self.disp(
205 A.color( 205 A.color(
206 C.A_SUBHEADER, 206 C.A_SUBHEADER,
207 _("values: "), 207 _("values: "),
208 A.RESET, 208 A.RESET,
209 ", ".join([shlex.quote(a) for a in self._values_ori]) 209 ", ".join([shlex.quote(a) for a in self._values_ori]),
210 ), 210 ),
211 2, 211 2,
212 ) 212 )
213 213
214 if stdin: 214 if stdin:
225 positionals=" ".join(shlex.quote(p) for p in self._pos), 225 positionals=" ".join(shlex.quote(p) for p in self._pos),
226 ) 226 )
227 ) 227 )
228 self.disp("\n") 228 self.disp("\n")
229 else: 229 else:
230 self.disp(" (" + ", ".join(self._values_ori) + ")", 2, end=' ') 230 self.disp(" (" + ", ".join(self._values_ori) + ")", 2, end=" ")
231 args = [sys.argv[0]] + self.args.command + self._opts + self._pos 231 args = [sys.argv[0]] + self.args.command + self._opts + self._pos
232 p = await asyncio.create_subprocess_exec( 232 p = await asyncio.create_subprocess_exec(
233 *args, 233 *args,
234 stdin=subprocess.PIPE, 234 stdin=subprocess.PIPE,
235 stdout=subprocess.PIPE, 235 stdout=subprocess.PIPE,
236 stderr=subprocess.PIPE, 236 stderr=subprocess.PIPE,
237 ) 237 )
238 stdout, stderr = await p.communicate(stdin.encode('utf-8')) 238 stdout, stderr = await p.communicate(stdin.encode("utf-8"))
239 log = self.args.log 239 log = self.args.log
240 log_err = self.args.log_err 240 log_err = self.args.log_err
241 log_tpl = "{command}\n{buff}\n\n" 241 log_tpl = "{command}\n{buff}\n\n"
242 if log: 242 if log:
243 log.write(log_tpl.format( 243 log.write(
244 command=" ".join(shlex.quote(a) for a in args), 244 log_tpl.format(
245 buff=stdout.decode('utf-8', 'replace'))) 245 command=" ".join(shlex.quote(a) for a in args),
246 buff=stdout.decode("utf-8", "replace"),
247 )
248 )
246 if log_err: 249 if log_err:
247 log_err.write(log_tpl.format( 250 log_err.write(
248 command=" ".join(shlex.quote(a) for a in args), 251 log_tpl.format(
249 buff=stderr.decode('utf-8', 'replace'))) 252 command=" ".join(shlex.quote(a) for a in args),
253 buff=stderr.decode("utf-8", "replace"),
254 )
255 )
250 ret = p.returncode 256 ret = p.returncode
251 if ret == 0: 257 if ret == 0:
252 self.disp(A.color(C.A_SUCCESS, _("OK"))) 258 self.disp(A.color(C.A_SUCCESS, _("OK")))
253 else: 259 else:
254 self.disp(A.color(C.A_FAILURE, _("FAILED"))) 260 self.disp(A.color(C.A_FAILURE, _("FAILED")))