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