Added application and collection service

This commit is contained in:
Sven Heidemann 2021-11-23 12:27:16 +01:00
parent c2fc611f94
commit e017462416
6 changed files with 80 additions and 34 deletions

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class ApplicationServiceABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class CollectionServiceABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,4 @@
class ApplicationService:
def __init__(self):
pass

View File

@ -0,0 +1,4 @@
class CollectionService:
def __init__(self):
pass

View File

@ -4,6 +4,7 @@ from cpl_core.console import Console
from cpl_query.extension import List from cpl_query.extension import List
from multi_install.abc.menu_service_abc import MenuServiceABC from multi_install.abc.menu_service_abc import MenuServiceABC
from multi_install.config.os_settings import OSSettings from multi_install.config.os_settings import OSSettings
from multi_install.model.main_menu_enum import MainMenuEnum
class MenuService(MenuServiceABC): class MenuService(MenuServiceABC):
@ -16,53 +17,75 @@ class MenuService(MenuServiceABC):
def run(self): def run(self):
is_end = False is_end = False
while not is_end: while not is_end:
self.select_os() is_end = self.select_os()
main_menu = self.main_menu() if not is_end:
is_end = self.main_menu()
if main_menu == 'Exit':
is_end = True
elif main_menu == 'Back': if is_end:
break Console.write_line()
def select_os(self): def select_os(self) -> bool:
Console.clear() Console.clear()
options = List(str, self._os_settings.operating_systems.copy()) options = List(str, self._os_settings.operating_systems.copy())
options.append('Exit') options.append('Exit')
Console.write_line('Select option:') Console.write_line('Select option:')
options.for_each(lambda o: Console.write_line(f'[{options.index(o)}] {o}')) options.for_each(lambda o: Console.write_line(f'[{options.index(o)+1}] {o}'))
os = int(Console.read('\n:')) os = 0
try:
os = int(Console.read('\n:'))-1
except ValueError:
Console.error('Input value must be int!')
return True
if os == options.index('Exit'): if os == options.index('Exit'):
exit() return True
self._os = os self._os = os
return False
def main_menu(self) -> str:
def main_menu(self) -> bool:
Console.clear() Console.clear()
options = List(str, [ options = List(str, [
'Install collection', MainMenuEnum.install_collection.value,
'Uninstall collection', MainMenuEnum.uninstall_collection.value,
'Add collection', MainMenuEnum.add_collection.value,
'Remove collection', MainMenuEnum.remove_collection.value,
'Install application', MainMenuEnum.install_application.value,
'Uninstall application', MainMenuEnum.uninstall_application.value,
'Add application', MainMenuEnum.add_application.value,
'Remove application', MainMenuEnum.remove_application.value,
'Add application',
'Back', MainMenuEnum.back.value,
'Exit' MainMenuEnum.exit.value
]) ])
Console.write_line('Select option:') Console.write_line('Select option:')
options.for_each(lambda o: Console.write_line(f'[{options.index(o)}] {o}')) options.for_each(lambda o: Console.write_line(f'[{options.index(o)+1}] {o}'))
selected = int(Console.read('\n:')) selected = 0
if selected == options.index('Exit'): try:
exit() selected = int(Console.read('\n:'))-1
except ValueError:
Console.error('Input value must be int!')
return True
return selected # collection menu
if selected == options.index(MainMenuEnum.install_collection.value): pass
def select_collection(self) -> str: elif selected == options.index(MainMenuEnum.uninstall_collection.value): pass
options = [] elif selected == options.index(MainMenuEnum.add_collection.value): pass
options.append('Exit') elif selected == options.index(MainMenuEnum.remove_collection.value): pass
return Console.select('>', 'Select collection:', options)
# application menu
elif selected == options.index(MainMenuEnum.install_application.value): pass
elif selected == options.index(MainMenuEnum.uninstall_application.value): pass
elif selected == options.index(MainMenuEnum.add_application.value): pass
elif selected == options.index(MainMenuEnum.remove_application.value): pass
elif selected == options.index(MainMenuEnum.back.value):
return
elif selected == options.index(MainMenuEnum.exit.value):
return True
else:
raise Exception(f'Unknown option: {selected}')
return False