Compare commits
1 Commits
cc76227199
...
2025.10.19
| Author | SHA1 | Date | |
|---|---|---|---|
| 88d5d78583 |
@@ -75,3 +75,9 @@ class Application(ApplicationABC):
|
|||||||
test_settings1 = Configuration.get(TestSettings)
|
test_settings1 = Configuration.get(TestSettings)
|
||||||
Console.write_line(test_settings1.value)
|
Console.write_line(test_settings1.value)
|
||||||
# self.test_send_mail()
|
# self.test_send_mail()
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
while x < 500:
|
||||||
|
Console.write_line("Running...")
|
||||||
|
x += 1
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
from application import Application
|
from application import Application
|
||||||
from cpl.application import ApplicationBuilder
|
from cpl.application import ApplicationBuilder
|
||||||
from cpl.core.console import Console
|
|
||||||
from test_extension import TestExtension
|
from test_extension import TestExtension
|
||||||
from startup import Startup
|
from startup import Startup
|
||||||
from test_startup_extension import TestStartupExtension
|
from test_startup_extension import TestStartupExtension
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
Console.write_line("\n\n--- Application Starting ---\n")
|
|
||||||
app_builder = ApplicationBuilder(Application)
|
app_builder = ApplicationBuilder(Application)
|
||||||
app_builder.with_startup(Startup)
|
app_builder.with_startup(Startup)
|
||||||
app_builder.with_extension(TestStartupExtension)
|
app_builder.with_extension(TestStartupExtension)
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ class ApplicationABC(ABC):
|
|||||||
Contains instances of prepared objects
|
Contains instances of prepared objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def extend(cls, name: str | Callable, func: Callable[[Self], Self]):
|
||||||
|
r"""Extend the Application with a custom method
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
name: :class:`str`
|
||||||
|
Name of the method
|
||||||
|
func: :class:`Callable[[Self], Self]`
|
||||||
|
Function that takes the Application as a parameter and returns it
|
||||||
|
"""
|
||||||
|
if callable(name):
|
||||||
|
name = name.__name__
|
||||||
|
|
||||||
|
setattr(cls, name, func)
|
||||||
|
return cls
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(
|
def __init__(
|
||||||
self, services: ServiceProvider, loaded_modules: set[TModule], required_modules: list[str | object] = None
|
self, services: ServiceProvider, loaded_modules: set[TModule], required_modules: list[str | object] = None
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from typing import Callable
|
|||||||
from cpl.core.property import classproperty
|
from cpl.core.property import classproperty
|
||||||
from cpl.dependency.context import get_provider, use_root_provider
|
from cpl.dependency.context import get_provider, use_root_provider
|
||||||
from cpl.dependency.service_collection import ServiceCollection
|
from cpl.dependency.service_collection import ServiceCollection
|
||||||
from cpl.core.service.startup_task import StartupTask
|
from cpl.dependency.hosted.startup_task import StartupTask
|
||||||
|
|
||||||
|
|
||||||
class Host:
|
class Host:
|
||||||
@@ -86,9 +86,10 @@ class Host:
|
|||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
except (KeyboardInterrupt, asyncio.CancelledError):
|
except (KeyboardInterrupt, asyncio.CancelledError):
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
await cls._stop_all()
|
||||||
|
|
||||||
cls.get_loop().run_until_complete(runner())
|
cls.get_loop().run_until_complete(runner())
|
||||||
cls.get_loop().run_until_complete(cls.wait_for_all())
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, func: Callable, *args, **kwargs):
|
def run(cls, func: Callable, *args, **kwargs):
|
||||||
|
|||||||
@@ -11,16 +11,12 @@ T = TypeVar("T", bound="CPLStructureModel")
|
|||||||
|
|
||||||
|
|
||||||
class CPLStructureModel:
|
class CPLStructureModel:
|
||||||
def __init__(self, path: Optional[str] = None, ignore_fields: Optional[List[str]] = None):
|
def __init__(self, path: Optional[str] = None):
|
||||||
self._path = path
|
self.__path = path
|
||||||
|
|
||||||
self._ignore = {"_ignore", "_path"}
|
|
||||||
if ignore_fields is not None:
|
|
||||||
self._ignore.update(ignore_fields)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self) -> Optional[str]:
|
def path(self) -> Optional[str]:
|
||||||
return self._path
|
return self.__path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls: Type[T], path: Path | str) -> T:
|
def from_file(cls: Type[T], path: Path | str) -> T:
|
||||||
@@ -72,7 +68,7 @@ class CPLStructureModel:
|
|||||||
def to_json(self) -> Dict[str, Any]:
|
def to_json(self) -> Dict[str, Any]:
|
||||||
result: Dict[str, Any] = {}
|
result: Dict[str, Any] = {}
|
||||||
for key, value in self.__dict__.items():
|
for key, value in self.__dict__.items():
|
||||||
if not key.startswith("_") or key in self._ignore:
|
if not key.startswith("_") or key.startswith("__") or key.endswith("_"):
|
||||||
continue
|
continue
|
||||||
out_key = _self_or_cls_snake_to_camel(key[1:])
|
out_key = _self_or_cls_snake_to_camel(key[1:])
|
||||||
|
|
||||||
@@ -83,13 +79,13 @@ class CPLStructureModel:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if not self._path:
|
if not self.__path:
|
||||||
raise ValueError("Cannot save model without a path.")
|
raise ValueError("Cannot save model without a path.")
|
||||||
|
|
||||||
if not Path(self._path).exists():
|
if not Path(self.__path).exists():
|
||||||
os.makedirs(Path(self._path).parent, exist_ok=True)
|
os.makedirs(Path(self.__path).parent, exist_ok=True)
|
||||||
|
|
||||||
with open(self._path, "w", encoding="utf-8") as f:
|
with open(self.__path, "w", encoding="utf-8") as f:
|
||||||
json.dump(self.to_json(), f, indent=2)
|
json.dump(self.to_json(), f, indent=2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -24,23 +24,23 @@ class Workspace(CPLStructureModel):
|
|||||||
default_project: Optional[str],
|
default_project: Optional[str],
|
||||||
scripts: Dict[str, str],
|
scripts: Dict[str, str],
|
||||||
):
|
):
|
||||||
CPLStructureModel.__init__(self, path, ["_actual_projects", "_project_names"])
|
CPLStructureModel.__init__(self, path)
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._projects = projects
|
self._projects = projects
|
||||||
self._default_project = default_project
|
self._default_project = default_project
|
||||||
|
|
||||||
self._actual_projects = []
|
self.__actual_projects = []
|
||||||
self._project_names = []
|
self.__project_names = []
|
||||||
for project in projects:
|
for project in projects:
|
||||||
if Path(project).is_dir() or not Path(project).exists():
|
if Path(project).is_dir() or not Path(project).exists():
|
||||||
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
|
raise ValueError(f"Project path '{project}' does not exist or is a directory.")
|
||||||
|
|
||||||
p = Project.from_file(project)
|
p = Project.from_file(project)
|
||||||
self._actual_projects.append(p)
|
self.__actual_projects.append(p)
|
||||||
self._project_names.append(p.name)
|
self.__project_names.append(p.name)
|
||||||
|
|
||||||
if default_project is not None and default_project not in self._project_names:
|
if default_project is not None and default_project not in self.__project_names:
|
||||||
raise ValueError(f"Default project '{default_project}' not found in workspace projects.")
|
raise ValueError(f"Default project '{default_project}' not found in workspace projects.")
|
||||||
|
|
||||||
self._scripts = scripts
|
self._scripts = scripts
|
||||||
@@ -63,11 +63,11 @@ class Workspace(CPLStructureModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def actual_projects(self) -> List[Project]:
|
def actual_projects(self) -> List[Project]:
|
||||||
return self._actual_projects
|
return self.__actual_projects
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def project_names(self) -> List[str]:
|
def project_names(self) -> List[str]:
|
||||||
return self._project_names
|
return self.__project_names
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_project(self) -> Optional[str]:
|
def default_project(self) -> Optional[str]:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from cpl.core.time.cron import Cron
|
from cpl.core.time.cron import Cron
|
||||||
from cpl.core.service import HostedService
|
from cpl.dependency.hosted import HostedService
|
||||||
|
|
||||||
|
|
||||||
class CronjobABC(HostedService, ABC):
|
class CronjobABC(HostedService, ABC):
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from cpl.database.model.migration import Migration
|
|||||||
from cpl.database.model.server_type import ServerType, ServerTypes
|
from cpl.database.model.server_type import ServerType, ServerTypes
|
||||||
from cpl.database.schema.executed_migration import ExecutedMigration
|
from cpl.database.schema.executed_migration import ExecutedMigration
|
||||||
from cpl.database.schema.executed_migration_dao import ExecutedMigrationDao
|
from cpl.database.schema.executed_migration_dao import ExecutedMigrationDao
|
||||||
from cpl.core.service import StartupTask
|
from cpl.dependency.hosted import StartupTask
|
||||||
|
|
||||||
|
|
||||||
class MigrationService(StartupTask):
|
class MigrationService(StartupTask):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from cpl.database.abc.data_seeder_abc import DataSeederABC
|
from cpl.database.abc.data_seeder_abc import DataSeederABC
|
||||||
from cpl.database.logger import DBLogger
|
from cpl.database.logger import DBLogger
|
||||||
from cpl.dependency import ServiceProvider
|
from cpl.dependency import ServiceProvider
|
||||||
from cpl.core.service import StartupTask
|
from cpl.dependency.hosted import StartupTask
|
||||||
|
|
||||||
|
|
||||||
class SeederService(StartupTask):
|
class SeederService(StartupTask):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from cpl.core.errors import module_dependency_error
|
|||||||
from cpl.core.log.logger_abc import LoggerABC
|
from cpl.core.log.logger_abc import LoggerABC
|
||||||
from cpl.core.typing import T, Service
|
from cpl.core.typing import T, Service
|
||||||
from cpl.core.utils.cache import Cache
|
from cpl.core.utils.cache import Cache
|
||||||
from cpl.core.service.startup_task import StartupTask
|
from cpl.dependency.hosted.startup_task import StartupTask
|
||||||
from cpl.dependency.module.module import Module
|
from cpl.dependency.module.module import Module
|
||||||
from cpl.dependency.service_descriptor import ServiceDescriptor
|
from cpl.dependency.service_descriptor import ServiceDescriptor
|
||||||
from cpl.dependency.service_lifetime import ServiceLifetimeEnum
|
from cpl.dependency.service_lifetime import ServiceLifetimeEnum
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from typing import Type
|
|||||||
|
|
||||||
from cpl.core.configuration import ConfigurationModelABC
|
from cpl.core.configuration import ConfigurationModelABC
|
||||||
from cpl.core.typing import T
|
from cpl.core.typing import T
|
||||||
from cpl.core.service import StartupTask
|
from cpl.dependency.hosted import StartupTask
|
||||||
from cpl.dependency.module.module import Module
|
from cpl.dependency.module.module import Module
|
||||||
|
|
||||||
TModule = Type[Module]
|
TModule = Type[Module]
|
||||||
|
|||||||
Reference in New Issue
Block a user