Added application and collection service
This commit is contained in:
		
							
								
								
									
										7
									
								
								src/multi_install/abc/application_service_abc.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/multi_install/abc/application_service_abc.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | from abc import ABC, abstractmethod | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class ApplicationServiceABC(ABC): | ||||||
|  |  | ||||||
|  |     @abstractmethod | ||||||
|  |     def __init__(self): pass | ||||||
							
								
								
									
										7
									
								
								src/multi_install/abc/collection_service_abc.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/multi_install/abc/collection_service_abc.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | from abc import ABC, abstractmethod | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class CollectionServiceABC(ABC): | ||||||
|  |  | ||||||
|  |     @abstractmethod | ||||||
|  |     def __init__(self): pass | ||||||
							
								
								
									
										1
									
								
								src/multi_install/model/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/multi_install/model/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | # imports | ||||||
							
								
								
									
										4
									
								
								src/multi_install/service/application_service.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/multi_install/service/application_service.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | class ApplicationService: | ||||||
|  |  | ||||||
|  |     def __init__(self): | ||||||
|  |         pass | ||||||
							
								
								
									
										4
									
								
								src/multi_install/service/collection_service.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/multi_install/service/collection_service.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | class CollectionService: | ||||||
|  |  | ||||||
|  |     def __init__(self): | ||||||
|  |         pass | ||||||
| @@ -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': |             if is_end: | ||||||
|                 is_end = True |                 Console.write_line() | ||||||
|          |          | ||||||
|             elif main_menu == 'Back': |     def select_os(self) -> bool: | ||||||
|                 break |  | ||||||
|          |  | ||||||
|     def select_os(self): |  | ||||||
|         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 | ||||||
|  |         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 | ||||||
|          |          | ||||||
|     def select_collection(self) -> str:  |         # application menu | ||||||
|         options = [] |         elif selected == options.index(MainMenuEnum.install_application.value): pass | ||||||
|         options.append('Exit') |         elif selected == options.index(MainMenuEnum.uninstall_application.value): pass | ||||||
|         return Console.select('>', 'Select collection:', options) |         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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user