Add -v (not -q) to :spawn and make it work with -u.
This commit is contained in:
parent
84dacc9bc8
commit
5828bbafe9
@ -922,7 +922,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
win_id='win_id')
|
win_id='win_id')
|
||||||
def spawn(self, win_id, userscript=False, quiet=False, detach=False,
|
def spawn(self, win_id, userscript=False, verbose=False, detach=False,
|
||||||
*args):
|
*args):
|
||||||
"""Spawn a command in a shell.
|
"""Spawn a command in a shell.
|
||||||
|
|
||||||
@ -931,7 +931,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
userscript: Run the command as an userscript.
|
userscript: Run the command as an userscript.
|
||||||
quiet: Don't print the commandline being executed.
|
verbose: Show notifications when the command started/exited.
|
||||||
detach: Whether the command should be detached from qutebrowser.
|
detach: Whether the command should be detached from qutebrowser.
|
||||||
*args: The commandline to execute.
|
*args: The commandline to execute.
|
||||||
"""
|
"""
|
||||||
@ -939,10 +939,10 @@ class CommandDispatcher:
|
|||||||
args, userscript))
|
args, userscript))
|
||||||
cmd, *args = args
|
cmd, *args = args
|
||||||
if userscript:
|
if userscript:
|
||||||
self.run_userscript(cmd, *args)
|
self.run_userscript(cmd, *args, verbose=verbose)
|
||||||
else:
|
else:
|
||||||
proc = guiprocess.GUIProcess(self._win_id, what='command',
|
proc = guiprocess.GUIProcess(self._win_id, what='command',
|
||||||
verbose=not quiet,
|
verbose=verbose,
|
||||||
parent=self._tabbed_browser)
|
parent=self._tabbed_browser)
|
||||||
if detach:
|
if detach:
|
||||||
proc.start_detached(cmd, args)
|
proc.start_detached(cmd, args)
|
||||||
@ -956,12 +956,13 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
deprecated='Use :spawn --userscript instead!')
|
deprecated='Use :spawn --userscript instead!')
|
||||||
def run_userscript(self, cmd, *args: {'nargs': '*'}):
|
def run_userscript(self, cmd, *args: {'nargs': '*'}, verbose=False):
|
||||||
"""Run an userscript given as argument.
|
"""Run an userscript given as argument.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmd: The userscript to run.
|
cmd: The userscript to run.
|
||||||
args: Arguments to pass to the userscript.
|
args: Arguments to pass to the userscript.
|
||||||
|
verbose: Show notifications when the command started/exited.
|
||||||
"""
|
"""
|
||||||
cmd = os.path.expanduser(cmd)
|
cmd = os.path.expanduser(cmd)
|
||||||
env = {
|
env = {
|
||||||
@ -989,7 +990,8 @@ class CommandDispatcher:
|
|||||||
env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)
|
env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)
|
||||||
|
|
||||||
env.update(userscripts.store_source(mainframe))
|
env.update(userscripts.store_source(mainframe))
|
||||||
userscripts.run(cmd, *args, win_id=self._win_id, env=env)
|
userscripts.run(cmd, *args, win_id=self._win_id, env=env,
|
||||||
|
verbose=verbose)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def quickmark_save(self):
|
def quickmark_save(self):
|
||||||
|
@ -88,19 +88,20 @@ class _BaseUserscriptRunner(QObject):
|
|||||||
self._proc = None
|
self._proc = None
|
||||||
self._env = None
|
self._env = None
|
||||||
|
|
||||||
def _run_process(self, cmd, *args, env):
|
def _run_process(self, cmd, *args, env, verbose):
|
||||||
"""Start the given command.
|
"""Start the given command.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmd: The command to be started.
|
cmd: The command to be started.
|
||||||
*args: The arguments to hand to the command
|
*args: The arguments to hand to the command
|
||||||
env: A dictionary of environment variables to add.
|
env: A dictionary of environment variables to add.
|
||||||
|
verbose: Show notifications when the command started/exited.
|
||||||
"""
|
"""
|
||||||
self._env = {'QUTE_FIFO': self._filepath}
|
self._env = {'QUTE_FIFO': self._filepath}
|
||||||
self._env.update(env)
|
self._env.update(env)
|
||||||
self._proc = guiprocess.GUIProcess(self._win_id, 'userscript',
|
self._proc = guiprocess.GUIProcess(self._win_id, 'userscript',
|
||||||
additional_env=self._env,
|
additional_env=self._env,
|
||||||
parent=self)
|
verbose=verbose, parent=self)
|
||||||
self._proc.error.connect(self.on_proc_error)
|
self._proc.error.connect(self.on_proc_error)
|
||||||
self._proc.finished.connect(self.on_proc_finished)
|
self._proc.finished.connect(self.on_proc_finished)
|
||||||
self._proc.start(cmd, args)
|
self._proc.start(cmd, args)
|
||||||
@ -126,7 +127,7 @@ class _BaseUserscriptRunner(QObject):
|
|||||||
self._proc = None
|
self._proc = None
|
||||||
self._env = None
|
self._env = None
|
||||||
|
|
||||||
def run(self, cmd, *args, env=None):
|
def run(self, cmd, *args, env=None, verbose=False):
|
||||||
"""Run the userscript given.
|
"""Run the userscript given.
|
||||||
|
|
||||||
Needs to be overridden by subclasses.
|
Needs to be overridden by subclasses.
|
||||||
@ -135,6 +136,7 @@ class _BaseUserscriptRunner(QObject):
|
|||||||
cmd: The command to be started.
|
cmd: The command to be started.
|
||||||
*args: The arguments to hand to the command
|
*args: The arguments to hand to the command
|
||||||
env: A dictionary of environment variables to add.
|
env: A dictionary of environment variables to add.
|
||||||
|
verbose: Show notifications when the command started/exited.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -164,7 +166,7 @@ class _POSIXUserscriptRunner(_BaseUserscriptRunner):
|
|||||||
super().__init__(win_id, parent)
|
super().__init__(win_id, parent)
|
||||||
self._reader = None
|
self._reader = None
|
||||||
|
|
||||||
def run(self, cmd, *args, env=None):
|
def run(self, cmd, *args, env=None, verbose=False):
|
||||||
try:
|
try:
|
||||||
# tempfile.mktemp is deprecated and discouraged, but we use it here
|
# tempfile.mktemp is deprecated and discouraged, but we use it here
|
||||||
# to create a FIFO since the only other alternative would be to
|
# to create a FIFO since the only other alternative would be to
|
||||||
@ -182,7 +184,7 @@ class _POSIXUserscriptRunner(_BaseUserscriptRunner):
|
|||||||
self._reader = _QtFIFOReader(self._filepath)
|
self._reader = _QtFIFOReader(self._filepath)
|
||||||
self._reader.got_line.connect(self.got_cmd)
|
self._reader.got_line.connect(self.got_cmd)
|
||||||
|
|
||||||
self._run_process(cmd, *args, env=env)
|
self._run_process(cmd, *args, env=env, verbose=verbose)
|
||||||
|
|
||||||
def on_proc_finished(self):
|
def on_proc_finished(self):
|
||||||
"""Interrupt the reader when the process finished."""
|
"""Interrupt the reader when the process finished."""
|
||||||
@ -248,14 +250,14 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
|
|||||||
self._cleanup()
|
self._cleanup()
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
|
|
||||||
def run(self, cmd, *args, env=None):
|
def run(self, cmd, *args, env=None, verbose=False):
|
||||||
try:
|
try:
|
||||||
self._oshandle, self._filepath = tempfile.mkstemp(text=True)
|
self._oshandle, self._filepath = tempfile.mkstemp(text=True)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
message.error(self._win_id, "Error while creating tempfile: "
|
message.error(self._win_id, "Error while creating tempfile: "
|
||||||
"{}".format(e))
|
"{}".format(e))
|
||||||
return
|
return
|
||||||
self._run_process(cmd, *args, env=env)
|
self._run_process(cmd, *args, env=env, verbose=verbose)
|
||||||
|
|
||||||
|
|
||||||
class _DummyUserscriptRunner:
|
class _DummyUserscriptRunner:
|
||||||
@ -271,8 +273,9 @@ class _DummyUserscriptRunner:
|
|||||||
|
|
||||||
finished = pyqtSignal()
|
finished = pyqtSignal()
|
||||||
|
|
||||||
def run(self, _cmd, *_args, _env=None):
|
def run(self, cmd, *args, env=None, verbose=False):
|
||||||
"""Print an error as userscripts are not supported."""
|
"""Print an error as userscripts are not supported."""
|
||||||
|
# pylint: disable=unused-argument,unused-variable
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
raise cmdexc.CommandError(
|
raise cmdexc.CommandError(
|
||||||
"Userscripts are not supported on this platform!")
|
"Userscripts are not supported on this platform!")
|
||||||
@ -319,7 +322,7 @@ def store_source(frame):
|
|||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def run(cmd, *args, win_id, env):
|
def run(cmd, *args, win_id, env, verbose=False):
|
||||||
"""Convenience method to run an userscript.
|
"""Convenience method to run an userscript.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -327,6 +330,7 @@ def run(cmd, *args, win_id, env):
|
|||||||
*args: The arguments to pass to the userscript.
|
*args: The arguments to pass to the userscript.
|
||||||
win_id: The window id the userscript is executed in.
|
win_id: The window id the userscript is executed in.
|
||||||
env: A dictionary of variables to add to the process environment.
|
env: A dictionary of variables to add to the process environment.
|
||||||
|
verbose: Show notifications when the command started/exited.
|
||||||
"""
|
"""
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
@ -339,6 +343,6 @@ def run(cmd, *args, win_id, env):
|
|||||||
user_agent = config.get('network', 'user-agent')
|
user_agent = config.get('network', 'user-agent')
|
||||||
if user_agent is not None:
|
if user_agent is not None:
|
||||||
env['QUTE_USER_AGENT'] = user_agent
|
env['QUTE_USER_AGENT'] = user_agent
|
||||||
runner.run(cmd, *args, env=env)
|
runner.run(cmd, *args, env=env, verbose=verbose)
|
||||||
runner.finished.connect(commandrunner.deleteLater)
|
runner.finished.connect(commandrunner.deleteLater)
|
||||||
runner.finished.connect(runner.deleteLater)
|
runner.finished.connect(runner.deleteLater)
|
||||||
|
Loading…
Reference in New Issue
Block a user