summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/standarddir.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/utils/standarddir.py')
-rw-r--r--qutebrowser/utils/standarddir.py57
1 files changed, 28 insertions, 29 deletions
diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py
index e63b43548..cf9335d6e 100644
--- a/qutebrowser/utils/standarddir.py
+++ b/qutebrowser/utils/standarddir.py
@@ -27,8 +27,7 @@ import enum
import argparse
from typing import Iterator, Optional
-from qutebrowser.qt.core import QStandardPaths
-from qutebrowser.qt.widgets import QApplication
+from qutebrowser.qt import widgets, core
from qutebrowser.utils import log, debug, utils, version
@@ -64,7 +63,7 @@ def _unset_organization() -> Iterator[None]:
This is primarily needed in config.py.
"""
- qapp = QApplication.instance()
+ qapp = widgets.QApplication.instance()
if qapp is not None:
orgname = qapp.organizationName()
qapp.setOrganizationName(None) # type: ignore[arg-type]
@@ -77,12 +76,12 @@ def _unset_organization() -> Iterator[None]:
def _init_config(args: Optional[argparse.Namespace]) -> None:
"""Initialize the location for configs."""
- typ = QStandardPaths.StandardLocation.ConfigLocation
+ typ = core.QStandardPaths.StandardLocation.ConfigLocation
path = _from_args(typ, args)
if path is None:
if utils.is_windows:
app_data_path = _writable_location(
- QStandardPaths.StandardLocation.AppDataLocation)
+ core.QStandardPaths.StandardLocation.AppDataLocation)
path = os.path.join(app_data_path, 'config')
else:
path = _writable_location(typ)
@@ -128,7 +127,7 @@ def config_py() -> str:
def _init_data(args: Optional[argparse.Namespace]) -> None:
"""Initialize the location for data."""
- typ = QStandardPaths.StandardLocation.AppDataLocation
+ typ = core.QStandardPaths.StandardLocation.AppDataLocation
path = _from_args(typ, args)
if path is None:
if utils.is_windows:
@@ -136,7 +135,7 @@ def _init_data(args: Optional[argparse.Namespace]) -> None:
path = os.path.join(app_data_path, 'data')
elif sys.platform.startswith('haiku'):
# HaikuOS returns an empty value for AppDataLocation
- config_path = _writable_location(QStandardPaths.StandardLocation.ConfigLocation)
+ config_path = _writable_location(core.QStandardPaths.StandardLocation.ConfigLocation)
path = os.path.join(config_path, 'data')
else:
path = _writable_location(typ)
@@ -169,12 +168,12 @@ def data(system: bool = False) -> str:
def _init_cache(args: Optional[argparse.Namespace]) -> None:
"""Initialize the location for the cache."""
- typ = QStandardPaths.StandardLocation.CacheLocation
+ typ = core.QStandardPaths.StandardLocation.CacheLocation
path = _from_args(typ, args)
if path is None:
if utils.is_windows:
# Local, not Roaming!
- data_path = _writable_location(QStandardPaths.StandardLocation.AppLocalDataLocation)
+ data_path = _writable_location(core.QStandardPaths.StandardLocation.AppLocalDataLocation)
path = os.path.join(data_path, 'cache')
else:
path = _writable_location(typ)
@@ -193,7 +192,7 @@ def _init_download(args: Optional[argparse.Namespace]) -> None:
Note this is only the default directory as found by Qt.
Therefore, we also don't create it.
"""
- typ = QStandardPaths.StandardLocation.DownloadLocation
+ typ = core.QStandardPaths.StandardLocation.DownloadLocation
path = _from_args(typ, args)
if path is None:
path = _writable_location(typ)
@@ -208,9 +207,9 @@ def _init_runtime(args: Optional[argparse.Namespace]) -> None:
"""Initialize location for runtime data."""
if utils.is_mac or utils.is_windows:
# RuntimeLocation is a weird path on macOS and Windows.
- typ = QStandardPaths.StandardLocation.TempLocation
+ typ = core.QStandardPaths.StandardLocation.TempLocation
else:
- typ = QStandardPaths.StandardLocation.RuntimeLocation
+ typ = core.QStandardPaths.StandardLocation.RuntimeLocation
path = _from_args(typ, args)
if path is None:
@@ -218,10 +217,10 @@ def _init_runtime(args: Optional[argparse.Namespace]) -> None:
path = _writable_location(typ)
except EmptyValueError:
# Fall back to TempLocation when RuntimeLocation is misconfigured
- if typ == QStandardPaths.StandardLocation.TempLocation:
+ if typ == core.QStandardPaths.StandardLocation.TempLocation:
raise
path = _writable_location( # pragma: no cover
- QStandardPaths.StandardLocation.TempLocation)
+ core.QStandardPaths.StandardLocation.TempLocation)
# This is generic, but per-user.
# _writable_location makes sure we have a qutebrowser-specific subdir.
@@ -253,23 +252,23 @@ def runtime() -> str:
return _locations[_Location.runtime]
-def _writable_location(typ: QStandardPaths.StandardLocation) -> str:
+def _writable_location(typ: core.QStandardPaths.StandardLocation) -> str:
"""Wrapper around QStandardPaths.writableLocation.
Arguments:
typ: A QStandardPaths::StandardLocation member.
"""
- typ_str = debug.qenum_key(QStandardPaths, typ)
+ typ_str = debug.qenum_key(core.QStandardPaths, typ)
# Types we are sure we handle correctly below.
assert typ in [
- QStandardPaths.StandardLocation.ConfigLocation, QStandardPaths.StandardLocation.AppLocalDataLocation,
- QStandardPaths.StandardLocation.CacheLocation, QStandardPaths.StandardLocation.DownloadLocation,
- QStandardPaths.StandardLocation.RuntimeLocation, QStandardPaths.StandardLocation.TempLocation,
- QStandardPaths.StandardLocation.AppDataLocation], typ_str
+ core.QStandardPaths.StandardLocation.ConfigLocation, core.QStandardPaths.StandardLocation.AppLocalDataLocation,
+ core.QStandardPaths.StandardLocation.CacheLocation, core.QStandardPaths.StandardLocation.DownloadLocation,
+ core.QStandardPaths.StandardLocation.RuntimeLocation, core.QStandardPaths.StandardLocation.TempLocation,
+ core.QStandardPaths.StandardLocation.AppDataLocation], typ_str
with _unset_organization():
- path = QStandardPaths.writableLocation(typ)
+ path = core.QStandardPaths.writableLocation(typ)
log.misc.debug("writable location for {}: {}".format(typ_str, path))
if not path:
@@ -281,7 +280,7 @@ def _writable_location(typ: QStandardPaths.StandardLocation) -> str:
# Add the application name to the given path if needed.
# This is in order for this to work without a QApplication (and thus
# QStandardsPaths not knowing the application name).
- if (typ != QStandardPaths.StandardLocation.DownloadLocation and
+ if (typ != core.QStandardPaths.StandardLocation.DownloadLocation and
path.split(os.sep)[-1] != APPNAME):
path = os.path.join(path, APPNAME)
@@ -289,7 +288,7 @@ def _writable_location(typ: QStandardPaths.StandardLocation) -> str:
def _from_args(
- typ: QStandardPaths.StandardLocation,
+ typ: core.QStandardPaths.StandardLocation,
args: Optional[argparse.Namespace]
) -> Optional[str]:
"""Get the standard directory from an argparse namespace.
@@ -298,12 +297,12 @@ def _from_args(
The overridden path, or None if there is no override.
"""
basedir_suffix = {
- QStandardPaths.StandardLocation.ConfigLocation: 'config',
- QStandardPaths.StandardLocation.AppDataLocation: 'data',
- QStandardPaths.StandardLocation.AppLocalDataLocation: 'data',
- QStandardPaths.StandardLocation.CacheLocation: 'cache',
- QStandardPaths.StandardLocation.DownloadLocation: 'download',
- QStandardPaths.StandardLocation.RuntimeLocation: 'runtime',
+ core.QStandardPaths.StandardLocation.ConfigLocation: 'config',
+ core.QStandardPaths.StandardLocation.AppDataLocation: 'data',
+ core.QStandardPaths.StandardLocation.AppLocalDataLocation: 'data',
+ core.QStandardPaths.StandardLocation.CacheLocation: 'cache',
+ core.QStandardPaths.StandardLocation.DownloadLocation: 'download',
+ core.QStandardPaths.StandardLocation.RuntimeLocation: 'runtime',
}
if getattr(args, 'basedir', None) is None: