Added publish command to cli

This commit is contained in:
Sven Heidemann 2020-12-16 18:14:11 +01:00
parent 09eb3a41d6
commit a6122536a6
7 changed files with 116 additions and 5 deletions

View File

@ -1,10 +1,10 @@
import sys
import traceback
from typing import Optional
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.publish.publish import Publish
from sh_edraft.cli.cpl_cli.commands.version import Version
from sh_edraft.cli.interpreter.interpreter import Interpreter
from sh_edraft.console.console import Console
@ -19,6 +19,7 @@ class CLI:
self._interpreter.add_command(Build())
self._interpreter.add_command(Help())
self._interpreter.add_command(New())
self._interpreter.add_command(Publish())
self._interpreter.add_command(Version())
def main(self):

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
sh_edraft.cli.cpl_cli.commands.publish
~~~~~~~~~~~~~~~~~~~
:copyright: (c) 2020 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'sh_edraft.cli.cpl_cli.commands.publish'
__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)

View File

@ -0,0 +1,48 @@
from typing import Optional
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
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.base.service_provider_base import ServiceProviderBase
class PublishApp(ApplicationBase):
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._publisher: Optional[PublisherBase] = None
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'build.json')
def create_services(self):
# Add and create logger
self._services.add_singleton(LoggerBase, Logger)
self._logger = self._services.get_service(LoggerBase)
# Add and create publisher
self._services.add_singleton(PublisherBase, Publisher)
self._publisher: Publisher = self._services.get_service(PublisherBase)
def main(self):
self._logger.header(f'{self._configuration.environment.application_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'Customer: {self._configuration.environment.customer}')
self._publisher.create()
self._publisher.build()
self._publisher.publish()

View File

@ -0,0 +1,23 @@
from sh_edraft.cli.command.base.command_base import CommandBase
from sh_edraft.cli.cpl_cli.commands.publish.app import PublishApp
from sh_edraft.console.console import Console
class Publish(CommandBase):
def __init__(self):
CommandBase.__init__(self)
self._app = PublishApp()
self._aliases.append('-b')
self._aliases.append('-B')
def run(self, args: list[str]):
if len(args) > 0:
Console.error(f'Invalid arguments {args}')
Console.error('Run \'cpl help\'')
self._app.create_application_host()
self._app.create_configuration()
self._app.create_services()
self._app.main()

View File

@ -24,4 +24,7 @@ class PublisherBase(ServiceBase):
def exclude(self, path: str): pass
@abstractmethod
def publish(self) -> str: pass
def build(self): pass
@abstractmethod
def publish(self): pass

View File

@ -2,6 +2,8 @@ import os
import shutil
from string import Template as stringTemplate
from setuptools import sandbox
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publishing.base.publisher_base import PublisherBase
from sh_edraft.publishing.model.publish_settings_model import PublishSettings
@ -255,8 +257,17 @@ class Publisher(PublisherBase):
self._create_dist_path()
self._logger.trace(__name__, f'Stopped {__name__}.create')
def publish(self):
self._logger.trace(__name__, f'Started {__name__}.publish')
def build(self):
self._logger.trace(__name__, f'Started {__name__}.build')
self._write_templates()
self._copy_all_included_files()
self._logger.trace(__name__, f'Stopped {__name__}.build')
def publish(self):
self._logger.trace(__name__, f'Started {__name__}.publish')
setup_py = os.path.join(self._publish_settings.dist_path, 'setup.py')
if not os.path.isfile(setup_py):
self._logger.fatal(__name__, f'setup.py not found in {self._publish_settings.dist_path}')
sandbox.run_setup(os.path.abspath(setup_py), ['sdist', 'bdist_wheel'])
self._logger.trace(__name__, f'Stopped {__name__}.publish')

View File

@ -54,7 +54,7 @@ class Program(ApplicationBase):
self._publisher.include('../../README.MD')
self._publisher.include('../../requirements.txt')
self._publisher.create()
self._publisher.publish()
self._publisher.build()
if __name__ == '__main__':