Improve algorithm to pick package provider (!1775)

Pick the provider with the shortest name instead of always the first one
This commit is contained in:
Luca Weiss 2019-04-13 10:14:36 +02:00 committed by Oliver Smith
parent 8b8a73e8dd
commit c847dfde7c
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
2 changed files with 19 additions and 11 deletions

View File

@ -337,6 +337,22 @@ def providers(args, package, arch=None, must_exist=True, indexes=None):
return ret
def provider_shortest(providers, pkgname):
"""
Get the provider with the shortest pkgname and log a message. In most cases
this should be sufficient, e.g. 'mesa-purism-gc7000-egl, mesa-egl' or
'gtk+2.0-maemo, gtk+2.0'.
:param providers: returned dict from providers(), must not be empty
:param pkgname: the package name we are interested in (for the log message)
"""
ret = min(list(providers.keys()), key=len)
if len(providers) != 1:
logging.debug(pkgname + ": has multiple providers (" +
", ".join(providers.keys()) + "), picked shortest: " + ret)
return providers[ret]
def package(args, package, arch=None, must_exist=True, indexes=None):
"""
Get a specific package's data from an apkindex.
@ -362,12 +378,7 @@ def package(args, package, arch=None, must_exist=True, indexes=None):
# Any provider
if package_providers:
provider_pkgname = list(package_providers.keys())[0]
if len(package_providers) != 1:
logging.debug(package + ": provided by multiple packages (" +
", ".join(package_providers) + "), picked " +
provider_pkgname)
return package_providers[provider_pkgname]
return pmb.parse.apkindex.provider_shortest(package_providers, package)
# No provider
if must_exist:

View File

@ -89,11 +89,8 @@ def package_provider(args, pkgname, pkgnames_install, suffix="native"):
" the '" + suffix + "' chroot already")
return provider
# 5. Pick the first one
provider_pkgname = list(providers.keys())[0]
logging.debug(pkgname + " has multiple providers (" +
", ".join(providers) + "), picked: " + provider_pkgname)
return providers[provider_pkgname]
# 5. Pick the provider
return pmb.parse.apkindex.provider_shortest(providers, pkgname)
def package_from_index(args, pkgname_depend, pkgnames_install, package_aport,