Added menus

This commit is contained in:
Sven Heidemann 2021-11-23 09:25:51 +01:00
parent 673554dd6d
commit 5ddc2dc72d
11 changed files with 122 additions and 3 deletions

5
src/multi_install.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
# -*- coding: utf-8 -*-
export PYTHONPATH=./:$PYTHONPATH
python3.9 multi_install_cli/main.py

View File

@ -1 +1 @@
# imports: # imports

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,19 @@
from abc import ABC, abstractmethod
class MenuServiceABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def run(self): pass
@abstractmethod
def select_os(self) -> str: pass
@abstractmethod
def main_menu(self) -> str: pass
@abstractmethod
def select_collection(self) -> str: pass

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,24 @@
import traceback
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console
class OSSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._operating_systems = []
@property
def operating_systems(self) -> list[str]:
return self._operating_systems
def from_dict(self, settings: dict):
try:
for os in settings['OperatingSystems']:
self._operating_systems.append(os)
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 @@
# imports

View File

@ -0,0 +1,47 @@
from cpl_core.console import Console
from multi_install.abc.menu_service_abc import MenuServiceABC
from multi_install.config.os_settings import OSSettings
class MenuService(MenuServiceABC):
def __init__(self, os_settings: OSSettings):
self._os_settings = os_settings
self._is_running = True
def run(self):
while self._is_running:
os = self.select_os()
if os == 'Exit':
self._is_running = False
break
main_menu = self.main_menu()
if main_menu == 'Exit':
self._is_running = False
break
def select_os(self) -> str:
options = self._os_settings.operating_systems
options.append('Exit')
return Console.select('>', 'Select OS:', options)
def main_menu(self) -> str:
options = [
'Install collection',
'Add collection',
'Remove collection',
'Install application',
'Add application',
'Remove application',
'Add application'
]
options.append('Exit')
return Console.select('>', 'Select option:', options)
def select_collection(self) -> str:
options = []
options.append('Exit')
return Console.select('>', 'Select collection:', options)

View File

@ -3,14 +3,18 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from multi_install.abc.menu_service_abc import MenuServiceABC
class Application(ApplicationABC): class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
self._menu_service: MenuServiceABC = services.get_service(MenuServiceABC)
def configure(self): def configure(self):
pass pass
def main(self): def main(self):
Console.write_line('Hello World') self._menu_service.run()

View File

@ -11,5 +11,12 @@
"Filename": "log_$start_time.log", "Filename": "log_$start_time.log",
"ConsoleLogLevel": "ERROR", "ConsoleLogLevel": "ERROR",
"FileLogLevel": "WARN" "FileLogLevel": "WARN"
},
"OS": {
"OperatingSystems": [
"Fedora",
"Ubuntu"
]
} }
} }

View File

@ -1,7 +1,11 @@
import os
from cpl_core.application import StartupABC from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironment from cpl_core.environment import ApplicationEnvironment
from multi_install.abc.menu_service_abc import MenuServiceABC
from multi_install.service.menu_service import MenuService
class Startup(StartupABC): class Startup(StartupABC):
@ -10,7 +14,13 @@ class Startup(StartupABC):
StartupABC.__init__(self) StartupABC.__init__(self)
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
environment.set_working_directory(os.path.dirname(__file__))
configuration.add_json_file('appsettings.json')
return configuration return configuration
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
services.add_singleton(MenuServiceABC, MenuService)
return services.build_service_provider() return services.build_service_provider()