Merge branch 'craftyguy-system-wide-data-path'
This commit is contained in:
commit
e4625a2849
@ -43,6 +43,7 @@ Changed
|
||||
`:download-cancel --all`. It does the same as `:download-clear`.
|
||||
- Improved detection of URLs/search terms when pasting multiple lines.
|
||||
- Don't remove `qutebrowser-editor-*` temporary file if editor subprocess crashed
|
||||
- Userscripts are also searched in `/usr/share/qutebrowser/userscripts`.
|
||||
|
||||
Fixed
|
||||
~~~~~
|
||||
|
@ -199,6 +199,7 @@ Contributors, sorted by the number of commits in descending order:
|
||||
* Fritz V155 Reichwald
|
||||
* Franz Fellner
|
||||
* Corentin Jule
|
||||
* Clayton Craft
|
||||
* zwarag
|
||||
* xd1le
|
||||
* haxwithaxe
|
||||
|
@ -625,8 +625,11 @@ Note the {url} variable which gets replaced by the current URL might be useful h
|
||||
* +'cmdline'+: The commandline to execute.
|
||||
|
||||
==== optional arguments
|
||||
* +*-u*+, +*--userscript*+: Run the command as a userscript. Either store the userscript in `~/.local/share/qutebrowser/userscripts`
|
||||
(or `$XDG_DATA_DIR`), or use an absolute path.
|
||||
* +*-u*+, +*--userscript*+: Run the command as a userscript. You can use an absolute path, or store the userscript in one of those
|
||||
locations:
|
||||
- `~/.local/share/qutebrowser/userscripts`
|
||||
(or `$XDG_DATA_DIR`)
|
||||
- `/usr/share/qutebrowser/userscripts`
|
||||
|
||||
* +*-v*+, +*--verbose*+: Show notifications when the command started/exited.
|
||||
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
|
||||
|
@ -918,9 +918,12 @@ class CommandDispatcher:
|
||||
useful here.
|
||||
|
||||
Args:
|
||||
userscript: Run the command as a userscript. Either store the
|
||||
userscript in `~/.local/share/qutebrowser/userscripts`
|
||||
(or `$XDG_DATA_DIR`), or use an absolute path.
|
||||
userscript: Run the command as a userscript. You can use an
|
||||
absolute path, or store the userscript in one of those
|
||||
locations:
|
||||
- `~/.local/share/qutebrowser/userscripts`
|
||||
(or `$XDG_DATA_DIR`)
|
||||
- `/usr/share/qutebrowser/userscripts`
|
||||
verbose: Show notifications when the command started/exited.
|
||||
detach: Whether the command should be detached from qutebrowser.
|
||||
cmdline: The commandline to execute.
|
||||
|
@ -344,14 +344,18 @@ def run(cmd, *args, win_id, env, verbose=False):
|
||||
user_agent = config.get('network', 'user-agent')
|
||||
if user_agent is not None:
|
||||
env['QUTE_USER_AGENT'] = user_agent
|
||||
cmd = os.path.expanduser(cmd)
|
||||
cmd_path = os.path.expanduser(cmd)
|
||||
|
||||
# if cmd is not given as an absolute path, look it up
|
||||
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
|
||||
if not os.path.isabs(cmd):
|
||||
log.misc.debug("{} is no absolute path".format(cmd))
|
||||
cmd = os.path.join(standarddir.data(), "userscripts", cmd)
|
||||
if not os.path.isabs(cmd_path):
|
||||
log.misc.debug("{} is no absolute path".format(cmd_path))
|
||||
cmd_path = os.path.join(standarddir.data(), "userscripts", cmd)
|
||||
if not os.path.exists(cmd_path):
|
||||
cmd_path = os.path.join(standarddir.system_data(),
|
||||
"userscripts", cmd)
|
||||
log.misc.debug("Userscript to run: {}".format(cmd_path))
|
||||
|
||||
runner.run(cmd, *args, env=env, verbose=verbose)
|
||||
runner.run(cmd_path, *args, env=env, verbose=verbose)
|
||||
runner.finished.connect(commandrunner.deleteLater)
|
||||
runner.finished.connect(runner.deleteLater)
|
||||
|
@ -65,6 +65,17 @@ def data():
|
||||
return path
|
||||
|
||||
|
||||
def system_data():
|
||||
"""Get a location for system-wide data. This path may be read-only."""
|
||||
if sys.platform.startswith('linux'):
|
||||
path = "/usr/share/qutebrowser"
|
||||
if not os.path.exists(path):
|
||||
path = data()
|
||||
else:
|
||||
path = data()
|
||||
return path
|
||||
|
||||
|
||||
def cache():
|
||||
"""Get a location for the cache."""
|
||||
typ = QStandardPaths.CacheLocation
|
||||
|
@ -313,3 +313,25 @@ class TestCreatingDir:
|
||||
|
||||
func = getattr(standarddir, typ)
|
||||
func()
|
||||
|
||||
|
||||
class TestSystemData:
|
||||
|
||||
"""Test system data path."""
|
||||
|
||||
def test_system_datadir_exist_linux(self, monkeypatch):
|
||||
"""Test that /usr/share/qutebrowser is used if path exists."""
|
||||
monkeypatch.setattr('sys.platform', "linux")
|
||||
monkeypatch.setattr(os.path, 'exists', lambda path: True)
|
||||
assert standarddir.system_data() == "/usr/share/qutebrowser"
|
||||
|
||||
@pytest.mark.linux
|
||||
def test_system_datadir_not_exist_linux(self, monkeypatch):
|
||||
"""Test that system-wide path isn't used on linux if path not exist."""
|
||||
monkeypatch.setattr(os.path, 'exists', lambda path: False)
|
||||
assert standarddir.system_data() == standarddir.data()
|
||||
|
||||
def test_system_datadir_unsupportedos(self, monkeypatch):
|
||||
"""Test that system-wide path is not used on non-Linux OS."""
|
||||
monkeypatch.setattr('sys.platform', "potato")
|
||||
assert standarddir.system_data() == standarddir.data()
|
||||
|
Loading…
Reference in New Issue
Block a user