mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 03:34:15 +02:00
[flatpak] sorting packages before updating
This commit is contained in:
@@ -79,21 +79,21 @@ class AURClient:
|
||||
self.logger.info('{p} is based on {b}. Retrieving {b} .SRCINFO'.format(p=info_name, b=info_base))
|
||||
return self.get_src_info(info_base)
|
||||
|
||||
def extract_all_dependencies(self, pkginfo: dict) -> Set[str]:
|
||||
def extract_required_dependencies(self, pkginfo: dict) -> Set[str]:
|
||||
deps = set()
|
||||
for attr in ('makedepends', 'depends', 'checkdepends'):
|
||||
if pkginfo.get(attr):
|
||||
deps.update([pacman.RE_DEP_OPERATORS.split(dep)[0] for dep in info[attr]])
|
||||
deps.update([pacman.RE_DEP_OPERATORS.split(dep)[0] for dep in pkginfo[attr]])
|
||||
|
||||
return deps
|
||||
|
||||
def get_all_dependencies(self, name: str) -> Set[str]:
|
||||
def get_required_dependencies(self, name: str) -> Set[str]:
|
||||
info = self.get_src_info(name)
|
||||
|
||||
if not info:
|
||||
raise PackageNotFoundException(name)
|
||||
|
||||
return self.extract_all_dependencies(info)
|
||||
return self.extract_required_dependencies(info)
|
||||
|
||||
def _map_names_as_queries(self, names) -> str:
|
||||
return '&'.join(['arg[{}]={}'.format(i, urllib.parse.quote(n)) for i, n in enumerate(names)])
|
||||
|
||||
@@ -1009,7 +1009,7 @@ class ArchManager(SoftwareManager):
|
||||
for n in names:
|
||||
names_map[n] = pkg
|
||||
|
||||
pkg_deps[pkg] = self.aur_client.extract_all_dependencies(srcinfo)
|
||||
pkg_deps[pkg] = self.aur_client.extract_required_dependencies(srcinfo)
|
||||
except:
|
||||
pkg_deps[pkg] = None
|
||||
self.logger.warning("Could not retrieve dependencies for '{}'".format(pkg.name))
|
||||
|
||||
@@ -71,7 +71,7 @@ class DependenciesAnalyser:
|
||||
|
||||
missing_sub = []
|
||||
for rdep in missing_root:
|
||||
subdeps = self.aur_client.get_all_dependencies(rdep[0]) if rdep[1] == 'aur' else pacman.read_dependencies(rdep[0])
|
||||
subdeps = self.aur_client.get_required_dependencies(rdep[0]) if rdep[1] == 'aur' else pacman.read_dependencies(rdep[0])
|
||||
subdeps_not_analysis = {sd for sd in subdeps if sd not in global_in_analysis}
|
||||
|
||||
if subdeps_not_analysis:
|
||||
@@ -93,7 +93,7 @@ class DependenciesAnalyser:
|
||||
in_analyses = {*names}
|
||||
|
||||
for name in names:
|
||||
subdeps = self.aur_client.get_all_dependencies(name) if mirror == 'aur' else pacman.read_dependencies(name)
|
||||
subdeps = self.aur_client.get_required_dependencies(name) if mirror == 'aur' else pacman.read_dependencies(name)
|
||||
|
||||
if subdeps:
|
||||
missing_subdeps = self.get_missing_packages(subdeps, in_analysis=in_analyses)
|
||||
|
||||
@@ -469,3 +469,28 @@ class FlatpakManager(SoftwareManager):
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def sort_update_order(self, pkgs: List[FlatpakApplication]) -> List[FlatpakApplication]:
|
||||
partials, runtimes, apps = [], [], []
|
||||
|
||||
for p in pkgs:
|
||||
if p.runtime:
|
||||
if p.partial:
|
||||
partials.append(p)
|
||||
else:
|
||||
runtimes.append(p)
|
||||
else:
|
||||
apps.append(p)
|
||||
|
||||
if not runtimes:
|
||||
return [*partials, *apps]
|
||||
elif partials:
|
||||
all_runtimes = []
|
||||
for runtime in runtimes:
|
||||
for partial in partials:
|
||||
if partial.base_id == runtime.id:
|
||||
all_runtimes.append(partial)
|
||||
|
||||
all_runtimes.append(runtime)
|
||||
return [*all_runtimes, *apps]
|
||||
else:
|
||||
return [*runtimes, *apps]
|
||||
|
||||
@@ -10,7 +10,7 @@ class FlatpakApplication(SoftwarePackage):
|
||||
|
||||
def __init__(self, id: str = None, name: str = None, version: str = None, latest_version: str = None, description: str = None,
|
||||
branch: str = None, arch: str = None, origin: str = None, runtime: bool = False, ref: str = None, commit: str = None,
|
||||
installation: str = None, i18n: I18n = None):
|
||||
installation: str = None, i18n: I18n = None, partial: bool = False):
|
||||
super(FlatpakApplication, self).__init__(id=id, name=name, version=version,
|
||||
latest_version=latest_version, description=description)
|
||||
self.ref = ref
|
||||
@@ -19,7 +19,7 @@ class FlatpakApplication(SoftwarePackage):
|
||||
self.origin = origin
|
||||
self.runtime = runtime
|
||||
self.commit = commit
|
||||
self.partial = False
|
||||
self.partial = partial
|
||||
self.installation = installation if installation else 'system'
|
||||
self.i18n = i18n
|
||||
self.base_id = None
|
||||
|
||||
@@ -438,9 +438,13 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
if by_manager:
|
||||
for man, pkgs in by_manager.items():
|
||||
ti = time.time()
|
||||
sorted_list.extend(man.sort_update_order(pkgs))
|
||||
tf = time.time()
|
||||
self.logger.info(man.__class__.__name__ + " took {0:.2f} seconds".format(tf - ti))
|
||||
if len(pkgs) > 1:
|
||||
ti = time.time()
|
||||
sorted_list.extend(man.sort_update_order(pkgs))
|
||||
tf = time.time()
|
||||
self.logger.info(man.__class__.__name__ + " took {0:.2f} seconds".format(tf - ti))
|
||||
else:
|
||||
self.logger.info("Only one package to sort for {}. Ignoring sorting.".format(man.__class__.__name__))
|
||||
sorted_list.extend(pkgs)
|
||||
|
||||
return sorted_list
|
||||
|
||||
@@ -108,7 +108,7 @@ class UpdateSelectedApps(AsyncAction):
|
||||
sorted_pkgs = self.manager.sort_update_order([view.model for view in self.apps_to_update])
|
||||
|
||||
for pkg in sorted_pkgs:
|
||||
|
||||
self.change_substatus('')
|
||||
name = pkg.name if not RE_VERSION_IN_NAME.findall(pkg.name) else pkg.name.split('version')[0].strip()
|
||||
|
||||
self.change_status('{} {} {}...'.format(self.i18n['manage_window.status.upgrading'], name, pkg.version))
|
||||
|
||||
Reference in New Issue
Block a user