Merge a9a4af2b63 into 7e3df43463
This commit is contained in:
commit
9b82a85895
|
|
@ -38,6 +38,7 @@ class _Location(enum.Enum):
|
|||
|
||||
|
||||
APPNAME = 'qutebrowser'
|
||||
CONFIG_LOCATIONS = [os.path.normpath(os.getenv('XDG_CONFIG_HOME', '~/.config')) + '/', '~/.']
|
||||
|
||||
|
||||
class EmptyValueError(Exception):
|
||||
|
|
@ -82,7 +83,7 @@ def _init_config(args: Optional[argparse.Namespace]) -> None:
|
|||
if utils.is_mac:
|
||||
path = _from_args(typ, args)
|
||||
if path is None: # pragma: no branch
|
||||
path = os.path.expanduser('~/.' + APPNAME)
|
||||
path = _get_config_location()
|
||||
_create(path)
|
||||
_locations[_Location.config] = path
|
||||
|
||||
|
|
@ -93,6 +94,18 @@ def _init_config(args: Optional[argparse.Namespace]) -> None:
|
|||
_locations[_Location.config_py] = config_py_file
|
||||
|
||||
|
||||
def _get_config_location() -> str:
|
||||
"""Get the optimal location for the config directory on disk.
|
||||
|
||||
Searches CONFIG_LOCATIONS in order for existing config folder, defaults to
|
||||
CONFIG_LOCATIONS[0]
|
||||
"""
|
||||
it = (p + APPNAME for p in CONFIG_LOCATIONS if
|
||||
os.path.exists(os.path.expanduser(p + APPNAME)))
|
||||
path = next(it, CONFIG_LOCATIONS[0] + APPNAME)
|
||||
return os.path.expanduser(path)
|
||||
|
||||
|
||||
def config(auto: bool = False) -> str:
|
||||
"""Get the location for the config directory.
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ def test_unset_organization_no_qapp(monkeypatch):
|
|||
@pytest.mark.posix
|
||||
def test_fake_mac_config(tmp_path, fake_home_envvar):
|
||||
"""Test standardir.config on a fake Mac."""
|
||||
expected = str(tmp_path) + '/.qute_test' # always with /
|
||||
expected = str(tmp_path) + '/.config/qute_test' # always with /
|
||||
standarddir._init_config(args=None)
|
||||
assert standarddir.config() == expected
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ class TestStandardDir:
|
|||
(standarddir.data, 2, ['Application Support', APPNAME]),
|
||||
(lambda: standarddir.config(auto=True), 1, [APPNAME]),
|
||||
(standarddir.config, 0,
|
||||
os.path.expanduser('~').split(os.sep) + ['.qute_test']),
|
||||
os.path.expanduser('~').split(os.sep) + ['.config'] + ['qute_test']),
|
||||
(standarddir.cache, 2, ['Caches', APPNAME]),
|
||||
(standarddir.download, 1, ['Downloads']),
|
||||
])
|
||||
|
|
|
|||
Loading…
Reference in New Issue