mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-10 06:34:15 +02:00
[improvement][ui] not performing a full table refresh after installing a new package
This commit is contained in:
@@ -15,7 +15,8 @@ from typing import List, Set, Type, Tuple, Dict, Iterable
|
||||
|
||||
import requests
|
||||
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements
|
||||
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
|
||||
TransactionResult
|
||||
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, \
|
||||
@@ -63,7 +64,8 @@ class TransactionContext:
|
||||
install_file: str = None, repository: str = None, pkg: ArchPackage = None,
|
||||
remote_repo_map: Dict[str, str] = None, provided_map: Dict[str, Set[str]] = None,
|
||||
remote_provided_map: Dict[str, Set[str]] = None, aur_idx: Set[str] = None,
|
||||
missing_deps: List[Tuple[str, str]] = None):
|
||||
missing_deps: List[Tuple[str, str]] = None, installed: Set[str] = None, removed: Dict[str, SoftwarePackage] = None,
|
||||
disk_loader: DiskCacheLoader = None):
|
||||
self.name = name
|
||||
self.base = base
|
||||
self.maintainer = maintainer
|
||||
@@ -84,12 +86,16 @@ class TransactionContext:
|
||||
self.remote_provided_map = remote_provided_map
|
||||
self.aur_idx = aur_idx
|
||||
self.missing_deps = missing_deps
|
||||
self.installed = installed
|
||||
self.removed = removed
|
||||
self.disk_loader = disk_loader
|
||||
|
||||
@classmethod
|
||||
def gen_context_from(cls, pkg: ArchPackage, arch_config: dict, root_password: str, handler: ProcessHandler) -> "TransactionContext":
|
||||
return cls(name=pkg.name, base=pkg.get_base_name(), maintainer=pkg.maintainer, repository=pkg.repository,
|
||||
arch_config=arch_config, watcher=handler.watcher, handler=handler, skip_opt_deps=True,
|
||||
change_progress=True, root_password=root_password, dependency=False)
|
||||
change_progress=True, root_password=root_password, dependency=False,
|
||||
installed=set(), removed={})
|
||||
|
||||
def get_base_name(self):
|
||||
return self.base if self.base else self.name
|
||||
@@ -99,7 +105,7 @@ class TransactionContext:
|
||||
|
||||
def clone_base(self):
|
||||
return TransactionContext(watcher=self.watcher, handler=self.handler, root_password=self.root_password,
|
||||
arch_config=self.config)
|
||||
arch_config=self.config, installed=set(), removed={})
|
||||
|
||||
def gen_dep_context(self, name: str, repository: str):
|
||||
dep_context = self.clone_base()
|
||||
@@ -107,6 +113,8 @@ class TransactionContext:
|
||||
dep_context.repository = repository
|
||||
dep_context.dependency = True
|
||||
dep_context.change_progress = False
|
||||
dep_context.installed = set()
|
||||
dep_context.removed = {}
|
||||
return dep_context
|
||||
|
||||
def has_install_file(self) -> bool:
|
||||
@@ -894,7 +902,7 @@ class ArchManager(SoftwareManager):
|
||||
context.change_progress = False
|
||||
|
||||
try:
|
||||
if not self.install(pkg=pkg, root_password=root_password, watcher=watcher, context=context):
|
||||
if not self.install(pkg=pkg, root_password=root_password, watcher=watcher, disk_loader=None, context=context).success:
|
||||
watcher.print(self.i18n['arch.upgrade.fail'].format('"{}"'.format(pkg.name)))
|
||||
self.logger.error("Could not upgrade AUR package '{}'".format(pkg.name))
|
||||
watcher.change_substatus('')
|
||||
@@ -1500,6 +1508,8 @@ class ArchManager(SoftwareManager):
|
||||
message.show_deps_not_installed(context.watcher, context.name, deps_not_installed, self.i18n)
|
||||
return False
|
||||
|
||||
context.installed.update({d[0] for d in missing_deps})
|
||||
|
||||
return True
|
||||
|
||||
def _list_missing_deps(self, context: TransactionContext) -> List[Tuple[str, str]]:
|
||||
@@ -1657,6 +1667,8 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
if deps_not_installed:
|
||||
message.show_optdeps_not_installed(deps_not_installed, context.watcher, self.i18n)
|
||||
else:
|
||||
context.installed.update({dep[0] for dep in sorted_deps})
|
||||
|
||||
return True
|
||||
|
||||
@@ -1703,6 +1715,12 @@ class ArchManager(SoftwareManager):
|
||||
to_uninstall = [conflict for conflict in conflicting_apps if conflict != context.name]
|
||||
|
||||
self.logger.info("Preparing to uninstall conflicting packages: {}".format(to_uninstall))
|
||||
|
||||
pkgs_to_uninstall = self.read_installed(disk_loader=context.disk_loader, names=to_uninstall, internet_available=True).installed
|
||||
|
||||
if not pkgs_to_uninstall:
|
||||
self.logger.warning("Could not load packages to uninstall")
|
||||
|
||||
for conflict in to_uninstall:
|
||||
context.watcher.change_substatus(self.i18n['arch.uninstalling.conflict'].format(bold(conflict)))
|
||||
|
||||
@@ -1711,6 +1729,13 @@ class ArchManager(SoftwareManager):
|
||||
body=self.i18n['arch.uninstalling.conflict.fail'].format(bold(conflict)),
|
||||
type_=MessageType.ERROR)
|
||||
return False
|
||||
else:
|
||||
uninstalled = [p for p in pkgs_to_uninstall if p.name == conflict]
|
||||
if uninstalled:
|
||||
uninstalled[0].icon_path = None
|
||||
uninstalled[0].icon_url = None
|
||||
uninstalled[0].installed = False
|
||||
context.removed[conflict] = uninstalled[0]
|
||||
else:
|
||||
self.logger.info("No conflict detected for '{}'".format(context.name))
|
||||
|
||||
@@ -1742,6 +1767,7 @@ class ArchManager(SoftwareManager):
|
||||
else:
|
||||
status_handler = None
|
||||
|
||||
installed_with_same_name = self.read_installed(disk_loader=context.disk_loader, internet_available=True, names={context.name}).installed
|
||||
context.watcher.change_substatus(self.i18n['arch.installing.package'].format(bold(context.name)))
|
||||
installed, _ = context.handler.handle_simple(pacman.install_as_process(pkgpaths=to_install,
|
||||
root_password=context.root_password,
|
||||
@@ -1755,6 +1781,16 @@ class ArchManager(SoftwareManager):
|
||||
self._update_progress(context, 95)
|
||||
|
||||
if installed:
|
||||
context.installed.add(context.name)
|
||||
context.installed.update((p for p in to_install if not p.startswith('/')))
|
||||
|
||||
if installed_with_same_name:
|
||||
for p in installed_with_same_name:
|
||||
context.removed[p.name] = p
|
||||
p.installed = False
|
||||
p.icon_path = None
|
||||
p.icon_url = None
|
||||
|
||||
context.watcher.change_substatus(self.i18n['status.caching_data'].format(bold(context.name)))
|
||||
|
||||
if not context.maintainer:
|
||||
@@ -1887,16 +1923,16 @@ class ArchManager(SoftwareManager):
|
||||
watcher.change_substatus(self.i18n['arch.makepkg.optimizing'])
|
||||
ArchCompilationOptimizer(arch_config, self.i18n, self.context.logger).optimize()
|
||||
|
||||
def install(self, pkg: ArchPackage, root_password: str, watcher: ProcessWatcher, context: TransactionContext = None) -> bool:
|
||||
def install(self, pkg: ArchPackage, root_password: str, disk_loader: DiskCacheLoader, watcher: ProcessWatcher, context: TransactionContext = None) -> TransactionResult:
|
||||
self.aur_client.clean_caches()
|
||||
|
||||
if not self._check_action_allowed(pkg, watcher):
|
||||
return False
|
||||
return TransactionResult(success=False, installed=[], removed=[])
|
||||
|
||||
handler = ProcessHandler(watcher) if not context else context.handler
|
||||
|
||||
if self._is_database_locked(handler, root_password):
|
||||
return False
|
||||
return TransactionResult(success=False, installed=[], removed=[])
|
||||
|
||||
if context:
|
||||
install_context = context
|
||||
@@ -1904,6 +1940,7 @@ class ArchManager(SoftwareManager):
|
||||
install_context = TransactionContext.gen_context_from(pkg=pkg, handler=handler, arch_config=read_config(),
|
||||
root_password=root_password)
|
||||
install_context.skip_opt_deps = False
|
||||
install_context.disk_loader = disk_loader
|
||||
|
||||
self._sync_databases(arch_config=install_context.config, root_password=root_password, handler=handler)
|
||||
|
||||
@@ -1919,7 +1956,30 @@ class ArchManager(SoftwareManager):
|
||||
data = json.loads(data)
|
||||
pkg.fill_cached_data(data)
|
||||
|
||||
return res
|
||||
installed = []
|
||||
|
||||
if res and disk_loader and install_context.installed:
|
||||
installed.append(pkg)
|
||||
|
||||
installed_to_load = []
|
||||
|
||||
if len(install_context.installed) > 1:
|
||||
installed_to_load.extend({i for i in install_context.installed if i != pkg.name})
|
||||
|
||||
if installed_to_load:
|
||||
installed_loaded = self.read_installed(disk_loader=disk_loader,
|
||||
names=installed_to_load,
|
||||
internet_available=True).installed
|
||||
|
||||
installed.extend(installed_loaded)
|
||||
|
||||
if len(installed_loaded) + 1 != len(install_context.installed):
|
||||
missing = ','.join({p for p in installed_loaded if p.name not in install_context.installed})
|
||||
self.logger.warning("Could not load all installed packages. Missing: {}".format(missing))
|
||||
|
||||
removed = [*install_context.removed.values()] if install_context.removed else []
|
||||
|
||||
return TransactionResult(success=res, installed=installed, removed=removed)
|
||||
|
||||
def _install_from_repository(self, context: TransactionContext) -> bool:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user