mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-20 05:37:43 +00:00
Add the injector and configurations.
This commit is contained in:
Generated
+16
-1
@@ -48,6 +48,21 @@ files = [
|
|||||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "injector"
|
||||||
|
version = "0.22.0"
|
||||||
|
description = "Injector - Python dependency injection framework, inspired by Guice"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "injector-0.22.0-py2.py3-none-any.whl", hash = "sha256:74379ccef3b893bc7d0b7d504c255b5160c5a55e97dc7bdcc73cb33cc7dce3a1"},
|
||||||
|
{file = "injector-0.22.0.tar.gz", hash = "sha256:79b2d4a0874c75d3aa735f11c5b32b89d9542711ca07071161882c5e9cc15ed6"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
dev = ["black (==24.3.0)", "build (==1.0.3)", "check-manifest (==0.49)", "click (==8.1.7)", "coverage[toml] (==7.3.2)", "exceptiongroup (==1.2.0)", "importlib-metadata (==7.0.0)", "iniconfig (==2.0.0)", "mypy (==1.7.1)", "mypy-extensions (==1.0.0)", "packaging (==23.2)", "pathspec (==0.12.1)", "platformdirs (==4.1.0)", "pluggy (==1.3.0)", "pyproject-hooks (==1.0.0)", "pytest (==7.4.3)", "pytest-cov (==4.1.0)", "tomli (==2.0.1)", "typing-extensions (==4.9.0)", "zipp (==3.17.0)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "markdown-it-py"
|
name = "markdown-it-py"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@@ -227,4 +242,4 @@ test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6.
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "c4e6d6acce5883eb7abc4928705c61919b15c9494d8ccf1404f480e08c71e870"
|
content-hash = "d0b0192e0197ecd6f960d87e534852e700a4a52e72ed35f1dd58806f2a96c354"
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ typer = "^0.7.0"
|
|||||||
peewee = "^3.15.4"
|
peewee = "^3.15.4"
|
||||||
pyfzf = "^0.3.1"
|
pyfzf = "^0.3.1"
|
||||||
platformdirs = "^3.1.1"
|
platformdirs = "^3.1.1"
|
||||||
|
injector = "^0.22.0"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
tui-rsync = "tui_rsync.main:main"
|
tui-rsync = "tui_rsync.main:main"
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from injector import singleton, inject, Injector, Module, provider
|
||||||
|
|
||||||
|
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort
|
||||||
|
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.ports.configuration import UserDataPathsPort
|
||||||
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
|
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||||
|
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||||
|
|
||||||
|
|
||||||
|
class Configuration(Module):
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_user_data_paths(self) -> UserDataPathsPort:
|
||||||
|
return UserDataPaths()
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_database_manager(self, user_data_paths: UserDataPathsPort) -> DatabaseManagerPort:
|
||||||
|
return SqliteDatabaseManager(user_data_paths)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_plan_repository(self, database_manager: DatabaseManagerPort) -> BackupPlanRepositoryPort:
|
||||||
|
return BackupPlanRepository(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_plan_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupPlanService:
|
||||||
|
return BackupPlanService(backup_plan_repository)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from injector import Injector
|
||||||
|
|
||||||
|
|
||||||
|
class CurrentConfiguration:
|
||||||
|
"""
|
||||||
|
Manages global state for the configuration using injector.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_injector: Injector | None = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_injector() -> Injector:
|
||||||
|
if CurrentConfiguration._injector is None:
|
||||||
|
raise RuntimeError("Injector not initialized")
|
||||||
|
return CurrentConfiguration._injector
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(instance):
|
||||||
|
return CurrentConfiguration.get_injector().get(instance)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_injector(new_injector):
|
||||||
|
CurrentConfiguration._injector = new_injector
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
|
from injector import Injector
|
||||||
|
|
||||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||||
|
from tui_rsync.infrastructure.configuration.configuration import Configuration
|
||||||
|
from tui_rsync.infrastructure.configuration.current_configuration import CurrentConfiguration
|
||||||
from tui_rsync.user_interface.cli.cli import cli_app
|
from tui_rsync.user_interface.cli.cli import cli_app
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
injector = Injector([Configuration()])
|
||||||
|
CurrentConfiguration.set_injector(injector)
|
||||||
UserDataPaths().safe_create_user_data_dir()
|
UserDataPaths().safe_create_user_data_dir()
|
||||||
cli_app()
|
cli_app()
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,10 @@ from rich.console import Console
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
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.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.components.backup_plan.domain import BackupPlan, Source, Destination
|
||||||
from tui_rsync.core.shared_kernel.components.common import Label
|
from tui_rsync.core.shared_kernel.components.common import Label
|
||||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
from tui_rsync.infrastructure.configuration.current_configuration import CurrentConfiguration
|
||||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
|
||||||
|
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
@@ -58,9 +56,7 @@ def add(
|
|||||||
if source is None:
|
if source is None:
|
||||||
source = console.input("What is the [yellow b]path to the source[/]? ")
|
source = console.input("What is the [yellow b]path to the source[/]? ")
|
||||||
|
|
||||||
db = SqliteDatabaseManager(UserDataPaths())
|
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
|
||||||
repository = BackupPlanRepository(db)
|
|
||||||
service = BackupPlanService(repository)
|
|
||||||
|
|
||||||
plan = BackupPlan(label=Label(label), source=Source(source), destinations=[Destination(path) for path in destinations])
|
plan = BackupPlan(label=Label(label), source=Source(source), destinations=[Destination(path) for path in destinations])
|
||||||
service.add(plan)
|
service.add(plan)
|
||||||
|
|||||||
Reference in New Issue
Block a user