Merge branch 'HolySmoke86-issue1940'
This commit is contained in:
commit
296f309859
@ -136,6 +136,7 @@ Changed
|
|||||||
* `fonts -> messages.info`
|
* `fonts -> messages.info`
|
||||||
- The `qute:settings` page now also shows option descriptions.
|
- The `qute:settings` page now also shows option descriptions.
|
||||||
- `qute:version` and `qutebrowser --version` now show various important paths
|
- `qute:version` and `qutebrowser --version` now show various important paths
|
||||||
|
- `:spawn`/userscripts now show a nicer error when a script wasn't found
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
@ -166,9 +166,9 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Nathan Isom
|
* Nathan Isom
|
||||||
* Thorsten Wißmann
|
* Thorsten Wißmann
|
||||||
* Austin Anderson
|
* Austin Anderson
|
||||||
|
* Daniel Karbach
|
||||||
* Jimmy
|
* Jimmy
|
||||||
* Niklas Haas
|
* Niklas Haas
|
||||||
* Daniel Karbach
|
|
||||||
* Alexey "Averrin" Nabrodov
|
* Alexey "Averrin" Nabrodov
|
||||||
* nanjekyejoannah
|
* nanjekyejoannah
|
||||||
* avk
|
* avk
|
||||||
|
@ -1126,7 +1126,7 @@ class CommandDispatcher:
|
|||||||
try:
|
try:
|
||||||
userscripts.run_async(tab, cmd, *args, win_id=self._win_id,
|
userscripts.run_async(tab, cmd, *args, win_id=self._win_id,
|
||||||
env=env, verbose=verbose)
|
env=env, verbose=verbose)
|
||||||
except userscripts.UnsupportedError as e:
|
except userscripts.Error as e:
|
||||||
raise cmdexc.CommandError(e)
|
raise cmdexc.CommandError(e)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
|
@ -315,7 +315,34 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedError(Exception):
|
class Error(Exception):
|
||||||
|
|
||||||
|
"""Base class for userscript exceptions."""
|
||||||
|
|
||||||
|
|
||||||
|
class NotFoundError(Error):
|
||||||
|
|
||||||
|
"""Raised when spawning a userscript that doesn't exist.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
script_name: name of the userscript as called
|
||||||
|
paths: path names that were searched for the userscript
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, script_name, paths=None):
|
||||||
|
super().__init__()
|
||||||
|
self.script_name = script_name
|
||||||
|
self.paths = paths
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
msg = "Userscript '{}' not found".format(self.script_name)
|
||||||
|
if self.paths:
|
||||||
|
msg += " in userscript directories {}".format(
|
||||||
|
', '.join(repr(path) for path in self.paths))
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
class UnsupportedError(Error):
|
||||||
|
|
||||||
"""Raised when userscripts aren't supported on this platform."""
|
"""Raised when userscripts aren't supported on this platform."""
|
||||||
|
|
||||||
@ -323,12 +350,37 @@ class UnsupportedError(Exception):
|
|||||||
return "Userscripts are not supported on this platform!"
|
return "Userscripts are not supported on this platform!"
|
||||||
|
|
||||||
|
|
||||||
|
def _lookup_path(cmd):
|
||||||
|
"""Search userscript directories for given command.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotFoundError if the command could not be found.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cmd: The command to look for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A path to the userscript.
|
||||||
|
"""
|
||||||
|
directories = [
|
||||||
|
os.path.join(standarddir.data(), "userscripts"),
|
||||||
|
os.path.join(standarddir.system_data(), "userscripts"),
|
||||||
|
]
|
||||||
|
for directory in directories:
|
||||||
|
cmd_path = os.path.join(directory, cmd)
|
||||||
|
if os.path.exists(cmd_path):
|
||||||
|
return cmd_path
|
||||||
|
|
||||||
|
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):
|
||||||
"""Run a userscript after dumping page html/source.
|
"""Run a userscript after dumping page html/source.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
UnsupportedError if userscripts are not supported on the current
|
UnsupportedError if userscripts are not supported on the current
|
||||||
platform.
|
platform.
|
||||||
|
NotFoundError if the command could not be found.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tab: The WebKitTab/WebEngineTab to get the source from.
|
tab: The WebKitTab/WebEngineTab to get the source from.
|
||||||
@ -371,10 +423,9 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False):
|
|||||||
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
|
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
|
||||||
if not os.path.isabs(cmd_path):
|
if not os.path.isabs(cmd_path):
|
||||||
log.misc.debug("{} is no absolute path".format(cmd_path))
|
log.misc.debug("{} is no absolute path".format(cmd_path))
|
||||||
cmd_path = os.path.join(standarddir.data(), "userscripts", cmd)
|
cmd_path = _lookup_path(cmd)
|
||||||
if not os.path.exists(cmd_path):
|
elif not os.path.exists(cmd_path):
|
||||||
cmd_path = os.path.join(standarddir.system_data(),
|
raise NotFoundError(cmd_path)
|
||||||
"userscripts", cmd)
|
|
||||||
log.misc.debug("Userscript to run: {}".format(cmd_path))
|
log.misc.debug("Userscript to run: {}".format(cmd_path))
|
||||||
|
|
||||||
runner.finished.connect(commandrunner.deleteLater)
|
runner.finished.connect(commandrunner.deleteLater)
|
||||||
|
@ -10,7 +10,11 @@ Feature: :spawn
|
|||||||
|
|
||||||
Scenario: Starting a userscript which doesn't exist
|
Scenario: Starting a userscript which doesn't exist
|
||||||
When I run :spawn -u this_does_not_exist
|
When I run :spawn -u this_does_not_exist
|
||||||
Then the error "Error while spawning userscript: The process failed to start." should be shown
|
Then the error "Userscript 'this_does_not_exist' not found in userscript directories *" should be shown
|
||||||
|
|
||||||
|
Scenario: Starting a userscript with absoloute path which doesn't exist
|
||||||
|
When I run :spawn -u /this_does_not_exist
|
||||||
|
Then the error "Userscript '/this_does_not_exist' not found" should be shown
|
||||||
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/1614
|
# https://github.com/The-Compiler/qutebrowser/issues/1614
|
||||||
@posix
|
@posix
|
||||||
|
Loading…
Reference in New Issue
Block a user