Improved publisher

This commit is contained in:
Sven Heidemann 2020-12-15 17:27:52 +01:00
parent 6f82bd8b35
commit 7ee2eff483
7 changed files with 41 additions and 21 deletions

View File

@ -3,6 +3,6 @@ from enum import Enum
class VersionEnum(Enum): class VersionEnum(Enum):
Major = 'major' Major = 'Major'
Minor = 'minor' Minor = 'Minor'
Micro = 'micro' Micro = 'Micro'

View File

@ -11,6 +11,7 @@ class Console:
_foreground_color: ForegroundColor = ForegroundColor.default _foreground_color: ForegroundColor = ForegroundColor.default
_x: Optional[int] = None _x: Optional[int] = None
_y: Optional[int] = None _y: Optional[int] = None
_disabled: bool = False
""" """
Properties Properties
@ -60,6 +61,9 @@ class Console:
@classmethod @classmethod
def _output(cls, string: str, x: int = None, y: int = None, end='\n'): def _output(cls, string: str, x: int = None, y: int = None, end='\n'):
if cls._disabled:
return
args = [] args = []
colored_args = [] colored_args = []
@ -95,6 +99,14 @@ class Console:
Console.read_line() Console.read_line()
exit() exit()
@classmethod
def disable(cls):
cls._disabled = True
@classmethod
def enable(cls):
cls._disabled = False
@classmethod @classmethod
def read(cls, output: str = None) -> str: def read(cls, output: str = None) -> str:
if output is not None: if output is not None:

View File

@ -15,10 +15,10 @@ class PublishSettings(ConfigurationModelBase):
self._source_path: Optional[str] = None self._source_path: Optional[str] = None
self._dist_path: Optional[str] = None self._dist_path: Optional[str] = None
self._templates: Optional[list[Template]] = None self._templates: list[Template] = []
self._included_files: Optional[list[str]] = None self._included_files: list[str] = []
self._excluded_files: Optional[list[str]] = None self._excluded_files: list[str] = []
self._template_ending: Optional[str] = None self._template_ending: Optional[str] = None
@ -74,7 +74,11 @@ class PublishSettings(ConfigurationModelBase):
try: try:
self._source_path = settings[PublishSettingsName.source_path.value] self._source_path = settings[PublishSettingsName.source_path.value]
self._dist_path = settings[PublishSettingsName.dist_path.value] self._dist_path = settings[PublishSettingsName.dist_path.value]
self._templates = Template().from_dict(settings[PublishSettingsName.templates.value]) for template in settings[PublishSettingsName.templates.value]:
temp = Template()
temp.from_dict(template)
self._templates.append(temp)
self._included_files = settings[PublishSettingsName.included_files.value] self._included_files = settings[PublishSettingsName.included_files.value]
self._excluded_files = settings[PublishSettingsName.excluded_files.value] self._excluded_files = settings[PublishSettingsName.excluded_files.value]
self._template_ending = settings[PublishSettingsName.template_ending.value] self._template_ending = settings[PublishSettingsName.template_ending.value]

View File

@ -19,7 +19,7 @@ class Template(ConfigurationModelBase):
license_description: Optional[str] = None, license_description: Optional[str] = None,
title: Optional[str] = None, title: Optional[str] = None,
author: Optional[str] = None, author: Optional[str] = None,
version: Optional[dict] = None version: Optional[Version] = Version()
): ):
ConfigurationModelBase.__init__(self) ConfigurationModelBase.__init__(self)
self._template_path: Optional[str] = template_path self._template_path: Optional[str] = template_path
@ -33,8 +33,7 @@ class Template(ConfigurationModelBase):
self._title: Optional[str] = title self._title: Optional[str] = title
self._author: Optional[str] = author self._author: Optional[str] = author
self._version: Optional[Version] = Version() self._version: Optional[Version] = version
self._version.from_dict(version)
self._file_content: Optional[str] = None self._file_content: Optional[str] = None

View File

@ -15,7 +15,7 @@ from sh_edraft.time.model import TimeFormatSettings
class PublisherTest(unittest.TestCase): class PublisherTest(unittest.TestCase):
def _configure(self): def _configure(self):
self._version = Version(2020, 12, 5).to_dict() self._version = Version(2020, 12, 5)
templates = [ templates = [
Template( Template(
'../../publish_templates/all_template.txt', '../../publish_templates/all_template.txt',

View File

@ -11,7 +11,7 @@
"ConsoleLogLevel": "TRACE", "ConsoleLogLevel": "TRACE",
"FileLogLevel": "TRACE" "FileLogLevel": "TRACE"
}, },
"PublisherSettings": { "PublishSettings": {
"SourcePath": "../", "SourcePath": "../",
"DistPath": "../../dist", "DistPath": "../../dist",
"Templates": [ "Templates": [
@ -27,9 +27,9 @@
"Title": "", "Title": "",
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"Version": { "Version": {
"major": 2020, "Major": 2020,
"minor": 12, "Minor": 12,
"micro": 9 "Micro": 9
} }
}, },
{ {
@ -44,9 +44,9 @@
"Title": "", "Title": "",
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"Version": { "Version": {
"major": 2020, "Major": 2020,
"minor": 12, "Minor": 12,
"micro": 9 "Micro": 9
} }
} }
], ],

View File

@ -1,6 +1,7 @@
from typing import Optional from typing import Optional
from sh_edraft.configuration.base import ConfigurationBase from sh_edraft.configuration.base import ConfigurationBase
from sh_edraft.console import Console
from sh_edraft.hosting import ApplicationHost from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting.base import ApplicationBase from sh_edraft.hosting.base import ApplicationBase
from sh_edraft.logging import Logger from sh_edraft.logging import Logger
@ -20,6 +21,7 @@ class Program(ApplicationBase):
self._configuration: Optional[ConfigurationBase] = None self._configuration: Optional[ConfigurationBase] = None
self._logger: Optional[LoggerBase] = None self._logger: Optional[LoggerBase] = None
self._publisher: Optional[PublisherBase] = None self._publisher: Optional[PublisherBase] = None
# Console.disable()
def create_application_host(self): def create_application_host(self):
self._app_host = ApplicationHost() self._app_host = ApplicationHost()
@ -36,6 +38,7 @@ class Program(ApplicationBase):
def create_services(self): def create_services(self):
# Add and create logger # Add and create logger
Console.enable()
self._services.add_singleton(LoggerBase, Logger) self._services.add_singleton(LoggerBase, Logger)
self._logger = self._services.get_service(LoggerBase) self._logger = self._services.get_service(LoggerBase)
@ -48,10 +51,12 @@ class Program(ApplicationBase):
self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}') self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}') self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}') self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')
#self._publisher.exclude() self._publisher.exclude('../tests')
#self._publisher.include() self._publisher.exclude('../tests_dev')
# self._publisher.include()
# self._publisher.create() # self._publisher.create()
print(self._publisher) self._publisher.create()
self._publisher.publish()
if __name__ == '__main__': if __name__ == '__main__':