mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Do not pipe stderr, cause it hides ffmpeg output (#115)
* Do not pipe stderr, cause it hides ffmpeg output * Improve cmd failed message
This commit is contained in:
parent
568e15aecb
commit
c567e3c599
2 changed files with 14 additions and 16 deletions
|
@ -398,8 +398,7 @@ class Controller:
|
|||
f.write(msg.text_content)
|
||||
f.flush()
|
||||
with suspend(self.view) as s:
|
||||
if err_msg := s.open_file(f.name, cmd):
|
||||
self.present_error(err_msg)
|
||||
s.open_file(f.name, cmd)
|
||||
return
|
||||
|
||||
path = msg.local_path
|
||||
|
@ -411,15 +410,20 @@ class Controller:
|
|||
return
|
||||
self.tg.open_message_content(chat_id, msg.msg_id)
|
||||
with suspend(self.view) as s:
|
||||
if err_msg := s.open_file(path, cmd):
|
||||
self.present_error(err_msg)
|
||||
s.open_file(path, cmd)
|
||||
|
||||
@bind(msg_handler, ["!"])
|
||||
def open_msg_with_cmd(self) -> None:
|
||||
"""Open msg or file with cmd: less %s"""
|
||||
msg = MsgProxy(self.model.current_msg)
|
||||
if cmd := self.view.status.get_input():
|
||||
return self._open_msg(msg, cmd)
|
||||
cmd = self.view.status.get_input()
|
||||
if not cmd:
|
||||
return
|
||||
if "%s" not in cmd:
|
||||
return self.present_error(
|
||||
"command should contain <%s> which will be replaced by file path"
|
||||
)
|
||||
return self._open_msg(msg, cmd)
|
||||
|
||||
@bind(msg_handler, ["l", "^J"])
|
||||
def open_current_msg(self) -> None:
|
||||
|
|
14
tg/utils.py
14
tg/utils.py
|
@ -184,26 +184,20 @@ class suspend:
|
|||
self.view = view
|
||||
|
||||
def call(self, cmd: str) -> CompletedProcess:
|
||||
return subprocess.run(cmd, shell=True, stderr=subprocess.PIPE)
|
||||
return subprocess.run(cmd, shell=True)
|
||||
|
||||
def run_with_input(self, cmd: str, text: str) -> None:
|
||||
subprocess.run(cmd, universal_newlines=True, input=text, shell=True)
|
||||
|
||||
def open_file(self, file_path: str, cmd: str = None) -> str:
|
||||
def open_file(self, file_path: str, cmd: str = None) -> None:
|
||||
if cmd:
|
||||
try:
|
||||
cmd = cmd % shlex.quote(file_path)
|
||||
except TypeError:
|
||||
return "command should contain <%s> which will be replaced by file path"
|
||||
cmd = cmd % shlex.quote(file_path)
|
||||
else:
|
||||
cmd = get_file_handler(file_path)
|
||||
|
||||
proc = self.call(cmd)
|
||||
if proc.returncode:
|
||||
stderr = proc.stderr.decode()
|
||||
log.error("Error happened executing <%s>:\n%s", cmd, stderr)
|
||||
return stderr
|
||||
return ""
|
||||
input(f"Command <{cmd}> failed: press <enter> to continue")
|
||||
|
||||
def __enter__(self) -> "suspend":
|
||||
for view in (self.view.chats, self.view.msgs, self.view.status):
|
||||
|
|
Loading…
Reference in a new issue