From 9e3c631ac4c42972fa5432cfcb30f3ad8a1056dc Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Dec 2020 17:37:43 +0100 Subject: [PATCH] Improved publish process --- src/build.json | 65 +++++++++++++++++++ src/sh_edraft/cli/command/__init__.py | 25 +++++++ src/sh_edraft/cli/command/base/__init__.py | 25 +++++++ src/sh_edraft/cli/cpl_cli/__init__.py | 25 +++++++ src/sh_edraft/cli/cpl_cli/cli.py | 37 +---------- .../cli/cpl_cli/commands/__init__.py | 25 +++++++ src/sh_edraft/cli/cpl_cli/commands/build.py | 26 -------- .../app/build.json} | 8 +-- src/sh_edraft/cli/interpreter/__init__.py | 25 +++++++ src/sh_edraft/logging/logger.py | 2 +- src/sh_edraft/publishing/publisher.py | 31 +++++++-- 11 files changed, 225 insertions(+), 69 deletions(-) create mode 100644 src/build.json delete mode 100644 src/sh_edraft/cli/cpl_cli/commands/build.py rename src/sh_edraft/cli/cpl_cli/{project.json => templates/app/build.json} (79%) diff --git a/src/build.json b/src/build.json new file mode 100644 index 00000000..da1551cc --- /dev/null +++ b/src/build.json @@ -0,0 +1,65 @@ +{ + "TimeFormatSettings": { + "DateFormat": "%Y-%m-%d", + "TimeFormat": "%H:%M:%S", + "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", + "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" + }, + "LoggingSettings": { + "Path": "../build/logs/", + "Filename": "log_$start_time.log", + "ConsoleLogLevel": "INFO", + "FileLogLevel": "TRACE" + }, + "PublishSettings": { + "SourcePath": "./", + "DistPath": "../build/dist", + "Templates": [ + { + "TemplatePath": "../publish_templates/all_template.txt", + "Name": "all", + "Description": "", + "LongDescription": "", + "CopyrightDate": "2020", + "CopyrightName": "sh-edraft.de", + "LicenseName": "MIT", + "LicenseDescription": ", see LICENSE for more details.", + "Title": "", + "Author": "Sven Heidemann", + "Version": { + "Major": 2020, + "Minor": 12, + "Micro": 9 + } + }, + { + "TemplatePath": "../publish_templates/all_template.txt", + "Name": "sh_edraft", + "Description": "common python library", + "LongDescription": "Library to share common classes and models used at sh-edraft.de", + "CopyrightDate": "2020", + "CopyrightName": "sh-edraft.de", + "LicenseName": "MIT", + "LicenseDescription": ", see LICENSE for more details.", + "Title": "", + "Author": "Sven Heidemann", + "Version": { + "Major": 2020, + "Minor": 12, + "Micro": 9 + } + } + ], + "IncludedFiles": [ + "../LICENSE", + "../README.md", + "../requirements.txt", + "sh_edraft/cli/cpl_cli/templates" + ], + "ExcludedFiles": [ + "./tests", + "./tests_dev" + ], + "TemplateEnding": "_template.txt" + } +} diff --git a/src/sh_edraft/cli/command/__init__.py b/src/sh_edraft/cli/command/__init__.py index e69de29b..336d4a17 100644 --- a/src/sh_edraft/cli/command/__init__.py +++ b/src/sh_edraft/cli/command/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.command +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.command' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/cli/command/base/__init__.py b/src/sh_edraft/cli/command/base/__init__.py index e69de29b..83d30e3e 100644 --- a/src/sh_edraft/cli/command/base/__init__.py +++ b/src/sh_edraft/cli/command/base/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.command.base +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.command.base' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/cli/cpl_cli/__init__.py b/src/sh_edraft/cli/cpl_cli/__init__.py index e69de29b..1c8b1737 100644 --- a/src/sh_edraft/cli/cpl_cli/__init__.py +++ b/src/sh_edraft/cli/cpl_cli/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.cpl_cli +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.cpl_cli' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/cli/cpl_cli/cli.py b/src/sh_edraft/cli/cpl_cli/cli.py index 798829f7..a1eb8a70 100644 --- a/src/sh_edraft/cli/cpl_cli/cli.py +++ b/src/sh_edraft/cli/cpl_cli/cli.py @@ -2,49 +2,21 @@ import sys import traceback from typing import Optional -from sh_edraft.cli.cpl_cli.commands.build import Build +from sh_edraft.cli.cpl_cli.commands.build.build import Build from sh_edraft.cli.cpl_cli.commands.help import Help from sh_edraft.cli.cpl_cli.commands.new import New from sh_edraft.cli.cpl_cli.commands.version import Version from sh_edraft.cli.interpreter.interpreter import Interpreter -from sh_edraft.configuration.base import ConfigurationBase from sh_edraft.console.console import Console -from sh_edraft.hosting.application_host import ApplicationHost -from sh_edraft.hosting.base.application_base import ApplicationBase -from sh_edraft.logging.logger import Logger -from sh_edraft.logging.base.logger_base import LoggerBase -from sh_edraft.publishing.publisher import Publisher -from sh_edraft.publishing.base.publisher_base import PublisherBase -from sh_edraft.service.providing.service_provider import ServiceProviderBase -class CLI(ApplicationBase): +class CLI: def __init__(self): - ApplicationBase.__init__(self) - - self._app_host: Optional[ApplicationHost] = None - self._services: Optional[ServiceProviderBase] = None - self._configuration: Optional[ConfigurationBase] = None - self._logger: Optional[LoggerBase] = None - self._interpreter = Interpreter() - def create_application_host(self): - self._app_host = ApplicationHost() - self._configuration = self._app_host.configuration - self._services = self._app_host.services - - def create_configuration(self): - self._configuration.add_json_file(f'project.json') - - def create_services(self): - self._services.add_singleton(LoggerBase, Logger) - self._logger = self._services.get_service(LoggerBase) - self._services.add_singleton(PublisherBase, Publisher) - def setup(self): - self._interpreter.add_command(Build(self._services, self._configuration)) + self._interpreter.add_command(Build()) self._interpreter.add_command(Help()) self._interpreter.add_command(New()) self._interpreter.add_command(Version()) @@ -61,9 +33,6 @@ class CLI(ApplicationBase): def main(): cli = CLI() - cli.create_application_host() - cli.create_configuration() - cli.create_services() cli.setup() cli.main() diff --git a/src/sh_edraft/cli/cpl_cli/commands/__init__.py b/src/sh_edraft/cli/cpl_cli/commands/__init__.py index e69de29b..8f0a8760 100644 --- a/src/sh_edraft/cli/cpl_cli/commands/__init__.py +++ b/src/sh_edraft/cli/cpl_cli/commands/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.cpl_cli.commands +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.cpl_cli.commands' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/cli/cpl_cli/commands/build.py b/src/sh_edraft/cli/cpl_cli/commands/build.py deleted file mode 100644 index 15653d15..00000000 --- a/src/sh_edraft/cli/cpl_cli/commands/build.py +++ /dev/null @@ -1,26 +0,0 @@ -from sh_edraft.cli.command.base.command_base import CommandBase -from sh_edraft.configuration.base.configuration_base import ConfigurationBase -from sh_edraft.console.console import Console -from sh_edraft.publishing.publisher import Publisher -from sh_edraft.publishing.base.publisher_base import PublisherBase -from sh_edraft.service.providing.service_provider import ServiceProviderBase - - -class Build(CommandBase): - - def __init__(self, services: ServiceProviderBase, config: ConfigurationBase): - CommandBase.__init__(self) - self._services = services - self._config = config - - self._aliases.append('-b') - self._aliases.append('-B') - self._publisher: Publisher = self._services.get_service(PublisherBase) - - def run(self, args: list[str]): - if len(args) > 0: - Console.error(f'Invalid arguments {args}') - Console.error('Run \'cpl help\'') - - self._publisher.create() - self._publisher.publish() diff --git a/src/sh_edraft/cli/cpl_cli/project.json b/src/sh_edraft/cli/cpl_cli/templates/app/build.json similarity index 79% rename from src/sh_edraft/cli/cpl_cli/project.json rename to src/sh_edraft/cli/cpl_cli/templates/app/build.json index 5d15af9e..c6ea10bc 100644 --- a/src/sh_edraft/cli/cpl_cli/project.json +++ b/src/sh_edraft/cli/cpl_cli/templates/app/build.json @@ -6,14 +6,14 @@ "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" }, "LoggingSettings": { - "Path": "logs/", + "Path": "build/logs/", "Filename": "log_$start_time.log", "ConsoleLogLevel": "INFO", - "FileLogLevel": "TRACE" + "FileLogLevel": "INFO" }, "PublishSettings": { - "SourcePath": "../", - "DistPath": "../../../../dist", + "SourcePath": "./", + "DistPath": "build/dist", "Templates": [], "IncludedFiles": [], "ExcludedFiles": [], diff --git a/src/sh_edraft/cli/interpreter/__init__.py b/src/sh_edraft/cli/interpreter/__init__.py index e69de29b..fdf21dc1 100644 --- a/src/sh_edraft/cli/interpreter/__init__.py +++ b/src/sh_edraft/cli/interpreter/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.interpreter +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.interpreter' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/logging/logger.py b/src/sh_edraft/logging/logger.py index ec96469e..6668132e 100644 --- a/src/sh_edraft/logging/logger.py +++ b/src/sh_edraft/logging/logger.py @@ -48,7 +48,7 @@ class Logger(LoggerBase): try: # check if log file path exists if not os.path.exists(self._path): - os.mkdir(self._path) + os.makedirs(self._path) except Exception as e: self._fatal_console(__name__, 'Cannot create log dir', ex=e) diff --git a/src/sh_edraft/publishing/publisher.py b/src/sh_edraft/publishing/publisher.py index 2e922f36..d426ee5f 100644 --- a/src/sh_edraft/publishing/publisher.py +++ b/src/sh_edraft/publishing/publisher.py @@ -16,6 +16,8 @@ class Publisher(PublisherBase): self._logger: LoggerBase = logger self._publish_settings: PublishSettings = publish_settings + self._included_files: list[str] = [] + @property def source_path(self) -> str: return self._publish_settings.source_path @@ -53,10 +55,31 @@ class Publisher(PublisherBase): def _read_source_path(self): self._logger.trace(__name__, f'Started {__name__}._read_source_path') + included_files = self._publish_settings.included_files + for included in included_files: + if os.path.isdir(included): + self._publish_settings.included_files.remove(included) + + for r, d, f in os.walk(included): + for file in f: + file_path = os.path.join(self._publish_settings.source_path, r, file) + if os.path.isfile(file_path): + self._included_files.append(file_path) + else: + self._logger.fatal(__name__, f'File not found: {file}') + for r, d, f in os.walk(self._publish_settings.source_path): for file in f: - if file.endswith('.py') or file in self._publish_settings.included_files: - self._publish_settings.included_files.append(os.path.join(r, file)) + is_file_excluded = False + if os.path.join(r, file) in self._publish_settings.excluded_files: + is_file_excluded = True + else: + for excluded in self._publish_settings.excluded_files: + if os.path.join(r, file).__contains__(excluded): + is_file_excluded = True + + if not is_file_excluded and file.endswith('.py') or file in self._publish_settings.included_files: + self._included_files.append(os.path.join(r, file)) self._logger.trace(__name__, f'Stopped {__name__}._read_source_path') @@ -109,7 +132,7 @@ class Publisher(PublisherBase): def _write_templates(self): self._logger.trace(__name__, f'Started {__name__}._write_templates') for template in self._publish_settings.templates: - for file in self._publish_settings.included_files: + for file in self._included_files: if os.path.basename(file) == '__init__.py' and file not in self._publish_settings.excluded_files: template_name = template.name if template.name == 'all' or template.name == '': @@ -167,7 +190,7 @@ class Publisher(PublisherBase): if self._publish_settings.dist_path.endswith('/'): dist_path = dist_path[:len(dist_path) - 1] - for file in self._publish_settings.included_files: + for file in self._included_files: is_file_excluded = False if file in self._publish_settings.excluded_files: is_file_excluded = True