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`.
|
`:download-cancel --all`. It does the same as `:download-clear`.
|
||||||
- Improved detection of URLs/search terms when pasting multiple lines.
|
- Improved detection of URLs/search terms when pasting multiple lines.
|
||||||
- Don't remove `qutebrowser-editor-*` temporary file if editor subprocess crashed
|
- Don't remove `qutebrowser-editor-*` temporary file if editor subprocess crashed
|
||||||
|
- Userscripts are also searched in `/usr/share/qutebrowser/userscripts`.
|
||||||
|
|
||||||
Fixed
|
Fixed
|
||||||
~~~~~
|
~~~~~
|
||||||
|
@ -199,6 +199,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Fritz V155 Reichwald
|
* Fritz V155 Reichwald
|
||||||
* Franz Fellner
|
* Franz Fellner
|
||||||
* Corentin Jule
|
* Corentin Jule
|
||||||
|
* Clayton Craft
|
||||||
* zwarag
|
* zwarag
|
||||||
* xd1le
|
* xd1le
|
||||||
* haxwithaxe
|
* 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.
|
* +'cmdline'+: The commandline to execute.
|
||||||
|
|
||||||
==== optional arguments
|
==== optional arguments
|
||||||
* +*-u*+, +*--userscript*+: Run the command as a userscript. Either store the userscript in `~/.local/share/qutebrowser/userscripts`
|
* +*-u*+, +*--userscript*+: Run the command as a userscript. You can use an absolute path, or store the userscript in one of those
|
||||||
(or `$XDG_DATA_DIR`), or use an absolute path.
|
locations:
|
||||||
|
- `~/.local/share/qutebrowser/userscripts`
|
||||||
|
(or `$XDG_DATA_DIR`)
|
||||||
|
- `/usr/share/qutebrowser/userscripts`
|
||||||
|
|
||||||
* +*-v*+, +*--verbose*+: Show notifications when the command started/exited.
|
* +*-v*+, +*--verbose*+: Show notifications when the command started/exited.
|
||||||
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
|
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
|
||||||
|
@ -918,9 +918,12 @@ class CommandDispatcher:
|
|||||||
useful here.
|
useful here.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
userscript: Run the command as a userscript. Either store the
|
userscript: Run the command as a userscript. You can use an
|
||||||
userscript in `~/.local/share/qutebrowser/userscripts`
|
absolute path, or store the userscript in one of those
|
||||||
(or `$XDG_DATA_DIR`), or use an absolute path.
|
locations:
|
||||||
|
- `~/.local/share/qutebrowser/userscripts`
|
||||||
|
(or `$XDG_DATA_DIR`)
|
||||||
|
- `/usr/share/qutebrowser/userscripts`
|
||||||
verbose: Show notifications when the command started/exited.
|
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.
|
||||||
cmdline: The commandline to execute.
|
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')
|
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
|
||||||
cmd = os.path.expanduser(cmd)
|
cmd_path = os.path.expanduser(cmd)
|
||||||
|
|
||||||
# if cmd is not given as an absolute path, look it up
|
# if cmd is not given as an absolute path, look it up
|
||||||
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
|
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
|
||||||
if not os.path.isabs(cmd):
|
if not os.path.isabs(cmd_path):
|
||||||
log.misc.debug("{} is no absolute path".format(cmd))
|
log.misc.debug("{} is no absolute path".format(cmd_path))
|
||||||
cmd = os.path.join(standarddir.data(), "userscripts", cmd)
|
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(commandrunner.deleteLater)
|
||||||
runner.finished.connect(runner.deleteLater)
|
runner.finished.connect(runner.deleteLater)
|
||||||
|
@ -65,6 +65,17 @@ def data():
|
|||||||
return path
|
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():
|
def cache():
|
||||||
"""Get a location for the cache."""
|
"""Get a location for the cache."""
|
||||||
typ = QStandardPaths.CacheLocation
|
typ = QStandardPaths.CacheLocation
|
||||||
|
@ -313,3 +313,25 @@ class TestCreatingDir:
|
|||||||
|
|
||||||
func = getattr(standarddir, typ)
|
func = getattr(standarddir, typ)
|
||||||
func()
|
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