Merge standarddir.system_data() into standarddir.data(system=True)
See #2791
This commit is contained in:
parent
2d500d4efa
commit
a2f16dbecd
@ -376,7 +376,7 @@ def _lookup_path(cmd):
|
||||
"""
|
||||
directories = [
|
||||
os.path.join(standarddir.data(), "userscripts"),
|
||||
os.path.join(standarddir.system_data(), "userscripts"),
|
||||
os.path.join(standarddir.data(system=True), "userscripts"),
|
||||
]
|
||||
for directory in directories:
|
||||
cmd_path = os.path.join(directory, cmd)
|
||||
|
@ -77,15 +77,7 @@ def _init_data(args):
|
||||
_create(path)
|
||||
_locations[Location.data] = path
|
||||
|
||||
|
||||
def data():
|
||||
return _locations[Location.data]
|
||||
|
||||
|
||||
def _init_system_data(_args):
|
||||
"""Initialize the location for system-wide data.
|
||||
|
||||
This path may be read-only."""
|
||||
# system_data
|
||||
_locations.pop(Location.system_data, None) # Remove old state
|
||||
if sys.platform.startswith('linux'):
|
||||
path = "/usr/share/qutebrowser"
|
||||
@ -93,11 +85,18 @@ def _init_system_data(_args):
|
||||
_locations[Location.system_data] = path
|
||||
|
||||
|
||||
def system_data():
|
||||
try:
|
||||
return _locations[Location.system_data]
|
||||
except KeyError:
|
||||
return _locations[Location.data]
|
||||
def data(system=False):
|
||||
"""Get the data directory.
|
||||
|
||||
If system=True is given, gets the system-wide (probably non-writable) data
|
||||
directory.
|
||||
"""
|
||||
if system:
|
||||
try:
|
||||
return _locations[Location.system_data]
|
||||
except KeyError:
|
||||
pass
|
||||
return _locations[Location.data]
|
||||
|
||||
|
||||
def _init_cache(args):
|
||||
@ -235,7 +234,6 @@ def _init_dirs(args=None):
|
||||
"""
|
||||
_init_config(args)
|
||||
_init_data(args)
|
||||
_init_system_data(args)
|
||||
_init_cache(args)
|
||||
_init_download(args)
|
||||
_init_runtime(args)
|
||||
|
@ -222,7 +222,7 @@ def _path_info():
|
||||
return {
|
||||
'config': standarddir.config(),
|
||||
'data': standarddir.data(),
|
||||
'system_data': standarddir.system_data(),
|
||||
'system data': standarddir.data(system=True),
|
||||
'cache': standarddir.cache(),
|
||||
'runtime': standarddir.runtime(),
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ class TestSystemData:
|
||||
monkeypatch.setattr('sys.platform', "linux")
|
||||
monkeypatch.setattr(os.path, 'exists', lambda path: True)
|
||||
standarddir._init_dirs()
|
||||
assert standarddir.system_data() == "/usr/share/qutebrowser"
|
||||
assert standarddir.data(system=True) == "/usr/share/qutebrowser"
|
||||
|
||||
@pytest.mark.linux
|
||||
def test_system_datadir_not_exist_linux(self, monkeypatch, tmpdir,
|
||||
@ -288,7 +288,7 @@ class TestSystemData:
|
||||
fake_args.basedir = str(tmpdir)
|
||||
monkeypatch.setattr(os.path, 'exists', lambda path: False)
|
||||
standarddir._init_dirs(fake_args)
|
||||
assert standarddir.system_data() == standarddir.data()
|
||||
assert standarddir.data(system=True) == standarddir.data()
|
||||
|
||||
def test_system_datadir_unsupportedos(self, monkeypatch, tmpdir,
|
||||
fake_args):
|
||||
@ -296,7 +296,7 @@ class TestSystemData:
|
||||
fake_args.basedir = str(tmpdir)
|
||||
monkeypatch.setattr('sys.platform', "potato")
|
||||
standarddir._init_dirs(fake_args)
|
||||
assert standarddir.system_data() == standarddir.data()
|
||||
assert standarddir.data(system=True) == standarddir.data()
|
||||
|
||||
|
||||
class TestMoveWebEngineData:
|
||||
|
@ -460,8 +460,8 @@ def test_path_info(monkeypatch):
|
||||
"""Test _path_info()."""
|
||||
patches = {
|
||||
'config': lambda: 'CONFIG PATH',
|
||||
'data': lambda: 'DATA PATH',
|
||||
'system_data': lambda: 'SYSTEM DATA PATH',
|
||||
'data': lambda system=False: ('SYSTEM DATA PATH' if system
|
||||
else 'DATA PATH'),
|
||||
'cache': lambda: 'CACHE PATH',
|
||||
'runtime': lambda: 'RUNTIME PATH',
|
||||
}
|
||||
@ -473,7 +473,7 @@ def test_path_info(monkeypatch):
|
||||
|
||||
assert pathinfo['config'] == 'CONFIG PATH'
|
||||
assert pathinfo['data'] == 'DATA PATH'
|
||||
assert pathinfo['system_data'] == 'SYSTEM DATA PATH'
|
||||
assert pathinfo['system data'] == 'SYSTEM DATA PATH'
|
||||
assert pathinfo['cache'] == 'CACHE PATH'
|
||||
assert pathinfo['runtime'] == 'RUNTIME PATH'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user