Handle OSError when using subprocess.
This commit is contained in:
parent
8ec42908f1
commit
655115858c
@ -546,12 +546,16 @@ class Application(QApplication):
|
|||||||
log.destroy.debug("args: {}".format(args))
|
log.destroy.debug("args: {}".format(args))
|
||||||
log.destroy.debug("cwd: {}".format(cwd))
|
log.destroy.debug("cwd: {}".format(cwd))
|
||||||
# Open a new process and immediately shutdown the existing one
|
# Open a new process and immediately shutdown the existing one
|
||||||
if cwd is None:
|
try:
|
||||||
subprocess.Popen(args)
|
if cwd is None:
|
||||||
|
subprocess.Popen(args)
|
||||||
|
else:
|
||||||
|
subprocess.Popen(args, cwd=cwd)
|
||||||
|
except OSError as e:
|
||||||
|
log.destroy.error("Failed to restart: {}".format(e))
|
||||||
else:
|
else:
|
||||||
subprocess.Popen(args, cwd=cwd)
|
if shutdown:
|
||||||
if shutdown:
|
self.shutdown()
|
||||||
self.shutdown()
|
|
||||||
|
|
||||||
@cmdutils.register(instance='app', split=False, debug=True)
|
@cmdutils.register(instance='app', split=False, debug=True)
|
||||||
def debug_pyeval(self, s):
|
def debug_pyeval(self, s):
|
||||||
|
@ -794,7 +794,11 @@ class CommandDispatcher:
|
|||||||
*args: The commandline to execute.
|
*args: The commandline to execute.
|
||||||
"""
|
"""
|
||||||
log.procs.debug("Executing: {}".format(args))
|
log.procs.debug("Executing: {}".format(args))
|
||||||
subprocess.Popen(args)
|
try:
|
||||||
|
subprocess.Popen(args)
|
||||||
|
except OSError as e:
|
||||||
|
raise cmdexc.CommandError("Error while spawning command: "
|
||||||
|
"{}".format(e))
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def home(self):
|
def home(self):
|
||||||
|
@ -420,7 +420,11 @@ class HintManager(QObject):
|
|||||||
"""Spawn a simple command from a hint."""
|
"""Spawn a simple command from a hint."""
|
||||||
urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
|
urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||||
args = self._context.get_args(urlstr)
|
args = self._context.get_args(urlstr)
|
||||||
subprocess.Popen(args)
|
try:
|
||||||
|
subprocess.Popen(args)
|
||||||
|
except OSError as e:
|
||||||
|
msg = "Error while spawning command: {}".format(e)
|
||||||
|
message.error(self._win_id, msg, immediately=True)
|
||||||
|
|
||||||
def _resolve_url(self, elem, baseurl=None):
|
def _resolve_url(self, elem, baseurl=None):
|
||||||
"""Resolve a URL and check if we want to keep it.
|
"""Resolve a URL and check if we want to keep it.
|
||||||
|
@ -96,7 +96,7 @@ def _git_str_subprocess(gitpath):
|
|||||||
['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
||||||
cwd=gitpath).decode('UTF-8').strip()
|
cwd=gitpath).decode('UTF-8').strip()
|
||||||
return '{} ({})'.format(cid, date)
|
return '{} ({})'.format(cid, date)
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
except (subprocess.CalledProcessError, OSError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ def call_asciidoc(src, dst):
|
|||||||
args.append(src)
|
args.append(src)
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(args)
|
subprocess.check_call(args)
|
||||||
except subprocess.CalledProcessError as e:
|
except (subprocess.CalledProcessError, OSError) as e:
|
||||||
utils.print_col(str(e), 'red')
|
utils.print_col(str(e), 'red')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -96,7 +96,7 @@ def _run_subprocess(name, args):
|
|||||||
"""Run a checker via subprocess."""
|
"""Run a checker via subprocess."""
|
||||||
try:
|
try:
|
||||||
return subprocess.call([name] + args)
|
return subprocess.call([name] + args)
|
||||||
except FileNotFoundError:
|
except OSError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ def _git_str():
|
|||||||
['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
||||||
cwd=BASEDIR).decode('UTF-8').strip()
|
cwd=BASEDIR).decode('UTF-8').strip()
|
||||||
return '{} ({})'.format(cid, date)
|
return '{} ({})'.format(cid, date)
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
except (subprocess.CalledProcessError, OSError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user