diff --git a/setup.cfg b/setup.cfg index f5a5036b7..3c310d045 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,8 @@ package_dir = include_package_data = true python_requires = >=3.7 install_requires = - appdirs + platformdirs >=3.0.0, <4.0.0; sys_platform == 'darwin' # for macOS: breaking changes in 3.0.0, + platformdirs >=2.6.0, <4.0.0; sys_platform != 'darwin' # for others: 2.6+ works consistently. paramiko pyqt5 peewee diff --git a/src/vorta/__main__.py b/src/vorta/__main__.py index eb2ca3a1c..34a5bd8c3 100644 --- a/src/vorta/__main__.py +++ b/src/vorta/__main__.py @@ -58,7 +58,7 @@ def exception_handler(type, value, tb): # Init database sqlite_db = SqliteDatabase( - os.path.join(SETTINGS_DIR, 'settings.db'), + SETTINGS_DIR / 'settings.db', pragmas={ 'journal_mode': 'wal', }, diff --git a/src/vorta/application.py b/src/vorta/application.py index 3b9e427f0..3c9327db6 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -1,6 +1,7 @@ import logging import os import sys +from pathlib import Path from typing import Any, Dict, List, Tuple from PyQt5 import QtCore from PyQt5.QtWidgets import QMessageBox @@ -22,7 +23,7 @@ logger = logging.getLogger(__name__) -APP_ID = os.path.join(TEMP_DIR, "socket") +APP_ID = TEMP_DIR / "socket" class VortaApp(QtSingleApplication): @@ -41,7 +42,7 @@ class VortaApp(QtSingleApplication): check_failed_event = QtCore.pyqtSignal(dict) def __init__(self, args_raw, single_app=False): - super().__init__(APP_ID, args_raw) + super().__init__(str(APP_ID), args_raw) args = parse_args() if self.isRunning(): if single_app: @@ -193,8 +194,8 @@ def check_darwin_permissions(self): This function tries reading a file that is known to be restricted and warn the user about incomplete backups. """ - test_path = os.path.expanduser('~/Library/Cookies') - if os.path.exists(test_path) and not os.access(test_path, os.R_OK): + test_path = Path('~/Library/Cookies').expanduser() + if test_path.exists() and not os.access(test_path, os.R_OK): msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse) diff --git a/src/vorta/autostart.py b/src/vorta/autostart.py index 096d13b33..bd1c22736 100644 --- a/src/vorta/autostart.py +++ b/src/vorta/autostart.py @@ -47,7 +47,7 @@ def open_app_at_startup(enabled=True): elif sys.platform.startswith('linux'): from pathlib import Path - from appdirs import user_config_dir + from platformdirs import user_config_path is_flatpak = Path('/.flatpak-info').exists() @@ -58,7 +58,7 @@ def open_app_at_startup(enabled=True): if is_flatpak: autostart_path = Path.home() / '.config' / 'autostart' else: - autostart_path = Path(user_config_dir("autostart")) + autostart_path = user_config_path("autostart") if not autostart_path.exists(): autostart_path.mkdir(parents=True, exist_ok=True) diff --git a/src/vorta/config.py b/src/vorta/config.py index c744f55e0..80961e1b5 100644 --- a/src/vorta/config.py +++ b/src/vorta/config.py @@ -1,25 +1,17 @@ -import os from pathlib import Path -import appdirs +import platformdirs APP_NAME = 'Vorta' APP_AUTHOR = 'BorgBase' APP_ID_DARWIN = 'com.borgbase.client.macos' -dirs = appdirs.AppDirs(APP_NAME, APP_AUTHOR) -SETTINGS_DIR = dirs.user_data_dir -LOG_DIR = dirs.user_log_dir -CACHE_DIR = dirs.user_cache_dir -TEMP_DIR = os.path.join(CACHE_DIR, "tmp") +dirs = platformdirs.PlatformDirs(APP_NAME, APP_AUTHOR) +SETTINGS_DIR = dirs.user_data_path +LOG_DIR = dirs.user_log_path +CACHE_DIR = dirs.user_cache_path +TEMP_DIR = CACHE_DIR / "tmp" PROFILE_BOOTSTRAP_FILE = Path.home() / '.vorta-init.json' -if not os.path.exists(SETTINGS_DIR): - os.makedirs(SETTINGS_DIR) -if not os.path.exists(LOG_DIR): - os.makedirs(LOG_DIR) - -if not os.path.exists(CACHE_DIR): - os.makedirs(CACHE_DIR) - -if not os.path.exists(TEMP_DIR): - os.makedirs(TEMP_DIR) +# ensure directories exist +for dir in (SETTINGS_DIR, LOG_DIR, CACHE_DIR, TEMP_DIR): + dir.mkdir(parents=True, exist_ok=True) diff --git a/src/vorta/log.py b/src/vorta/log.py index 34ac2aa71..e0f8e7510 100644 --- a/src/vorta/log.py +++ b/src/vorta/log.py @@ -7,7 +7,6 @@ """ import logging -import os from logging.handlers import TimedRotatingFileHandler from .config import LOG_DIR @@ -23,7 +22,7 @@ def init_logger(background=False): formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # create handlers - fh = TimedRotatingFileHandler(os.path.join(LOG_DIR, 'vorta.log'), when='d', interval=1, backupCount=5) + fh = TimedRotatingFileHandler(LOG_DIR / 'vorta.log', when='d', interval=1, backupCount=5) fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) logger.addHandler(fh)