Code review changes.

This fixes the following problems found in a review:

1. Manual modification of the asciidoc has been undone.
2. --output-to-tab has been renamed to the less verbose --output.
3. spawn_output has been changed to spawn-output in the url.
4. Erroneous newline in imports has been removed.
5. output in guiprocess.py has been marked private.
6. If there is no output for either stderr or stdout, say so.
7. Missing space in a text line was added.
8. Redundant initialising of an empty string removed.
This commit is contained in:
George Edward Bulmer 2017-12-08 19:00:46 +00:00
parent 9f9311840a
commit 9f8dbe95e4
4 changed files with 17 additions and 20 deletions

View File

@ -1148,7 +1148,7 @@ Set a mark at the current scroll position in the current tab.
[[spawn]]
=== spawn
Syntax: +:spawn [*--userscript*] [*--verbose*] [*--output-to-tab*] [*--detach*] 'cmdline'+
Syntax: +:spawn [*--userscript*] [*--verbose*] [*--output*] [*--detach*] 'cmdline'+
Spawn a command in a shell.
@ -1163,7 +1163,7 @@ Spawn a command in a shell.
- `/usr/share/qutebrowser/userscripts`
* +*-v*+, +*--verbose*+: Show notifications when the command started/exited.
* +*-v*+, +*--output-to-tab*+: Show stderr, stdout, and exit status in a new tab.
* +*-o*+, +*--output*+: Whether the output should be shown in a new tab.
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
==== note

View File

@ -1178,7 +1178,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0, no_replace_variables=True)
def spawn(self, cmdline, userscript=False, verbose=False,
output_to_tab=False, detach=False):
output=False, detach=False):
"""Spawn a command in a shell.
Args:
@ -1189,6 +1189,7 @@ class CommandDispatcher:
(or `$XDG_DATA_DIR`)
- `/usr/share/qutebrowser/userscripts`
verbose: Show notifications when the command started/exited.
output: Whether the output should be shown in a new tab.
detach: Whether the command should be detached from qutebrowser.
cmdline: The commandline to execute.
"""
@ -1210,7 +1211,7 @@ class CommandDispatcher:
cmd = os.path.expanduser(cmd)
proc = guiprocess.GUIProcess(what='command', verbose=verbose,
parent=self._tabbed_browser,
output_to_tab=output_to_tab)
output=output)
if detach:
proc.start_detached(cmd, args)
else:

View File

@ -269,9 +269,9 @@ def qute_pyeval(_url):
return 'text/html', html
@add_handler('spawn_output')
@add_handler('spawn-output')
def qute_spawn_output(_url):
"""Handler for qute://spawn_output."""
"""Handler for qute://spawn-output."""
html = jinja.render('pre.html', title='spawn output', content=spawn_output)
return 'text/html', html

View File

@ -25,7 +25,6 @@ from PyQt5.QtCore import (pyqtSlot, pyqtSignal, QObject, QProcess,
QProcessEnvironment, QUrl)
from qutebrowser.utils import message, log, objreg
from qutebrowser.browser import qutescheme
# A mapping of QProcess::ErrorCode's to human-readable strings.
@ -50,6 +49,7 @@ class GUIProcess(QObject):
cmd: The command which was started.
args: A list of arguments which gets passed.
verbose: Whether to show more messages.
_output: Whether to show the output in a new tab.
_started: Whether the underlying process is started.
_proc: The underlying QProcess.
_what: What kind of thing is spawned (process/editor/userscript/...).
@ -64,11 +64,11 @@ class GUIProcess(QObject):
started = pyqtSignal()
def __init__(self, what, *, verbose=False, additional_env=None,
parent=None, output_to_tab=False):
parent=None, output=False):
super().__init__(parent)
self._what = what
self.verbose = verbose
self.output_to_tab = output_to_tab
self._output = output
self._started = False
self.cmd = None
self.args = None
@ -100,28 +100,24 @@ class GUIProcess(QObject):
log.procs.debug("Process finished with code {}, status {}.".format(
code, status))
stdout = None
stderr = None
if self.output_to_tab:
if self._output:
stderr = bytes(self._proc.readAllStandardError()).decode('utf-8')
stdout = bytes(self._proc.readAllStandardOutput()).decode('utf-8')
spawn_log = ""
stderr = stderr or "(No output)"
stdout = stdout or "(No output)"
spawn_log += "Process finished with code {},status {}.".format(
spawn_log = "Process finished with code {}, status {}.".format(
code, status)
if stdout:
spawn_log += "\nProcess stdout:\n" + stdout.strip()
if stderr:
spawn_log += "\nProcess stderr:\n" + stderr.strip()
spawn_log += "\nProcess stdout:\n" + stdout.strip()
spawn_log += "\nProcess stderr:\n" + stderr.strip()
qutescheme.spawn_output = spawn_log
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window='last-focused')
tabbed_browser.openurl(QUrl('qute://spawn_output'), newtab=True)
tabbed_browser.openurl(QUrl('qute://spawn-output'), newtab=True)
if status == QProcess.CrashExit:
message.error("{} crashed!".format(self._what.capitalize()))