mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 22:24:16 +02:00
[api] refactoring: 'get_custom_actions' renamed to 'gen_custom_actions' and returning a Generator
This commit is contained in:
@@ -9,7 +9,7 @@ import traceback
|
||||
from datetime import datetime
|
||||
from math import floor
|
||||
from pathlib import Path
|
||||
from typing import Set, Type, List, Tuple, Optional
|
||||
from typing import Set, Type, List, Tuple, Optional, Iterable, Generator
|
||||
|
||||
from colorama import Fore
|
||||
from packaging.version import parse as parse_version
|
||||
@@ -78,7 +78,7 @@ class AppImageManager(SoftwareManager):
|
||||
self.logger = context.logger
|
||||
self.file_downloader = context.file_downloader
|
||||
self.configman = AppImageConfigManager()
|
||||
self.custom_actions = [CustomSoftwareAction(i18n_label_key='appimage.custom_action.install_file',
|
||||
self.custom_actions = (CustomSoftwareAction(i18n_label_key='appimage.custom_action.install_file',
|
||||
i18n_status_key='appimage.custom_action.install_file.status',
|
||||
manager=self,
|
||||
manager_method='install_file',
|
||||
@@ -90,7 +90,7 @@ class AppImageManager(SoftwareManager):
|
||||
manager_method='update_database',
|
||||
icon_path=resource.get_path('img/appimage.svg', ROOT_DIR),
|
||||
requires_root=False,
|
||||
requires_internet=True)]
|
||||
requires_internet=True))
|
||||
self.custom_app_actions = [CustomSoftwareAction(i18n_label_key='appimage.custom_action.manual_update',
|
||||
i18n_status_key='appimage.custom_action.manual_update.status',
|
||||
manager_method='update_file',
|
||||
@@ -862,8 +862,9 @@ class AppImageManager(SoftwareManager):
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
return self.custom_actions
|
||||
def gen_custom_actions(self) -> Generator[CustomSoftwareAction, None, None]:
|
||||
for action in self.custom_actions:
|
||||
yield action
|
||||
|
||||
def get_upgrade_requirements(self, pkgs: List[AppImage], root_password: str, watcher: ProcessWatcher) -> UpgradeRequirements:
|
||||
to_update = []
|
||||
|
||||
@@ -12,7 +12,7 @@ from math import floor
|
||||
from pathlib import Path
|
||||
from pwd import getpwnam
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type, Tuple, Dict, Iterable, Optional, Collection
|
||||
from typing import List, Set, Type, Tuple, Dict, Iterable, Optional, Collection, Generator
|
||||
|
||||
import requests
|
||||
from dateutil.parser import parse as parse_date
|
||||
@@ -3040,24 +3040,20 @@ class ArchManager(SoftwareManager):
|
||||
except PackageNotFoundException:
|
||||
pass # when nothing is returned, the upgrade is called off by the UI
|
||||
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
actions = []
|
||||
|
||||
def gen_custom_actions(self) -> Generator[CustomSoftwareAction, None, None]:
|
||||
arch_config = self.configman.get_config()
|
||||
|
||||
if pacman.is_mirrors_available():
|
||||
actions.append(self.custom_actions['ref_mirrors'])
|
||||
yield self.custom_actions['ref_mirrors']
|
||||
|
||||
actions.append(self.custom_actions['ref_dbs'])
|
||||
actions.append(self.custom_actions['clean_cache'])
|
||||
yield self.custom_actions['ref_dbs']
|
||||
yield self.custom_actions['clean_cache']
|
||||
|
||||
if bool(arch_config['repositories']):
|
||||
actions.append(self.custom_actions['sys_up'])
|
||||
yield self.custom_actions['sys_up']
|
||||
|
||||
if pacman.is_snapd_installed():
|
||||
actions.append(self.custom_actions['setup_snapd'])
|
||||
|
||||
return actions
|
||||
yield self.custom_actions['setup_snapd']
|
||||
|
||||
def fill_sizes(self, pkgs: List[ArchPackage]):
|
||||
installed, new, all_names, installed_names = [], [], [], []
|
||||
|
||||
@@ -9,7 +9,7 @@ import traceback
|
||||
from math import floor
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
from typing import List, Type, Set, Tuple, Optional, Dict
|
||||
from typing import List, Type, Set, Tuple, Optional, Dict, Generator
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
@@ -74,7 +74,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
self.suggestions = {}
|
||||
self.configman = WebConfigManager()
|
||||
self.idxman = SearchIndexManager(logger=context.logger)
|
||||
self.custom_actions = [
|
||||
self.custom_actions = (
|
||||
CustomSoftwareAction(i18n_label_key='web.custom_action.install_app',
|
||||
i18n_status_key='web.custom_action.install_app.status',
|
||||
manager=self,
|
||||
@@ -89,7 +89,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
icon_path=resource.get_path('img/web.svg', ROOT_DIR),
|
||||
requires_root=False,
|
||||
refresh=False)
|
||||
]
|
||||
)
|
||||
|
||||
def _get_lang_header(self) -> str:
|
||||
try:
|
||||
@@ -1170,5 +1170,6 @@ class WebApplicationManager(SoftwareManager):
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
return self.custom_actions
|
||||
def gen_custom_actions(self) -> Generator[CustomSoftwareAction, None, None]:
|
||||
for action in self.custom_actions:
|
||||
yield action
|
||||
|
||||
Reference in New Issue
Block a user