forked from sh-edraft.de/sh_linux_installation_scripts
Added menus
This commit is contained in:
parent
673554dd6d
commit
5ddc2dc72d
5
src/multi_install.sh
Executable file
5
src/multi_install.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
# -*- coding: utf-8 -*-
|
||||
export PYTHONPATH=./:$PYTHONPATH
|
||||
|
||||
python3.9 multi_install_cli/main.py
|
@ -1 +1 @@
|
||||
# imports:
|
||||
# imports
|
||||
|
1
src/multi_install/abc/__init__.py
Normal file
1
src/multi_install/abc/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
19
src/multi_install/abc/menu_service_abc.py
Normal file
19
src/multi_install/abc/menu_service_abc.py
Normal 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
|
1
src/multi_install/config/__init__.py
Normal file
1
src/multi_install/config/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
24
src/multi_install/config/os_settings.py
Normal file
24
src/multi_install/config/os_settings.py
Normal 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()}')
|
1
src/multi_install/service/__init__.py
Normal file
1
src/multi_install/service/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
47
src/multi_install/service/menu_service.py
Normal file
47
src/multi_install/service/menu_service.py
Normal 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)
|
@ -3,14 +3,18 @@ from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
from multi_install.abc.menu_service_abc import MenuServiceABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
self._menu_service: MenuServiceABC = services.get_service(MenuServiceABC)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World')
|
||||
self._menu_service.run()
|
@ -11,5 +11,12 @@
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "ERROR",
|
||||
"FileLogLevel": "WARN"
|
||||
},
|
||||
|
||||
"OS": {
|
||||
"OperatingSystems": [
|
||||
"Fedora",
|
||||
"Ubuntu"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
import os
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
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):
|
||||
@ -10,7 +14,13 @@ class Startup(StartupABC):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
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
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
services.add_singleton(MenuServiceABC, MenuService)
|
||||
|
||||
return services.build_service_provider()
|
||||
|
Reference in New Issue
Block a user