mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[snap] refactoring: custom actions moved to SnapApplication and are instantiated on demand
This commit is contained in:
@@ -9,18 +9,17 @@ from bauh.api.abstract.controller import SoftwareManager, SearchResult, Applicat
|
||||
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, PackageStatus
|
||||
SuggestionPriority, PackageStatus
|
||||
from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputOption, ViewComponent, PanelComponent, \
|
||||
FormComponent, TextInputComponent
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import resource
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.category import CategoriesDownloader
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import SystemProcess, ProcessHandler, new_root_subprocess, get_human_size_str
|
||||
from bauh.commons.view_utils import new_select
|
||||
from bauh.gems.snap import snap, URL_CATEGORIES_FILE, CATEGORIES_FILE_PATH, SUGGESTIONS_FILE, \
|
||||
get_icon_path, snapd, ROOT_DIR
|
||||
get_icon_path, snapd
|
||||
from bauh.gems.snap.config import SnapConfigManager
|
||||
from bauh.gems.snap.model import SnapApplication
|
||||
from bauh.gems.snap.snapd import SnapdClient
|
||||
@@ -43,23 +42,6 @@ class SnapManager(SoftwareManager):
|
||||
self.suggestions_cache = context.cache_factory.new()
|
||||
self.info_path = None
|
||||
self.configman = SnapConfigManager()
|
||||
self.custom_actions = (
|
||||
CustomSoftwareAction(i18n_status_key='snap.action.refresh.status',
|
||||
i18n_label_key='snap.action.refresh.label',
|
||||
i18n_description_key='snap.action.refresh.desc',
|
||||
icon_path=resource.get_path('img/refresh.svg', ROOT_DIR),
|
||||
manager_method='refresh',
|
||||
requires_root=True,
|
||||
i18n_confirm_key='snap.action.refresh.confirm'),
|
||||
CustomSoftwareAction(i18n_status_key='snap.action.channel.status',
|
||||
i18n_label_key='snap.action.channel.label',
|
||||
i18n_confirm_key='snap.action.channel.confirm',
|
||||
i18n_description_key='snap.action.channel.desc',
|
||||
icon_path=resource.get_path('img/refresh.svg', ROOT_DIR),
|
||||
manager_method='change_channel',
|
||||
requires_root=True,
|
||||
requires_confirmation=False)
|
||||
)
|
||||
|
||||
def _fill_categories(self, app: SnapApplication):
|
||||
categories = self.categories.get(app.name.lower())
|
||||
@@ -369,8 +351,7 @@ class SnapManager(SoftwareManager):
|
||||
confinement=app_json.get('confinement'),
|
||||
app_type=app_json.get('type'),
|
||||
app=is_application,
|
||||
installed_size=app_json.get('installed-size'),
|
||||
extra_actions=self.custom_actions)
|
||||
installed_size=app_json.get('installed-size'))
|
||||
|
||||
if disk_loader and app.installed:
|
||||
disk_loader.fill(app)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional, Set, Iterable
|
||||
from typing import Optional, Set, Iterable, Tuple
|
||||
|
||||
from bauh.api.abstract.model import SoftwarePackage, CustomSoftwareAction
|
||||
from bauh.commons import resource
|
||||
@@ -7,10 +7,34 @@ from bauh.gems.snap import ROOT_DIR
|
||||
|
||||
class SnapApplication(SoftwarePackage):
|
||||
|
||||
__actions: Optional[Tuple[CustomSoftwareAction, CustomSoftwareAction]] = None
|
||||
|
||||
@classmethod
|
||||
def actions(cls) -> Tuple[CustomSoftwareAction, CustomSoftwareAction]:
|
||||
if cls.__actions is None:
|
||||
cls.__actions = (
|
||||
CustomSoftwareAction(i18n_status_key='snap.action.refresh.status',
|
||||
i18n_label_key='snap.action.refresh.label',
|
||||
i18n_description_key='snap.action.refresh.desc',
|
||||
icon_path=resource.get_path('img/refresh.svg', ROOT_DIR),
|
||||
manager_method='refresh',
|
||||
requires_root=True,
|
||||
i18n_confirm_key='snap.action.refresh.confirm'),
|
||||
CustomSoftwareAction(i18n_status_key='snap.action.channel.status',
|
||||
i18n_label_key='snap.action.channel.label',
|
||||
i18n_confirm_key='snap.action.channel.confirm',
|
||||
i18n_description_key='snap.action.channel.desc',
|
||||
icon_path=resource.get_path('img/refresh.svg', ROOT_DIR),
|
||||
manager_method='change_channel',
|
||||
requires_root=True,
|
||||
requires_confirmation=False)
|
||||
)
|
||||
|
||||
return cls.__actions
|
||||
|
||||
def __init__(self, id: str = None, name: str = None, version: str = None, latest_version: str = None,
|
||||
description: str = None, publisher: str = None, rev: str = None, notes: str = None,
|
||||
confinement: str = None, verified_publisher: bool = False,
|
||||
extra_actions: Optional[Iterable[CustomSoftwareAction]] = None,
|
||||
screenshots: Optional[Set[str]] = None,
|
||||
license: Optional[str] = None,
|
||||
installed: bool = False,
|
||||
@@ -31,7 +55,6 @@ class SnapApplication(SoftwarePackage):
|
||||
self.notes = notes
|
||||
self.confinement = confinement
|
||||
self.verified_publisher = verified_publisher
|
||||
self.extra_actions = extra_actions
|
||||
self.screenshots = screenshots
|
||||
self.download_size = download_size
|
||||
self.developer = developer
|
||||
@@ -94,7 +117,7 @@ class SnapApplication(SoftwarePackage):
|
||||
|
||||
def get_custom_actions(self) -> Optional[Iterable[CustomSoftwareAction]]:
|
||||
if self.installed:
|
||||
return self.extra_actions
|
||||
return self.actions()
|
||||
|
||||
def supports_backup(self) -> bool:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user