Compare commits

...

5 Commits

Author SHA1 Message Date
359d333add Improved menu & config 2021-11-23 14:07:32 +01:00
51c852a839 Renamed ApplicationMenuService 2021-11-23 12:36:28 +01:00
e4c585d4c5 Added ABCs 2021-11-23 12:34:03 +01:00
e017462416 Added application and collection service 2021-11-23 12:27:16 +01:00
c2fc611f94 Improved menu handling 2021-11-23 12:27:01 +01:00
11 changed files with 303 additions and 39 deletions

View File

@@ -0,0 +1,19 @@
from abc import ABC, abstractmethod
class ApplicationMenuServiceABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def install_application(self): pass
@abstractmethod
def uninstall_application(self): pass
@abstractmethod
def add_application(self): pass
@abstractmethod
def remove_application(self): pass

View File

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

View File

@@ -10,10 +10,7 @@ class MenuServiceABC(ABC):
def run(self): pass
@abstractmethod
def select_os(self) -> str: pass
def select_os(self) -> bool: pass
@abstractmethod
def main_menu(self) -> str: pass
@abstractmethod
def select_collection(self) -> str: pass
def main_menu(self) -> bool: pass

View File

@@ -0,0 +1,39 @@
import traceback
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console
from multi_install.config.application_settings import ApplicationSettings
class ApplicationListSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._debian_apps = []
self._red_hat_apps = []
@property
def debian_apps(self) -> str:
return self._debian_apps
@property
def redhat_apps(self) -> str:
return self._debian_apps
def from_dict(self, settings: dict):
try:
for app_cfg in settings['Debian']:
app = ApplicationSettings()
app.from_dict(app_cfg)
self._debian_apps.append(app)
for app_cfg in settings['RedHat']:
app = ApplicationSettings()
app.from_dict(app_cfg)
self._red_hat_apps.append(app)
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,36 @@
import traceback
from typing import Optional
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console
class ApplicationSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._name = ''
self._repository = ''
self._source_url = ''
@property
def name(self) -> str:
return self._name
@property
def repository(self) -> str:
return self._repository
@property
def source_url(self) -> Optional[str]:
return self._source_url(self)
def from_dict(self, settings: dict):
try:
self._name = settings['Name']
self._repository = settings['Repository'] if 'Repository' in settings else None
self._source_url = settings['SourceUrl'] if 'SourceUrl' in settings else None
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,19 @@
from enum import Enum
class MainMenuEnum(Enum):
list_collection = 'List collection'
install_collection = 'Install collection'
uninstall_collection = 'Uninstall collection'
add_collection = 'Add collection'
remove_collection = 'Remove collection'
list_application = 'List application'
install_application = 'Install application'
uninstall_application = 'Uninstall application'
add_application = 'Add application'
remove_application = 'Remove application'
back = 'Back'
exit = 'Exit'

View File

@@ -0,0 +1,16 @@
from multi_install.abc.application_menu_service_abc import ApplicationMenuServiceABC
from multi_install.config.application_list_settings import ApplicationListSettings
class ApplicationMenuService(ApplicationMenuServiceABC):
def __init__(self, application_settings: ApplicationListSettings):
pass
def install_application(self): pass
def uninstall_application(self): pass
def add_application(self): pass
def remove_application(self): pass

View File

@@ -0,0 +1,7 @@
from multi_install.abc.collection_service_abc import CollectionServiceABC
class CollectionService(CollectionServiceABC):
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,77 @@ 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.list_collection.value): pass
elif 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.list_application.value): pass
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

View File

@@ -0,0 +1,98 @@
{
"Application": {
"RedHat": [],
"Debian": [
{
"Name": "brave-browser",
"Deps": [
{
"Name": "apt-transport-https"
},
{
"Name": "curl"
}
]
},
{
"Name": "barrier"
},
{
"Name": "gnome-boxes"
},
{
"Name": "google-chrome",
"SourceUrl": "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
},
{
"Name": "chrome-gnome-shell"
},
{
"Name": "discord",
"SourceUrl": "https://discordapp.com/api/download?platform=linux&format=deb"
},
{
"Name:": "balena-etcher-electron"
},
{
"Name": "flameshot"
},
{
"Name": "geary"
},
{
"Name": "git"
},
{
"Name": "gnome-tweaks"
},
{
"Name": "gpick"
},
{
"Name": "kcolorchooser"
},
{
"Name": "keepassxc"
},
{
"Name": "lsd",
"SourceUrl": "https://github.com/Peltoche/lsd/releases/download/0.19.0/lsd_0.19.0_amd64.deb"
},
{
"Name": "ncdu"
},
{
"Name": "neofetch"
},
{
"Name": "nextcloud-client",
"Repository": "ppa:nextcloud-devs/client"
},
{
"Name": "signal-desktop"
},
{
"Name": "stacer"
},
{
"Name": "sublime-text",
"Repository": "deb https://download.sublimetext.com/ apt/stable/"
},
{
"Name": "timeshift",
"Repository": "ppa:teejee2008/ppa"
},
{
"Name": "trash-cli"
},
{
"Name": "ulauncher",
"Repository": "ppa:agornostal/ulauncher"
},
{
"Name": "code",
"Repository": "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
}
]
}
}