2022.6 #88
@ -26,7 +26,9 @@ class CustomScriptService(CommandABC):
|
|||||||
cmd = self._config.get_configuration('ACTIVE_EXECUTABLE')
|
cmd = self._config.get_configuration('ACTIVE_EXECUTABLE')
|
||||||
|
|
||||||
for script in self._workspace.scripts:
|
for script in self._workspace.scripts:
|
||||||
if script == cmd:
|
if script != cmd:
|
||||||
|
continue
|
||||||
|
|
||||||
command = self._workspace.scripts[script]
|
command = self._workspace.scripts[script]
|
||||||
try:
|
try:
|
||||||
subprocess.run(command, shell=True if os.name == 'posix' else None)
|
subprocess.run(command, shell=True if os.name == 'posix' else None)
|
||||||
|
@ -5,6 +5,8 @@ import traceback
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from typing import Union, Type, Optional
|
from typing import Union, Type, Optional
|
||||||
|
|
||||||
|
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||||
|
from cpl_cli.configuration import WorkspaceSettings
|
||||||
from cpl_core.configuration.argument_abc import ArgumentABC
|
from cpl_core.configuration.argument_abc import ArgumentABC
|
||||||
from cpl_core.configuration.argument_builder import ArgumentBuilder
|
from cpl_core.configuration.argument_builder import ArgumentBuilder
|
||||||
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
|
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
|
||||||
@ -154,6 +156,28 @@ class Configuration(ConfigurationABC):
|
|||||||
self._print_error(__name__, f'Cannot load config file: {file}! -> {e}')
|
self._print_error(__name__, f'Cannot load config file: {file}! -> {e}')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def _handle_pre_or_post_executables(self, pre: bool, argument: ExecutableArgument, services: ServiceProviderABC):
|
||||||
|
script_type = 'pre-' if pre else 'post-'
|
||||||
|
workspace: Optional[WorkspaceSettings] = self.get_configuration(WorkspaceSettings)
|
||||||
|
if workspace is None or len(workspace.scripts) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
for script in workspace.scripts:
|
||||||
|
if script_type not in script and not script.startswith(script_type):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# split in two ifs to prevent exception
|
||||||
|
if script.split(script_type)[1] != argument.name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
css: CustomScriptService = services.get_service(CustomScriptService)
|
||||||
|
if css is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
Console.write_line()
|
||||||
|
self.add_configuration('ACTIVE_EXECUTABLE', script)
|
||||||
|
css.run([])
|
||||||
|
|
||||||
def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]):
|
def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]):
|
||||||
for i in range(0, len(arg_list)):
|
for i in range(0, len(arg_list)):
|
||||||
arg_str = arg_list[i]
|
arg_str = arg_list[i]
|
||||||
@ -308,8 +332,10 @@ class Configuration(ConfigurationABC):
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
|
cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
|
||||||
|
self._handle_pre_or_post_executables(True, exe, services)
|
||||||
self.add_configuration('ACTIVE_EXECUTABLE', exe.name)
|
self.add_configuration('ACTIVE_EXECUTABLE', exe.name)
|
||||||
cmd.execute(self._additional_arguments)
|
cmd.execute(self._additional_arguments)
|
||||||
|
self._handle_pre_or_post_executables(False, exe, services)
|
||||||
prevent = exe.prevent_next_executable
|
prevent = exe.prevent_next_executable
|
||||||
success = True
|
success = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user