mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[api] improvement: SoftwareManager.get_screenshots returning a generator instead of a list
This commit is contained in:
@@ -795,11 +795,9 @@ class AppImageManager(SoftwareManager):
|
||||
def cache_to_disk(self, pkg: SoftwarePackage, icon_bytes: Optional[bytes], only_icon: bool):
|
||||
self.serialize_to_disk(pkg, icon_bytes, only_icon)
|
||||
|
||||
def get_screenshots(self, pkg: AppImage) -> List[str]:
|
||||
if pkg.has_screenshots():
|
||||
return [pkg.url_screenshot]
|
||||
|
||||
return []
|
||||
def get_screenshots(self, pkg: AppImage) -> Generator[str, None, None]:
|
||||
if pkg.url_screenshot:
|
||||
yield pkg.url_screenshot
|
||||
|
||||
def clear_data(self, logs: bool = True):
|
||||
for f in glob.glob(f'{APPIMAGE_SHARED_DIR}/*.db'):
|
||||
|
||||
@@ -2790,9 +2790,6 @@ class ArchManager(SoftwareManager):
|
||||
final_cmd = pkg.command.replace('%U', '')
|
||||
subprocess.Popen(final_cmd, shell=True)
|
||||
|
||||
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
||||
pass
|
||||
|
||||
def _gen_bool_selector(self, id_: str, label_key: str, tooltip_key: str, value: bool, max_width: int,
|
||||
capitalize_label: bool = True, label_params: Optional[list] = None, tooltip_params: Optional[list] = None) -> SingleSelectComponent:
|
||||
opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True),
|
||||
|
||||
@@ -5,10 +5,11 @@ from datetime import datetime
|
||||
from math import floor
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type, Tuple, Optional
|
||||
from typing import List, Set, Type, Tuple, Optional, Generator
|
||||
|
||||
from packaging.version import Version
|
||||
|
||||
from bauh.api import user
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
UpgradeRequirement, TransactionResult, SoftwareAction
|
||||
from bauh.api.abstract.disk import DiskCacheLoader
|
||||
@@ -17,11 +18,11 @@ from bauh.api.abstract.model import PackageHistory, PackageUpdate, SoftwarePacka
|
||||
SuggestionPriority, PackageStatus
|
||||
from bauh.api.abstract.view import MessageType, FormComponent, SingleSelectComponent, InputOption, SelectViewType, \
|
||||
ViewComponent, PanelComponent
|
||||
from bauh.api import user
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import strip_html, bold
|
||||
from bauh.commons.system import ProcessHandler
|
||||
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, FLATPAK_CONFIG_DIR, EXPORTS_PATH, \
|
||||
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, FLATPAK_CONFIG_DIR, \
|
||||
EXPORTS_PATH, \
|
||||
get_icon_path, VERSION_1_5, VERSION_1_2
|
||||
from bauh.gems.flatpak.config import FlatpakConfigManager
|
||||
from bauh.gems.flatpak.constants import FLATHUB_API_URL
|
||||
@@ -574,16 +575,16 @@ class FlatpakManager(SoftwareManager):
|
||||
def launch(self, pkg: FlatpakApplication):
|
||||
flatpak.run(str(pkg.id))
|
||||
|
||||
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
||||
screenshots_url = '{}/apps/{}'.format(FLATHUB_API_URL, pkg.id)
|
||||
urls = []
|
||||
def get_screenshots(self, pkg: FlatpakApplication) -> Generator[str, None, None]:
|
||||
screenshots_url = f'{FLATHUB_API_URL}/apps/{pkg.id}'
|
||||
|
||||
try:
|
||||
res = self.http_client.get_json(screenshots_url)
|
||||
|
||||
if res and res.get('screenshots'):
|
||||
for s in res['screenshots']:
|
||||
if s.get('imgDesktopUrl'):
|
||||
urls.append(s['imgDesktopUrl'])
|
||||
yield s['imgDesktopUrl']
|
||||
|
||||
except Exception as e:
|
||||
if e.__class__.__name__ == 'JSONDecodeError':
|
||||
@@ -591,8 +592,6 @@ class FlatpakManager(SoftwareManager):
|
||||
else:
|
||||
traceback.print_exc()
|
||||
|
||||
return urls
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
if not self.context.root_user:
|
||||
fields = []
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
import time
|
||||
import traceback
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type, Optional, Tuple
|
||||
from typing import List, Set, Type, Optional, Tuple, Generator
|
||||
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult, SoftwareAction
|
||||
@@ -440,8 +440,9 @@ class SnapManager(SoftwareManager):
|
||||
self.logger.info(f"Running '{pkg.name}': {cmd}")
|
||||
snap.run(cmd)
|
||||
|
||||
def get_screenshots(self, pkg: SnapApplication) -> List[str]:
|
||||
return pkg.screenshots if pkg.has_screenshots() else []
|
||||
def get_screenshots(self, pkg: SnapApplication) -> Generator[str, None, None]:
|
||||
if pkg.screenshots:
|
||||
yield from pkg.screenshots
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
snap_config = self.configman.get_config()
|
||||
|
||||
@@ -1072,9 +1072,6 @@ class WebApplicationManager(SoftwareManager):
|
||||
def launch(self, pkg: WebApplication):
|
||||
subprocess.Popen(args=[pkg.get_command()], shell=True, env={**os.environ})
|
||||
|
||||
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
||||
pass
|
||||
|
||||
def clear_data(self, logs: bool = True):
|
||||
if os.path.exists(ENV_PATH):
|
||||
if logs:
|
||||
|
||||
Reference in New Issue
Block a user