Improved command handling

This commit is contained in:
2021-03-04 19:06:53 +01:00
parent 2c43e55f77
commit 700bf9c937
17 changed files with 197 additions and 19 deletions

View File

View File

@@ -0,0 +1,46 @@
import traceback
from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
from cpl.console.foreground_color import ForegroundColor
from cpl.version.version import Version
from cpl_cli.publish.project_settings_name import ProjectSettingsName
class ProjectSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._dist_path: Optional[str] = None
self._excluded_files: list[str] = []
self._version: Optional[Version] = None
@property
def excluded_files(self) -> list[str]:
return self._excluded_files
@property
def dist_path(self) -> str:
return self._dist_path
@dist_path.setter
def dist_path(self, dist_path: str):
self._dist_path = dist_path
@property
def version(self) -> Version:
return self._version
def from_dict(self, settings: dict):
try:
self._dist_path = settings[ProjectSettingsName.dist_path.value]
self._excluded_files = settings[ProjectSettingsName.excluded_files.value]
self._version = settings[ProjectSettingsName.version.value]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.write_line(
f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettingsName.project.value} settings')
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
Console.set_foreground_color(ForegroundColor.default)

View File

@@ -0,0 +1,9 @@
from enum import Enum
class ProjectSettingsName(Enum):
dist_path = 'DistPath'
excluded_files = 'ExcludedFiles'
version = 'Version'
project = 'Project'

View File

@@ -0,0 +1,65 @@
import os
import shutil
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.console.console import Console
from cpl_cli.publish.project_settings import ProjectSettings
from cpl_cli.publish.publisher_abc import PublisherABC
class Publisher(PublisherABC):
def __init__(self, runtime: ApplicationRuntimeABC, project: ProjectSettings):
PublisherABC.__init__(self)
self._runtime = runtime
self._project = project
@property
def source_path(self) -> str:
return ''
@property
def dist_path(self) -> str:
return ''
def _create_dist_path(self):
self._project.dist_path = os.path.join(self._runtime.working_directory, self._project.dist_path)
Console.write_line('DIST:', self._project.dist_path)
if os.path.isdir(self._project.dist_path):
try:
shutil.rmtree(self._project.dist_path)
except Exception as e:
Console.error(f'{e}')
exit()
if not os.path.isdir(self._project.dist_path):
try:
os.makedirs(self._project.dist_path)
except Exception as e:
Console.error(f'{e}')
exit()
def _create_packages(self):
pass
def _dist_files(self):
pass
def include(self, path: str):
pass
def exclude(self, path: str):
pass
def build(self):
Console.write_line('Creating internal packages:')
self._create_packages()
Console.write_line('Building application:')
self._dist_files()
def publish(self):
pass

View File

@@ -0,0 +1,30 @@
from abc import abstractmethod
from cpl.dependency_injection.service_abc import ServiceABC
class PublisherABC(ServiceABC):
@abstractmethod
def __init__(self):
ServiceABC.__init__(self)
@property
@abstractmethod
def source_path(self) -> str: pass
@property
@abstractmethod
def dist_path(self) -> str: pass
@abstractmethod
def include(self, path: str): pass
@abstractmethod
def exclude(self, path: str): pass
@abstractmethod
def build(self): pass
@abstractmethod
def publish(self): pass