mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 05:36:19 +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
|
include_package_data = true
|
||||||
python_requires = >=3.7
|
python_requires = >=3.7
|
||||||
install_requires =
|
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
|
paramiko
|
||||||
pyqt5
|
pyqt5
|
||||||
peewee
|
peewee
|
||||||
|
|
|
@ -58,7 +58,7 @@ def exception_handler(type, value, tb):
|
||||||
|
|
||||||
# Init database
|
# Init database
|
||||||
sqlite_db = SqliteDatabase(
|
sqlite_db = SqliteDatabase(
|
||||||
os.path.join(SETTINGS_DIR, 'settings.db'),
|
SETTINGS_DIR / 'settings.db',
|
||||||
pragmas={
|
pragmas={
|
||||||
'journal_mode': 'wal',
|
'journal_mode': 'wal',
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
APP_ID = os.path.join(TEMP_DIR, "socket")
|
APP_ID = TEMP_DIR / "socket"
|
||||||
|
|
||||||
|
|
||||||
class VortaApp(QtSingleApplication):
|
class VortaApp(QtSingleApplication):
|
||||||
|
@ -41,7 +42,7 @@ class VortaApp(QtSingleApplication):
|
||||||
check_failed_event = QtCore.pyqtSignal(dict)
|
check_failed_event = QtCore.pyqtSignal(dict)
|
||||||
|
|
||||||
def __init__(self, args_raw, single_app=False):
|
def __init__(self, args_raw, single_app=False):
|
||||||
super().__init__(APP_ID, args_raw)
|
super().__init__(str(APP_ID), args_raw)
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if self.isRunning():
|
if self.isRunning():
|
||||||
if single_app:
|
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
|
This function tries reading a file that is known to be restricted and warn the user about
|
||||||
incomplete backups.
|
incomplete backups.
|
||||||
"""
|
"""
|
||||||
test_path = os.path.expanduser('~/Library/Cookies')
|
test_path = Path('~/Library/Cookies').expanduser()
|
||||||
if os.path.exists(test_path) and not os.access(test_path, os.R_OK):
|
if test_path.exists() and not os.access(test_path, os.R_OK):
|
||||||
msg = QMessageBox()
|
msg = QMessageBox()
|
||||||
msg.setIcon(QMessageBox.Warning)
|
msg.setIcon(QMessageBox.Warning)
|
||||||
msg.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
|
msg.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
|
||||||
|
|
|
@ -47,7 +47,7 @@ def open_app_at_startup(enabled=True):
|
||||||
|
|
||||||
elif sys.platform.startswith('linux'):
|
elif sys.platform.startswith('linux'):
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from appdirs import user_config_dir
|
from platformdirs import user_config_path
|
||||||
|
|
||||||
is_flatpak = Path('/.flatpak-info').exists()
|
is_flatpak = Path('/.flatpak-info').exists()
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ def open_app_at_startup(enabled=True):
|
||||||
if is_flatpak:
|
if is_flatpak:
|
||||||
autostart_path = Path.home() / '.config' / 'autostart'
|
autostart_path = Path.home() / '.config' / 'autostart'
|
||||||
else:
|
else:
|
||||||
autostart_path = Path(user_config_dir("autostart"))
|
autostart_path = user_config_path("autostart")
|
||||||
|
|
||||||
if not autostart_path.exists():
|
if not autostart_path.exists():
|
||||||
autostart_path.mkdir(parents=True, exist_ok=True)
|
autostart_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
|
@ -1,25 +1,17 @@
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import appdirs
|
import platformdirs
|
||||||
|
|
||||||
APP_NAME = 'Vorta'
|
APP_NAME = 'Vorta'
|
||||||
APP_AUTHOR = 'BorgBase'
|
APP_AUTHOR = 'BorgBase'
|
||||||
APP_ID_DARWIN = 'com.borgbase.client.macos'
|
APP_ID_DARWIN = 'com.borgbase.client.macos'
|
||||||
dirs = appdirs.AppDirs(APP_NAME, APP_AUTHOR)
|
dirs = platformdirs.PlatformDirs(APP_NAME, APP_AUTHOR)
|
||||||
SETTINGS_DIR = dirs.user_data_dir
|
SETTINGS_DIR = dirs.user_data_path
|
||||||
LOG_DIR = dirs.user_log_dir
|
LOG_DIR = dirs.user_log_path
|
||||||
CACHE_DIR = dirs.user_cache_dir
|
CACHE_DIR = dirs.user_cache_path
|
||||||
TEMP_DIR = os.path.join(CACHE_DIR, "tmp")
|
TEMP_DIR = CACHE_DIR / "tmp"
|
||||||
PROFILE_BOOTSTRAP_FILE = Path.home() / '.vorta-init.json'
|
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):
|
# ensure directories exist
|
||||||
os.makedirs(LOG_DIR)
|
for dir in (SETTINGS_DIR, LOG_DIR, CACHE_DIR, TEMP_DIR):
|
||||||
|
dir.mkdir(parents=True, exist_ok=True)
|
||||||
if not os.path.exists(CACHE_DIR):
|
|
||||||
os.makedirs(CACHE_DIR)
|
|
||||||
|
|
||||||
if not os.path.exists(TEMP_DIR):
|
|
||||||
os.makedirs(TEMP_DIR)
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
from .config import LOG_DIR
|
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')
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
# create handlers
|
# 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.setLevel(logging.DEBUG)
|
||||||
fh.setFormatter(formatter)
|
fh.setFormatter(formatter)
|
||||||
logger.addHandler(fh)
|
logger.addHandler(fh)
|
||||||
|
|
Loading…
Reference in a new issue