diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-04-19 22:14:15 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-04-19 22:14:15 +0200 |
commit | 936dd37426c1afd5d8b7341029d30915b9fe005d (patch) | |
tree | 6dd02622708fe0061169874f13921bfc1b355585 | |
parent | ef94fb86261418bf97f3a8d5433fa647f38a1006 (diff) | |
parent | 22e7b06c10ffb8cc4b25f4002fd9880e18ab5799 (diff) | |
download | qutebrowser-936dd37426c1afd5d8b7341029d30915b9fe005d.tar.gz qutebrowser-936dd37426c1afd5d8b7341029d30915b9fe005d.zip |
Merge remote-tracking branch 'origin/pr/5322'
-rw-r--r-- | qutebrowser/browser/commands.py | 10 | ||||
-rw-r--r-- | qutebrowser/commands/userscripts.py | 17 | ||||
-rw-r--r-- | tests/end2end/features/conftest.py | 3 | ||||
-rw-r--r-- | tests/end2end/features/spawn.feature | 8 |
4 files changed, 28 insertions, 10 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index cf79672ca..2ceae0551 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1046,7 +1046,8 @@ class CommandDispatcher: if userscript: def _selection_callback(s): try: - runner = self._run_userscript(s, cmd, args, verbose, count) + runner = self._run_userscript( + s, cmd, args, verbose, output_messages, count) runner.finished.connect(_on_proc_finished) except cmdutils.CommandError as e: message.error(str(e)) @@ -1072,13 +1073,15 @@ class CommandDispatcher: proc.start(cmd, args) proc.finished.connect(_on_proc_finished) - def _run_userscript(self, selection, cmd, args, verbose, count): + def _run_userscript(self, selection, cmd, args, verbose, output_messages, + count): """Run a userscript given as argument. Args: cmd: The userscript to run. args: Arguments to pass to the userscript. verbose: Show notifications when the command started/exited. + output_messages: Show the output as messages. count: Exposed to the userscript. """ env = { @@ -1105,7 +1108,8 @@ class CommandDispatcher: try: runner = userscripts.run_async( - tab, cmd, *args, win_id=self._win_id, env=env, verbose=verbose) + tab, cmd, *args, win_id=self._win_id, env=env, verbose=verbose, + output_messages=output_messages) except userscripts.Error as e: raise cmdutils.CommandError(e) return runner diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 9d9ce3c52..f3a706d1a 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -148,7 +148,8 @@ class _BaseUserscriptRunner(QObject): log.procs.debug("Both text/HTML stored, kicking off userscript!") self._run_process(*self._args, **self._kwargs) - def _run_process(self, cmd, *args, env=None, verbose=False): + def _run_process(self, cmd, *args, env=None, verbose=False, + output_messages=False): """Start the given command. Args: @@ -156,15 +157,16 @@ class _BaseUserscriptRunner(QObject): *args: The arguments to hand to the command env: A dictionary of environment variables to add. verbose: Show notifications when the command started/exited. + output_messages: Show the output as messages. """ assert self._filepath is not None self._env['QUTE_FIFO'] = self._filepath if env is not None: self._env.update(env) - self._proc = guiprocess.GUIProcess('userscript', - additional_env=self._env, - verbose=verbose, parent=self) + self._proc = guiprocess.GUIProcess( + 'userscript', additional_env=self._env, + output_messages=output_messages, verbose=verbose, parent=self) self._proc.finished.connect(self.on_proc_finished) self._proc.error.connect(self.on_proc_error) self._proc.start(cmd, args) @@ -398,7 +400,8 @@ def _lookup_path(cmd): raise NotFoundError(cmd, directories) -def run_async(tab, cmd, *args, win_id, env, verbose=False): +def run_async(tab, cmd, *args, win_id, env, verbose=False, + output_messages=False): """Run a userscript after dumping page html/source. Raises: @@ -413,6 +416,7 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False): win_id: The window id the userscript is executed in. env: A dictionary of variables to add to the process environment. verbose: Show notifications when the command started/exited. + output_messages: Show the output as messages. """ tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) @@ -451,7 +455,8 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False): runner.finished.connect(commandrunner.deleteLater) runner.finished.connect(runner.deleteLater) - runner.prepare_run(cmd_path, *args, env=env, verbose=verbose) + runner.prepare_run(cmd_path, *args, env=env, verbose=verbose, + output_messages=output_messages) tab.dump_async(runner.store_html) tab.dump_async(runner.store_text, plain=True) return runner diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index f9df23ac9..9463d272b 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -49,7 +49,8 @@ def _get_echo_exe_path(): return os.path.join(testutils.abs_datapath(), 'userscripts', 'echo.bat') else: - return 'echo' + import shutil + return shutil.which("echo") @pytest.hookimpl(hookwrapper=True) diff --git a/tests/end2end/features/spawn.feature b/tests/end2end/features/spawn.feature index 5fabb044d..623bf4959 100644 --- a/tests/end2end/features/spawn.feature +++ b/tests/end2end/features/spawn.feature @@ -38,6 +38,14 @@ Feature: :spawn And I run :spawn (echo-exe) {url:pretty} Then "Executing * with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged + Scenario: Running :spawn with -m + When I run :spawn -m (echo-exe) Message 1 + Then the message "Message 1" should be shown + + Scenario: Running :spawn with -u -m + When I run :spawn -u -m (echo-exe) Message 2 + Then the message "Message 2" should be shown + @posix Scenario: Running :spawn with userscript When I open data/hello.txt |