external: do not crash if command can't be found
This commit is contained in:
parent
0a05d75e6b
commit
52716e66a7
|
@ -675,7 +675,10 @@ class Browser:
|
|||
return
|
||||
|
||||
command = self.config["source_editor"] + [source_filename]
|
||||
open_external_program(command)
|
||||
success = open_external_program(command)
|
||||
if not success:
|
||||
self.set_status_error("Could not open editor.")
|
||||
|
||||
if delete_source_after:
|
||||
os.unlink(source_filename)
|
||||
self.refresh_windows()
|
||||
|
|
|
@ -200,7 +200,9 @@ class CommandLine:
|
|||
return
|
||||
|
||||
command = self.editor_command + [temp_filepath]
|
||||
open_external_program(command)
|
||||
success = open_external_program(command)
|
||||
if not success:
|
||||
return
|
||||
|
||||
try:
|
||||
with open(temp_filepath, "rt") as temp_file:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Call external commands."""
|
||||
|
||||
import curses
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
|
@ -9,12 +10,21 @@ def open_external_program(command):
|
|||
|
||||
The caller has to refresh whatever windows it manages after calling this
|
||||
method or garbage may be left on the screen.
|
||||
|
||||
Returns:
|
||||
True if no exception occured.
|
||||
"""
|
||||
curses.nocbreak()
|
||||
curses.echo()
|
||||
curses.curs_set(1)
|
||||
result = True
|
||||
try:
|
||||
subprocess.run(command)
|
||||
except OSError as exc:
|
||||
logging.error(f"Failed to run '{command}': {exc}")
|
||||
result = False
|
||||
curses.mousemask(curses.ALL_MOUSE_EVENTS)
|
||||
curses.curs_set(0)
|
||||
curses.noecho()
|
||||
curses.cbreak()
|
||||
return result
|
||||
|
|
Reference in a new issue