mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 22:24:14 +02:00
[ui] fix: upgrading: only requesting the root password if required | [flatpak] fix -> crashing when trying to downgrade
This commit is contained in:
@@ -17,7 +17,7 @@ from pkg_resources import parse_version
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, UpgradeRequirements, UpgradeRequirement, \
|
||||
TransactionResult
|
||||
TransactionResult, SoftwareAction
|
||||
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, \
|
||||
@@ -416,7 +416,8 @@ class AppImageManager(SoftwareManager):
|
||||
app_tuple = cursor.fetchone()
|
||||
|
||||
if not app_tuple:
|
||||
raise Exception("Could not retrieve {} from the database {}".format(pkg, DB_APPS_PATH))
|
||||
self.logger.warning("Could not retrieve {} from the database {}".format(pkg, DB_APPS_PATH))
|
||||
return res
|
||||
finally:
|
||||
self._close_connection(DB_APPS_PATH, connection)
|
||||
|
||||
@@ -582,7 +583,7 @@ class AppImageManager(SoftwareManager):
|
||||
def can_work(self) -> bool:
|
||||
return self._is_sqlite3_available() and self.file_downloader.can_work()
|
||||
|
||||
def requires_root(self, action: str, pkg: AppImage):
|
||||
def requires_root(self, action: SoftwareAction, pkg: AppImage) -> bool:
|
||||
return False
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
|
||||
@@ -14,7 +14,7 @@ appimage.downgrade.first_version={} is in its first published version
|
||||
appimage.downgrade.impossible.body={} has only one published version.
|
||||
appimage.downgrade.impossible.title=Impossible to downgrade
|
||||
appimage.downgrade.install_version=It was not possible to install the version {} ({})
|
||||
appimage.downgrade.unknown_version.body=It was not possible to identify {} current version in its versions history
|
||||
appimage.downgrade.unknown_version.body={} current version was not found in its release history
|
||||
appimage.error.uninstall_current_version=It was not possible to uninstall the current version of {}
|
||||
appimage.history.0_version=version
|
||||
appimage.history.1_published_at=date
|
||||
|
||||
@@ -16,7 +16,7 @@ from typing import List, Set, Type, Tuple, Dict, Iterable, Optional
|
||||
import requests
|
||||
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult
|
||||
TransactionResult, SoftwareAction
|
||||
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, \
|
||||
@@ -2476,8 +2476,8 @@ class ArchManager(SoftwareManager):
|
||||
def cache_to_disk(self, pkg: ArchPackage, icon_bytes: bytes, only_icon: bool):
|
||||
pass
|
||||
|
||||
def requires_root(self, action: str, pkg: ArchPackage):
|
||||
if action == 'prepare':
|
||||
def requires_root(self, action: SoftwareAction, pkg: ArchPackage) -> bool:
|
||||
if action == SoftwareAction.PREPARE:
|
||||
arch_config = read_config()
|
||||
|
||||
if arch_config['refresh_mirrors_startup'] and mirrors.should_sync(self.logger):
|
||||
@@ -2485,7 +2485,7 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
return arch_config['sync_databases_startup'] and database.should_sync(arch_config, None, self.logger)
|
||||
|
||||
return action != 'search'
|
||||
return action != SoftwareAction.SEARCH
|
||||
|
||||
def _start_category_task(self, task_man: TaskManager):
|
||||
task_man.register_task('arch_aur_cats', self.i18n['task.download_categories'].format('Arch'), get_icon_path())
|
||||
|
||||
@@ -8,7 +8,7 @@ from threading import Thread
|
||||
from typing import List, Set, Type, Tuple, Optional
|
||||
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
UpgradeRequirement, TransactionResult
|
||||
UpgradeRequirement, TransactionResult, SoftwareAction
|
||||
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, \
|
||||
@@ -112,7 +112,7 @@ class FlatpakManager(SoftwareManager):
|
||||
def _add_updates(self, version: str, output: list):
|
||||
output.append(flatpak.list_updates_as_str(version))
|
||||
|
||||
def read_installed(self, disk_loader: DiskCacheLoader, limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult:
|
||||
def read_installed(self, disk_loader: Optional[DiskCacheLoader], limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult:
|
||||
version = flatpak.get_version()
|
||||
|
||||
updates = []
|
||||
@@ -174,7 +174,7 @@ class FlatpakManager(SoftwareManager):
|
||||
watcher.change_progress(10)
|
||||
watcher.change_substatus(self.i18n['flatpak.downgrade.commits'])
|
||||
|
||||
history = self.get_history(pkg)
|
||||
history = self.get_history(pkg, full_commit_str=True)
|
||||
|
||||
# downgrade is not possible if the app current commit in the first one:
|
||||
if history.pkg_status_idx == len(history.history) - 1:
|
||||
@@ -295,9 +295,9 @@ class FlatpakManager(SoftwareManager):
|
||||
else:
|
||||
return {}
|
||||
|
||||
def get_history(self, pkg: FlatpakApplication) -> PackageHistory:
|
||||
def get_history(self, pkg: FlatpakApplication, full_commit_str: bool = False) -> PackageHistory:
|
||||
pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation)
|
||||
commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin, pkg.installation)
|
||||
commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin, pkg.installation, full_str=full_commit_str)
|
||||
|
||||
status_idx = 0
|
||||
commit_found = False
|
||||
@@ -444,8 +444,8 @@ class FlatpakManager(SoftwareManager):
|
||||
def can_work(self) -> bool:
|
||||
return flatpak.is_installed()
|
||||
|
||||
def requires_root(self, action: str, pkg: FlatpakApplication):
|
||||
return action == 'downgrade' and pkg.installation == 'system'
|
||||
def requires_root(self, action: SoftwareAction, pkg: FlatpakApplication) -> bool:
|
||||
return action == SoftwareAction.DOWNGRADE and pkg.installation == 'system'
|
||||
|
||||
def prepare(self, task_manager: TaskManager, root_password: str, internet_available: bool):
|
||||
Thread(target=read_config, args=(True,), daemon=True).start()
|
||||
|
||||
@@ -233,7 +233,7 @@ def downgrade(app_ref: str, commit: str, installation: str, root_password: str)
|
||||
wrong_error_phrases={'Warning'})
|
||||
|
||||
|
||||
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]:
|
||||
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> Optional[List[str]]:
|
||||
try:
|
||||
p = SimpleProcess(['flatpak', 'remote-info', '--log', origin, app_ref, '--{}'.format(installation)])
|
||||
success, output = handler.handle_simple(p)
|
||||
@@ -245,7 +245,7 @@ def get_app_commits(app_ref: str, origin: str, installation: str, handler: Proce
|
||||
raise NoInternetException()
|
||||
|
||||
|
||||
def get_app_commits_data(app_ref: str, origin: str, installation: str) -> List[dict]:
|
||||
def get_app_commits_data(app_ref: str, origin: str, installation: str, full_str: bool = True) -> List[dict]:
|
||||
log = run_cmd('{} remote-info --log {} {} --{}'.format('flatpak', origin, app_ref, installation))
|
||||
|
||||
if not log:
|
||||
@@ -262,7 +262,7 @@ def get_app_commits_data(app_ref: str, origin: str, installation: str) -> List[d
|
||||
commit[attr] = data[1].strip()
|
||||
|
||||
if attr == 'commit':
|
||||
commit[attr] = commit[attr][0:8]
|
||||
commit[attr] = commit[attr] if full_str else commit[attr][0:8]
|
||||
|
||||
if attr == 'date':
|
||||
commit[attr] = datetime.strptime(commit[attr], '%Y-%m-%d %H:%M:%S +0000')
|
||||
|
||||
@@ -5,7 +5,7 @@ from threading import Thread
|
||||
from typing import List, Set, Type, Optional, Tuple
|
||||
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult
|
||||
TransactionResult, SoftwareAction
|
||||
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, \
|
||||
@@ -255,8 +255,8 @@ class SnapManager(SoftwareManager):
|
||||
def can_work(self) -> bool:
|
||||
return snap.is_installed()
|
||||
|
||||
def requires_root(self, action: str, pkg: SnapApplication):
|
||||
return action not in ('search', 'prepare')
|
||||
def requires_root(self, action: SoftwareAction, pkg: SnapApplication) -> bool:
|
||||
return action not in (SoftwareAction.PREPARE, SoftwareAction.SEARCH)
|
||||
|
||||
def refresh(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||
return ProcessHandler(watcher).handle_simple(snap.refresh_and_stream(pkg.name, root_password))[0]
|
||||
|
||||
@@ -17,7 +17,8 @@ from colorama import Fore
|
||||
from requests import exceptions, Response
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, UpgradeRequirements, TransactionResult
|
||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult, UpgradeRequirements, TransactionResult, \
|
||||
SoftwareAction
|
||||
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, \
|
||||
@@ -801,7 +802,7 @@ class WebApplicationManager(SoftwareManager):
|
||||
|
||||
return False
|
||||
|
||||
def requires_root(self, action: str, pkg: SoftwarePackage):
|
||||
def requires_root(self, action: SoftwareAction, pkg: SoftwarePackage) -> bool:
|
||||
return False
|
||||
|
||||
def _update_env_settings(self, task_manager: TaskManager = None):
|
||||
|
||||
Reference in New Issue
Block a user