mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 01:44:15 +02:00
[api] improvement: allowing several settings views to be returned (SoftwareManager.get_settings)
This commit is contained in:
@@ -12,17 +12,17 @@ from pathlib import Path
|
||||
from typing import Set, Type, List, Tuple, Optional, Iterable, Generator
|
||||
|
||||
from colorama import Fore
|
||||
from packaging.version import parse as parse_version
|
||||
from packaging.version import LegacyVersion
|
||||
from packaging.version import parse as parse_version
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, UpgradeRequirements, UpgradeRequirement, \
|
||||
TransactionResult, SoftwareAction
|
||||
TransactionResult, SoftwareAction, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \
|
||||
SuggestionPriority, CustomSoftwareAction
|
||||
from bauh.api.abstract.view import MessageType, ViewComponent, FormComponent, InputOption, SingleSelectComponent, \
|
||||
from bauh.api.abstract.view import MessageType, FormComponent, InputOption, SingleSelectComponent, \
|
||||
SelectViewType, TextInputComponent, PanelComponent, FileChooserComponent, ViewObserver
|
||||
from bauh.api.paths import DESKTOP_ENTRIES_DIR
|
||||
from bauh.commons import resource
|
||||
@@ -67,7 +67,7 @@ class ManualInstallationFileObserver(ViewObserver):
|
||||
self.version.set_value(None)
|
||||
|
||||
|
||||
class AppImageManager(SoftwareManager):
|
||||
class AppImageManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext):
|
||||
super(AppImageManager, self).__init__(context=context)
|
||||
@@ -850,7 +850,7 @@ class AppImageManager(SoftwareManager):
|
||||
print(f'{Fore.RED}[bauh][appimage] An exception has happened when deleting {f}{Fore.RESET}')
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
appimage_config = self.configman.get_config()
|
||||
max_width = floor(self.context.screen_width * 0.15)
|
||||
|
||||
@@ -871,12 +871,12 @@ class AppImageManager(SoftwareManager):
|
||||
id_='appim_sugs_exp')
|
||||
]
|
||||
|
||||
return PanelComponent([FormComponent(components=comps, id_='form')])
|
||||
yield SettingsView(self, PanelComponent([FormComponent(components=comps)]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
appimage_config = self.configman.get_config()
|
||||
|
||||
form = component.get_form_component('form')
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
appimage_config['database']['expiration'] = form.get_text_input('appim_db_exp').get_int_value()
|
||||
appimage_config['suggestions']['expiration'] = form.get_text_input('appim_sugs_exp').get_int_value()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from dateutil.parser import parse as parse_date
|
||||
|
||||
from bauh import __app_name__
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult, SoftwareAction
|
||||
TransactionResult, SoftwareAction, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus, \
|
||||
@@ -194,7 +194,7 @@ class TransactionContext:
|
||||
self.previous_change_progress = self.change_progress
|
||||
|
||||
|
||||
class ArchManager(SoftwareManager):
|
||||
class ArchManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext, disk_cache_updater: Optional[ArchDiskCacheUpdater] = None):
|
||||
super(ArchManager, self).__init__(context=context)
|
||||
@@ -2860,7 +2860,7 @@ class ArchManager(SoftwareManager):
|
||||
id_=id_,
|
||||
capitalize_label=capitalize_label)
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
arch_config = self.configman.get_config()
|
||||
max_width = floor(self.context.screen_width * 0.25)
|
||||
|
||||
@@ -3013,33 +3013,46 @@ class ArchManager(SoftwareManager):
|
||||
value=arch_config['categories_exp'] if isinstance(arch_config['categories_exp'], int) else ''),
|
||||
]
|
||||
|
||||
return PanelComponent([FormComponent(fields, spaces=False, id_='root')])
|
||||
yield SettingsView(self, PanelComponent([FormComponent(fields, spaces=False)]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
form = component.get_form_component('root')
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
arch_config['repositories'] = form.get_single_select_component('repos').get_selected()
|
||||
arch_config['optimize'] = form.get_single_select_component('opts').get_selected()
|
||||
arch_config['aur_rebuild_detector'] = form.get_single_select_component('rebuild_detector').get_selected()
|
||||
arch_config['aur_rebuild_detector_no_bin'] = form.get_single_select_component('rebuild_detector_no_bin').get_selected()
|
||||
|
||||
rebuild_no_bin = form.get_single_select_component('rebuild_detector_no_bin').get_selected()
|
||||
arch_config['aur_rebuild_detector_no_bin'] = rebuild_no_bin
|
||||
|
||||
arch_config['sync_databases'] = form.get_single_select_component('sync_dbs').get_selected()
|
||||
arch_config['sync_databases_startup'] = form.get_single_select_component('sync_dbs_start').get_selected()
|
||||
arch_config['clean_cached'] = form.get_single_select_component('clean_cached').get_selected()
|
||||
arch_config['refresh_mirrors_startup'] = form.get_single_select_component('ref_mirs').get_selected()
|
||||
arch_config['mirrors_sort_limit'] = form.get_component('mirrors_sort_limit').get_int_value()
|
||||
arch_config['repositories_mthread_download'] = form.get_component('mthread_download').get_selected()
|
||||
arch_config['mirrors_sort_limit'] = form.get_text_input('mirrors_sort_limit').get_int_value()
|
||||
arch_config['repositories_mthread_download'] = form.get_single_select_component('mthread_download').get_selected()
|
||||
arch_config['automatch_providers'] = form.get_single_select_component('autoprovs').get_selected()
|
||||
arch_config['prefer_repository_provider'] = form.get_single_select_component('prefer_repo_provider').get_selected()
|
||||
|
||||
prefer_repo_provider = form.get_single_select_component('prefer_repo_provider').get_selected()
|
||||
arch_config['prefer_repository_provider'] = prefer_repo_provider
|
||||
|
||||
arch_config['edit_aur_pkgbuild'] = form.get_single_select_component('edit_aur_pkgbuild').get_selected()
|
||||
arch_config['aur_remove_build_dir'] = form.get_single_select_component('aur_remove_build_dir').get_selected()
|
||||
arch_config['aur_build_dir'] = form.get_component('aur_build_dir').file_path
|
||||
arch_config['aur_build_only_chosen'] = form.get_single_select_component('aur_build_only_chosen').get_selected()
|
||||
arch_config['aur_idx_exp'] = form.get_component('aur_idx_exp').get_int_value()
|
||||
arch_config['check_dependency_breakage'] = form.get_single_select_component('check_dependency_breakage').get_selected()
|
||||
arch_config['suggest_optdep_uninstall'] = form.get_single_select_component('suggest_optdep_uninstall').get_selected()
|
||||
arch_config['suggest_unneeded_uninstall'] = form.get_single_select_component('suggest_unneeded_uninstall').get_selected()
|
||||
arch_config['categories_exp'] = form.get_component('arch_cats_exp').get_int_value()
|
||||
arch_config['aur_idx_exp'] = form.get_text_input('aur_idx_exp').get_int_value()
|
||||
|
||||
check_dep_break = form.get_single_select_component('check_dependency_breakage').get_selected()
|
||||
arch_config['check_dependency_breakage'] = check_dep_break
|
||||
|
||||
sug_opt_dep_uni = form.get_single_select_component('suggest_optdep_uninstall').get_selected()
|
||||
arch_config['suggest_optdep_uninstall'] = sug_opt_dep_uni
|
||||
|
||||
sug_unneeded_uni = form.get_single_select_component('suggest_unneeded_uninstall').get_selected()
|
||||
arch_config['suggest_unneeded_uninstall'] = sug_unneeded_uni
|
||||
|
||||
arch_config['categories_exp'] = form.get_text_input('arch_cats_exp').get_int_value()
|
||||
|
||||
if not arch_config['aur_build_dir']:
|
||||
arch_config['aur_build_dir'] = None
|
||||
|
||||
@@ -10,12 +10,12 @@ from typing import List, Optional, Tuple, Set, Type, Dict, Iterable, Generator
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SoftwareAction, TransactionResult, UpgradeRequirements, \
|
||||
SearchResult, UpgradeRequirement
|
||||
SearchResult, UpgradeRequirement, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import TaskManager, ProcessWatcher
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageSuggestion, PackageUpdate, PackageHistory, \
|
||||
CustomSoftwareAction
|
||||
from bauh.api.abstract.view import ViewComponent, TextInputComponent, PanelComponent, FormComponent, MessageType, \
|
||||
from bauh.api.abstract.view import TextInputComponent, PanelComponent, FormComponent, MessageType, \
|
||||
SingleSelectComponent, InputOption, SelectViewType
|
||||
from bauh.api.paths import CONFIG_DIR
|
||||
from bauh.commons.html import bold
|
||||
@@ -33,7 +33,7 @@ from bauh.gems.debian.suggestions import DebianSuggestionsDownloader
|
||||
from bauh.gems.debian.tasks import UpdateApplicationIndex, MapApplications, SynchronizePackages
|
||||
|
||||
|
||||
class DebianPackageManager(SoftwareManager):
|
||||
class DebianPackageManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext):
|
||||
super(DebianPackageManager, self).__init__(context)
|
||||
@@ -568,7 +568,7 @@ class DebianPackageManager(SoftwareManager):
|
||||
final_cmd = pkg.app.exe_path.replace('%U', '')
|
||||
Popen(final_cmd, shell=True)
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
deb_config = self.configman.get_config()
|
||||
|
||||
comps_width = int(self.context.screen_width * 0.105)
|
||||
@@ -632,24 +632,23 @@ class DebianPackageManager(SoftwareManager):
|
||||
value=str(suggestions_exp), only_int=True,
|
||||
max_width=comps_width)
|
||||
|
||||
return PanelComponent([FormComponent([input_sources, ti_sync_pkgs, ti_index_apps_exp, ti_suggestions_exp])])
|
||||
panel = PanelComponent([FormComponent([input_sources, ti_sync_pkgs, ti_index_apps_exp, ti_suggestions_exp])])
|
||||
yield SettingsView(self, panel)
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
deb_config = self.configman.get_config()
|
||||
|
||||
container = component.components[0]
|
||||
container = component.get_component_by_idx(0, FormComponent)
|
||||
deb_config['pkg_sources.app'] = container.get_single_select_component('pkg_sources.app').get_selected()
|
||||
deb_config['index_apps.exp'] = container.get_text_input('index_apps.exp').get_int_value()
|
||||
deb_config['sync_pkgs.time'] = container.get_text_input('sync_pkgs.time').get_int_value()
|
||||
deb_config['suggestions.exp'] = container.get_text_input('suggestions.exp').get_int_value()
|
||||
|
||||
if isinstance(container, FormComponent):
|
||||
deb_config['pkg_sources.app'] = container.get_single_select_component('pkg_sources.app').get_selected()
|
||||
deb_config['index_apps.exp'] = container.get_text_input('index_apps.exp').get_int_value()
|
||||
deb_config['sync_pkgs.time'] = container.get_text_input('sync_pkgs.time').get_int_value()
|
||||
deb_config['suggestions.exp'] = container.get_text_input('suggestions.exp').get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(deb_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
try:
|
||||
self.configman.save_config(deb_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def gen_custom_actions(self) -> Generator[CustomSoftwareAction, None, None]:
|
||||
if self._default_actions is None:
|
||||
|
||||
@@ -11,13 +11,13 @@ from packaging.version import Version
|
||||
|
||||
from bauh.api import user
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
UpgradeRequirement, TransactionResult, SoftwareAction
|
||||
UpgradeRequirement, TransactionResult, SoftwareAction, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import PackageHistory, PackageUpdate, SoftwarePackage, PackageSuggestion, \
|
||||
SuggestionPriority, PackageStatus, CustomSoftwareAction
|
||||
from bauh.api.abstract.view import MessageType, FormComponent, SingleSelectComponent, InputOption, SelectViewType, \
|
||||
ViewComponent, PanelComponent
|
||||
PanelComponent
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import strip_html, bold
|
||||
from bauh.commons.system import ProcessHandler
|
||||
@@ -33,7 +33,7 @@ DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.000Z'
|
||||
RE_INSTALL_REFS = re.compile(r'\d+\)\s+(.+)')
|
||||
|
||||
|
||||
class FlatpakManager(SoftwareManager):
|
||||
class FlatpakManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext):
|
||||
super(FlatpakManager, self).__init__(context=context)
|
||||
@@ -603,7 +603,7 @@ class FlatpakManager(SoftwareManager):
|
||||
else:
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
if not self.context.root_user:
|
||||
fields = []
|
||||
|
||||
@@ -623,13 +623,15 @@ class FlatpakManager(SoftwareManager):
|
||||
default_option=[o for o in install_opts if o.value == flatpak_config['installation_level']][0],
|
||||
max_per_line=len(install_opts),
|
||||
max_width=floor(self.context.screen_width * 0.22),
|
||||
type_=SelectViewType.RADIO))
|
||||
type_=SelectViewType.RADIO,
|
||||
id_='install'))
|
||||
|
||||
return PanelComponent([FormComponent(fields, self.i18n['installation'].capitalize())])
|
||||
yield SettingsView(self, PanelComponent([FormComponent(fields, self.i18n['installation'].capitalize())]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
flatpak_config = self.configman.get_config()
|
||||
flatpak_config['installation_level'] = component.components[0].components[0].get_selected()
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
flatpak_config['installation_level'] = form.get_single_select_component('install').get_selected()
|
||||
|
||||
try:
|
||||
self.configman.save_config(flatpak_config)
|
||||
|
||||
@@ -5,7 +5,7 @@ from threading import Thread
|
||||
from typing import List, Set, Type, Optional, Tuple, Generator
|
||||
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult, SoftwareAction
|
||||
TransactionResult, SoftwareAction, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \
|
||||
@@ -27,7 +27,7 @@ from bauh.gems.snap.snapd import SnapdClient
|
||||
RE_AVAILABLE_CHANNELS = re.compile(re.compile(r'(\w+)\s+(snap install.+)'))
|
||||
|
||||
|
||||
class SnapManager(SoftwareManager):
|
||||
class SnapManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext):
|
||||
super(SnapManager, self).__init__(context=context)
|
||||
@@ -427,7 +427,7 @@ class SnapManager(SoftwareManager):
|
||||
if pkg.screenshots:
|
||||
yield from pkg.screenshots
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
snap_config = self.configman.get_config()
|
||||
max_width = 200
|
||||
|
||||
@@ -446,14 +446,15 @@ class SnapManager(SoftwareManager):
|
||||
label=self.i18n['snap.config.categories_exp'],
|
||||
tooltip=self.i18n['snap.config.categories_exp.tip'])
|
||||
|
||||
return PanelComponent([FormComponent([install_channel, categories_exp], self.i18n['installation'].capitalize())])
|
||||
panel = PanelComponent([FormComponent([install_channel, categories_exp], self.i18n['installation'].capitalize())])
|
||||
yield SettingsView(self, panel)
|
||||
|
||||
def save_settings(self, component: ViewComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
snap_config = self.configman.get_config()
|
||||
|
||||
panel = component.components[0]
|
||||
snap_config['install_channel'] = panel.get_component('snap_install_channel').get_selected()
|
||||
snap_config['categories_exp'] = panel.get_component('snap_cat_exp').get_int_value()
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
snap_config['install_channel'] = form.get_single_select_component('snap_install_channel').get_selected()
|
||||
snap_config['categories_exp'] = form.get_text_input('snap_cat_exp').get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(snap_config)
|
||||
|
||||
@@ -18,7 +18,7 @@ from requests import Response
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, UpgradeRequirements, TransactionResult, \
|
||||
SoftwareAction
|
||||
SoftwareAction, SettingsView, SettingsController
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import SoftwarePackage, CustomSoftwareAction, PackageSuggestion, PackageUpdate, \
|
||||
@@ -62,7 +62,7 @@ RE_SYMBOLS_SPLIT = re.compile(r'[\-|_\s:.]')
|
||||
DEFAULT_LANGUAGE_HEADER = 'en-US, en'
|
||||
|
||||
|
||||
class WebApplicationManager(SoftwareManager):
|
||||
class WebApplicationManager(SoftwareManager, SettingsController):
|
||||
|
||||
def __init__(self, context: ApplicationContext, suggestions_loader: Optional[SuggestionsLoader] = None):
|
||||
super(WebApplicationManager, self).__init__(context=context)
|
||||
@@ -1105,7 +1105,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
print('{}[bauh][web] An exception has happened when deleting {}{}'.format(Fore.RED, ENV_PATH, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
web_config = self.configman.get_config()
|
||||
max_width = floor(self.context.screen_width * 0.15)
|
||||
|
||||
@@ -1149,26 +1149,27 @@ class WebApplicationManager(SoftwareManager):
|
||||
form_env = FormComponent(label=self.i18n['web.settings.nativefier.env'].capitalize(),
|
||||
components=[input_electron, select_nativefier, env_settings_exp, sugs_exp])
|
||||
|
||||
return PanelComponent([form_env])
|
||||
yield SettingsView(self, PanelComponent([form_env]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
web_config = self.configman.get_config()
|
||||
|
||||
form_env = component.components[0]
|
||||
form_env = component.get_component_by_idx(0, FormComponent)
|
||||
|
||||
web_config['environment']['electron']['version'] = str(form_env.get_component('electron_branch').get_value()).strip()
|
||||
electron_version = str(form_env.get_text_input('electron_branch').get_value()).strip()
|
||||
web_config['environment']['electron']['version'] = electron_version
|
||||
|
||||
if len(web_config['environment']['electron']['version']) == 0:
|
||||
web_config['environment']['electron']['version'] = None
|
||||
|
||||
system_nativefier = form_env.get_component('nativefier').get_selected()
|
||||
system_nativefier = form_env.get_single_select_component('nativefier').get_selected()
|
||||
|
||||
if system_nativefier and not nativefier.is_available():
|
||||
return False, [self.i18n['web.settings.env.nativefier.system.not_installed'].format('Nativefier')]
|
||||
|
||||
web_config['environment']['system'] = system_nativefier
|
||||
web_config['environment']['cache_exp'] = form_env.get_component('web_cache_exp').get_int_value()
|
||||
web_config['suggestions']['cache_exp'] = form_env.get_component('web_sugs_exp').get_int_value()
|
||||
web_config['environment']['cache_exp'] = form_env.get_text_input('web_cache_exp').get_int_value()
|
||||
web_config['suggestions']['cache_exp'] = form_env.get_text_input('web_sugs_exp').get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(web_config)
|
||||
|
||||
Reference in New Issue
Block a user