mirror of
https://github.com/borgbase/vorta
synced 2024-12-21 23:33:13 +00:00
Migrate from appdirs to platformdirs (#1617)
Fixes #1610. Replace deprecated `appdirs` with fork `platformdirs`. Use the new `*_path` api of set fork. This changes the type of the constants defined in `vorta.config` holding locations to `pathlib.Path`. * setup.cfg : Replace dep `appdirs` with `platformdirs`. * src/vorta/config.py : Migrate. Simplify code for ensuring that the directories exist. * src/vorta/log.py * src/vorta/autostart.py * src/vorta/application.py * src/vorta/__main__.py
This commit is contained in:
parent
b01fa1056a
commit
961e0b5057
6 changed files with 20 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue