mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
Add the configuration to get user data.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .user_data_paths_port import UserDataPathsPort
|
||||
|
||||
__all__ = ['UserDataPathsPort']
|
||||
@@ -0,0 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class UserDataPathsPort(ABC):
|
||||
@abstractmethod
|
||||
def safe_create_user_data_dir(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_db_path(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_data_dir(self):
|
||||
pass
|
||||
@@ -0,0 +1,3 @@
|
||||
from .user_data_paths import UserDataPaths
|
||||
|
||||
__all__ = ['UserDataPaths']
|
||||
@@ -0,0 +1,56 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2023-2025 Kostiantyn Klochko <kklochko@protonmail.com> #
|
||||
# #
|
||||
# This file is part of tui-rsync. #
|
||||
# #
|
||||
# tui-rsync is free software: you can redistribute it and/or modify it under #
|
||||
# uthe terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# tui-rsync is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along with #
|
||||
# tui-rsync. If not, see <https://www.gnu.org/licenses/>. #
|
||||
################################################################################
|
||||
|
||||
import platformdirs
|
||||
import os
|
||||
|
||||
from tui_rsync.core.ports.configuration import UserDataPathsPort
|
||||
|
||||
|
||||
class UserDataPaths(UserDataPathsPort):
|
||||
"""
|
||||
Configuration of the tui-rsync
|
||||
"""
|
||||
__APP_NAME = "tui-rsync"
|
||||
__APP_AUTHOR = "KKlochko"
|
||||
__DB_NAME = "sync.db"
|
||||
|
||||
def safe_create_user_data_dir(self):
|
||||
self.safe_create_path(self.get_user_data_dir())
|
||||
|
||||
def get_user_db_path(self):
|
||||
return platformdirs.user_data_path(
|
||||
self.__APP_NAME,
|
||||
self.__APP_AUTHOR,
|
||||
self.__DB_NAME
|
||||
)
|
||||
|
||||
def get_user_data_dir(self):
|
||||
return platformdirs.user_data_dir(
|
||||
self.__APP_NAME,
|
||||
self.__APP_AUTHOR,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def safe_create_path(path):
|
||||
"""
|
||||
Create path's folders if they do not exist
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
@@ -1,7 +1,9 @@
|
||||
from peewee import SqliteDatabase
|
||||
from .database_manager import DatabaseManager
|
||||
from ...core.ports.configuration import UserDataPathsPort
|
||||
|
||||
|
||||
class SqliteDatabaseManager(DatabaseManager):
|
||||
def __init__(self, filepath='sync.db'):
|
||||
def __init__(self, user_data_paths: UserDataPathsPort):
|
||||
filepath = user_data_paths.get_user_db_path()
|
||||
super().__init__(SqliteDatabase(filepath))
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.user_interface.cli.cli import cli_app
|
||||
|
||||
|
||||
def main():
|
||||
UserDataPaths().safe_create_user_data_dir()
|
||||
cli_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -25,6 +25,7 @@ from tui_rsync.core.components.backup_plan.application.repository.backup_plan_re
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination
|
||||
from tui_rsync.core.shared_kernel.components.common import Label
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ def add(
|
||||
if source is None:
|
||||
source = console.input("What is the [yellow b]path to the source[/]? ")
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
repository = BackupPlanRepository(db)
|
||||
service = BackupPlanService(repository)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from tui_rsync.core.components.backup_plan.application.commands import RemoveAll
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||
|
||||
console = Console()
|
||||
@@ -42,7 +43,7 @@ def one(
|
||||
[red b]Remove[/] an [yellow]existing backup plan[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
repository = BackupPlanRepository(db)
|
||||
service = BackupPlanService(repository)
|
||||
|
||||
@@ -65,7 +66,7 @@ def all():
|
||||
[red b]Remove[/] [yellow] all existing backup plans[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
removed = RemoveAllBackupBackupPlansCommand().execute()
|
||||
|
||||
if removed:
|
||||
|
||||
@@ -25,6 +25,7 @@ from tui_rsync.core.components.backup_plan.application.Queries import GetAllBack
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||
from tui_rsync.user_interface.cli.components.backup_plan.formating import BackupPlanFormat
|
||||
|
||||
@@ -44,7 +45,7 @@ def one(
|
||||
[green b]Show[/] an [yellow]existing backup plan by the id[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
repository = BackupPlanRepository(db)
|
||||
service = BackupPlanService(repository)
|
||||
|
||||
@@ -67,7 +68,7 @@ def all():
|
||||
[green b]Show[/] [yellow]all existing backup plans[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
query = GetAllBackupBackupPlansQuery()
|
||||
|
||||
for backup_plan in query.execute():
|
||||
|
||||
Reference in New Issue
Block a user