2022.7 - cpl-translation #90
@ -27,6 +27,7 @@ class InitTemplate:
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
$Imports
|
$Imports
|
||||||
|
|
||||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
@ -227,11 +227,19 @@ class PublisherService(PublisherABC):
|
|||||||
imports = '# imports:'
|
imports = '# imports:'
|
||||||
else:
|
else:
|
||||||
is_started = False
|
is_started = False
|
||||||
|
build_ignore = False
|
||||||
for line in module_file_lines:
|
for line in module_file_lines:
|
||||||
if line.__contains__('# imports'):
|
if line.__contains__('# imports'):
|
||||||
is_started = True
|
is_started = True
|
||||||
|
|
||||||
if ((line.__contains__('from') or line.__contains__('import')) and is_started) or line.startswith('__cli_startup_extension__'):
|
if line.__contains__('# build-ignore'):
|
||||||
|
build_ignore = True
|
||||||
|
|
||||||
|
if line.__contains__('# build-ignore-end') and is_started:
|
||||||
|
module_py_lines.append('# build-ignore-end'.replace('\n', ''))
|
||||||
|
build_ignore = False
|
||||||
|
|
||||||
|
if ((line.__contains__('from') or line.__contains__('import')) and is_started) or line.startswith('__cli_startup_extension__') or build_ignore:
|
||||||
module_py_lines.append(line.replace('\n', ''))
|
module_py_lines.append(line.replace('\n', ''))
|
||||||
|
|
||||||
if len(module_py_lines) > 0:
|
if len(module_py_lines) > 0:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from typing import Union, Type, Callable, Optional
|
from typing import Union, Type, Callable, Optional
|
||||||
|
|
||||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||||
from cpl_core.console import Console
|
|
||||||
from cpl_core.database.context.database_context_abc import DatabaseContextABC
|
from cpl_core.database.context.database_context_abc import DatabaseContextABC
|
||||||
from cpl_core.database.database_settings import DatabaseSettings
|
from cpl_core.database.database_settings import DatabaseSettings
|
||||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||||
@ -59,17 +58,6 @@ class ServiceCollection(ServiceCollectionABC):
|
|||||||
for pipe in PipeABC.__subclasses__():
|
for pipe in PipeABC.__subclasses__():
|
||||||
self.add_transient(PipeABC, pipe)
|
self.add_transient(PipeABC, pipe)
|
||||||
|
|
||||||
def add_translation(self):
|
|
||||||
try:
|
|
||||||
from cpl_translation.translation_service_abc import TranslationServiceABC
|
|
||||||
from cpl_translation.translation_service import TranslationService
|
|
||||||
from cpl_translation.translate_pipe import TranslatePipe
|
|
||||||
from cpl_translation.translation_settings import TranslationSettings
|
|
||||||
self.add_singleton(TranslationServiceABC, TranslationService)
|
|
||||||
self.add_transient(PipeABC, TranslatePipe)
|
|
||||||
except ImportError as e:
|
|
||||||
Console.error('cpl-translation is not installed', str(e))
|
|
||||||
|
|
||||||
def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None):
|
def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None):
|
||||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
||||||
return self
|
return self
|
||||||
|
@ -35,9 +35,9 @@ class ServiceCollectionABC(ABC):
|
|||||||
r"""Adds the CPL internal pipes as transient"""
|
r"""Adds the CPL internal pipes as transient"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_translation(self):
|
def add_translation(self):
|
||||||
r"""Adds the CPL translation"""
|
r"""Adds the CPL translation"""
|
||||||
|
raise NotImplementedError('You should install and use the cpl-translation package')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -1 +1,49 @@
|
|||||||
# imports:
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
cpl-translation sh-edraft Common Python library Translation
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
sh-edraft Common Python library Python Translation
|
||||||
|
|
||||||
|
:copyright: (c) 2022 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'cpl_translation'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||||
|
__version__ = '2022.8.1.dev7'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
# imports:
|
||||||
|
# build-ignore
|
||||||
|
|
||||||
|
|
||||||
|
def add_translation(self):
|
||||||
|
from cpl_core.console import Console
|
||||||
|
from cpl_core.pipes import PipeABC
|
||||||
|
from cpl_translation.translate_pipe import TranslatePipe
|
||||||
|
from cpl_translation.translation_service import TranslationService
|
||||||
|
from cpl_translation.translation_service_abc import TranslationServiceABC
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.add_singleton(TranslationServiceABC, TranslationService)
|
||||||
|
self.add_transient(PipeABC, TranslatePipe)
|
||||||
|
except ImportError as e:
|
||||||
|
Console.error('cpl-translation is not installed', str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
from cpl_core.dependency_injection import ServiceCollection
|
||||||
|
ServiceCollection.add_translation = add_translation
|
||||||
|
|
||||||
|
|
||||||
|
init()
|
||||||
|
# build-ignore-end
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major='2022', minor='8', micro='1.dev7')
|
||||||
|
Loading…
Reference in New Issue
Block a user