Philipp Hörist pushed to branch gtk4 at gajim / gajim
Commits:
ece27192 by Philipp Hörist at 2024-11-03T22:21:27+01:00
refactor: Move Download dirs into configpaths
- - - - -
3 changed files:
- gajim/common/configpaths.py
- gajim/common/const.py
- gajim/common/preview.py
Changes:
=====================================
gajim/common/configpaths.py
=====================================
@@ -174,7 +174,7 @@ def add(self,
path = Path(path)
- if location is not None:
+ if location != PathLocation.NONE:
path = self._prepare(path, unique)
self._paths[name] = (location, path, path_type)
@@ -193,7 +193,7 @@ def init(self):
self.add(*path)
# These paths are unique per profile
- unique_profile_paths = [
+ unique_profile_paths: list[tuple[str, str | Path, PathLocation,
PathType]] = [
# Data paths
('SECRETS_FILE', 'secrets', PathLocation.DATA, PathType.FILE),
('CERT_STORE', 'cert_store', PathLocation.DATA, PathType.FOLDER),
@@ -201,6 +201,9 @@ def init(self):
('PLUGINS_DATA', 'plugins_data',
PathLocation.DATA, PathType.FOLDER),
+ # Cache paths
+ ('DOWNLOADS_THUMB', 'downloads.thumb', PathLocation.CACHE,
PathType.FOLDER),
+
# Config paths
('SETTINGS', 'settings.sqlite', PathLocation.CONFIG,
PathType.FILE),
('CONFIG_FILE', 'config', PathLocation.CONFIG, PathType.FILE),
@@ -210,6 +213,17 @@ def init(self):
PathLocation.CONFIG, PathType.FILE),
]
+ # Determine downloads dir
+ path = ('DOWNLOADS', 'downloads', PathLocation.DATA, PathType.FOLDER)
+ if sys.platform == 'win32' and not gajim.IS_PORTABLE:
+ download_dir = GLib.get_user_special_dir(
+ GLib.UserDirectory.DIRECTORY_DOWNLOAD)
+ assert download_dir is not None
+ path = ('DOWNLOADS', Path(download_dir) / 'Gajim',
+ PathLocation.NONE, PathType.FOLDER)
+
+ unique_profile_paths.append(path)
+
for path in unique_profile_paths:
self.add(*path, unique=True)
=====================================
gajim/common/const.py
=====================================
@@ -83,6 +83,7 @@ class PathLocation(IntEnum):
CONFIG = 0
CACHE = 1
DATA = 2
+ NONE = 3
@unique
=====================================
gajim/common/preview.py
=====================================
@@ -193,14 +193,8 @@ def update_progress(self, progress: float, request:
HTTPRequest) -> None:
class PreviewManager:
def __init__(self) -> None:
- self._orig_dir = Path(configpaths.get('MY_DATA')) / 'downloads'
- self._thumb_dir = Path(configpaths.get('MY_CACHE')) / 'downloads.thumb'
-
- if GLib.mkdir_with_parents(str(self._orig_dir), 0o700) != 0:
- log.error('Failed to create: %s', self._orig_dir)
-
- if GLib.mkdir_with_parents(str(self._thumb_dir), 0o700) != 0:
- log.error('Failed to create: %s', self._thumb_dir)
+ self._orig_dir = configpaths.get('DOWNLOADS')
+ self._thumb_dir = configpaths.get('DOWNLOADS_THUMB')
self._previews: dict[str, Preview] = {}
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/ece271929680b54004200cf31a5abb9e743ce4fb
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/ece271929680b54004200cf31a5abb9e743ce4fb
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]