2021.4.6 #25

Merged
edraft merged 57 commits from 2021.4.6 into 2021.4.post1 2021-04-11 15:54:38 +02:00
7 changed files with 200 additions and 5 deletions
Showing only changes of commit 6a5c832288 - Show all commits

9
cpl-workspace.json Normal file
View File

@ -0,0 +1,9 @@
{
"Workspace": {
"DefaultProject": "cpl_cli",
"Projects": {
"cpl": "src/cpl/cpl.json",
"cpl_cli": "src/cpl_cli/cpl_cli.json"
}
}
}

57
src/cpl/cpl.json Normal file
View File

@ -0,0 +1,57 @@
{
"ProjectSettings": {
"Name": "sh_cpl",
"Version": {
"Major": "2021",
"Minor": "4",
"Micro": "post1"
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",
"Description": "sh-edraft Common Python library",
"LongDescription": "sh-edraft Common Python library",
"URL": "https://www.sh-edraft.de",
"CopyrightDate": "2020 - 2021",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"colorama==0.4.4",
"mysql-connector==2.2.9",
"psutil==5.8.0",
"packaging==20.9",
"pyfiglet==0.8.post1",
"pynput==1.7.3",
"SQLAlchemy==1.4.3",
"setuptools==54.2.0",
"tabulate==0.8.9",
"termcolor==1.1.0",
"watchdog==2.0.2",
"wheel==0.36.2"
],
"PythonVersion": ">=3.8",
"PythonPath": {},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "library",
"SourcePath": "",
"OutputPath": "dist",
"Main": "",
"EntryPoint": "cpl",
"IncludePackageData": true,
"Included": [
"*/templates"
],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {
"cpl_cli": [
"*.json"
]
}
}
}

View File

@ -1,9 +1,11 @@
import os import os
import sys
from abc import ABC from abc import ABC
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console from cpl.console.console import Console
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.error import Error from cpl_cli.error import Error
from cpl_cli.command_model import CommandModel from cpl_cli.command_model import CommandModel
@ -28,6 +30,9 @@ class CommandHandler(ABC):
def commands(self) -> list[CommandModel]: def commands(self) -> list[CommandModel]:
return self._commands return self._commands
def _load_json(self):
pass
def add_command(self, cmd: CommandModel): def add_command(self, cmd: CommandModel):
self._commands.append(cmd) self._commands.append(cmd)
@ -43,12 +48,48 @@ class CommandHandler(ABC):
""" """
for command in self._commands: for command in self._commands:
if cmd == command.name or cmd in command.aliases: if cmd == command.name or cmd in command.aliases:
if command.is_project_needed and not os.path.isfile(os.path.join(self._env.working_directory, 'cpl.json')): if command.is_project_needed and \
Error.error('The command requires to be run in an CPL project, but a project could not be found.') not os.path.isfile(os.path.join(self._env.working_directory, 'cpl-workspace.json')):
Error.error(
'The command requires to be run in an CPL workspace, but a workspace could not be found.'
)
return return
if command.is_project_needed: if command.is_project_needed:
self._config.add_json_file('cpl.json', optional=True, output=False) self._config.add_json_file('cpl-workspace.json', optional=True, output=False)
workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
if workspace is None:
Error.error(
'The command requires to be run in an CPL workspace, but a workspace could not be found.'
)
return
project_name = workspace.default_project
if len(args) > 0:
project_name = args[0]
index = sys.argv.index(args[0]) + 1
if index < len(sys.argv):
args = sys.argv[index:]
if project_name not in workspace.projects:
Error.error(
f'Project {project_name} not found.'
)
return
project_json = workspace.projects[project_name]
if not os.path.isfile(os.path.join(self._env.working_directory, project_json)):
Error.error(
'The command requires to be run in an CPL project, but a project could not be found.'
)
return
self._config.add_json_file(project_json, optional=True, output=False)
self._config.environment.set_working_directory(
os.path.join(self._env.working_directory, os.path.dirname(project_json))
)
self._services.get_service(command.command).run(args) self._services.get_service(command.command).run(args)
Console.write('\n') Console.write('\n')

View File

@ -0,0 +1,31 @@
import traceback
from typing import Optional
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console import Console
from cpl_cli.configuration.workspace_settings_name_enum import WorkspaceSettingsNameEnum
class WorkspaceSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._default_project: Optional[str] = None
self._projects: dict[str, str] = {}
@property
def default_project(self) -> str:
return self._default_project
@property
def projects(self) -> dict[str, str]:
return self._projects
def from_dict(self, settings: dict):
try:
self._default_project = settings[WorkspaceSettingsNameEnum.default_project.value]
self._projects = settings[WorkspaceSettingsNameEnum.projects.value]
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')

View File

@ -0,0 +1,7 @@
from enum import Enum
class WorkspaceSettingsNameEnum(Enum):
default_project = 'DefaultProject'
projects = 'Projects'

46
src/cpl_cli/cpl_cli.json Normal file
View File

@ -0,0 +1,46 @@
{
"ProjectSettings": {
"Name": "sh_cpl-cli",
"Version": {
"Major": "2021",
"Minor": "4",
"Micro": ""
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",
"Description": "sh-edraft Common Python library CLI",
"LongDescription": "sh-edraft Common Python library Command Line Interface",
"URL": "https://www.sh-edraft.de",
"CopyrightDate": "2020 - 2021",
"CopyrightName": "sh-edraft.de",
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"sh_cpl==2021.4.0"
],
"PythonVersion": ">=3.8",
"PythonPath": {},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "console",
"SourcePath": "",
"OutputPath": "dist",
"Main": "main",
"EntryPoint": "cpl",
"IncludePackageData": true,
"Included": [
"*/templates"
],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {
"cpl_cli": [
"*.json"
]
}
}
}

View File

@ -1,3 +1,5 @@
import os
from cpl.application.startup_abc import StartupABC from cpl.application.startup_abc import StartupABC
from cpl.configuration.console_argument import ConsoleArgument from cpl.configuration.console_argument import ConsoleArgument
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
@ -29,7 +31,7 @@ class Startup(StartupABC):
self._env = self._configuration.environment self._env = self._configuration.environment
self._services = services self._services = services
self._env.set_runtime_directory(__file__) self._env.set_runtime_directory(os.path.dirname(__file__))
def configure_configuration(self) -> ConfigurationABC: def configure_configuration(self) -> ConfigurationABC:
self._configuration.argument_error_function = Error.error self._configuration.argument_error_function = Error.error
@ -56,7 +58,9 @@ class Startup(StartupABC):
ConsoleArgument('', 'library', ['l', 'L'], ' ') ConsoleArgument('', 'library', ['l', 'L'], ' ')
])) ]))
self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'start', ['s', 'S'], '')) self._configuration.add_console_argument(
ConsoleArgument('', 'start', ['s', 'S'], ' ', is_value_token_optional=True)
)
self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' ')) self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))