forked from Mirror/pmbootstrap
pmb.helpers.pmaports: glob just once (!1898)
This commit is contained in:
parent
9d17ed29e3
commit
cd630edf25
3 changed files with 37 additions and 47 deletions
|
@ -131,8 +131,6 @@ def add_cache(args):
|
||||||
"find_aport": {},
|
"find_aport": {},
|
||||||
"pmb.helpers.package.depends_recurse": {},
|
"pmb.helpers.package.depends_recurse": {},
|
||||||
"pmb.helpers.package.get": {},
|
"pmb.helpers.package.get": {},
|
||||||
"pmb.helpers.pmaports._glob_apkbuilds": {},
|
|
||||||
"pmb.helpers.pmaports.get_list": {},
|
|
||||||
"pmb.helpers.repo.update": repo_update})
|
"pmb.helpers.repo.update": repo_update})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -247,11 +247,12 @@ def kconfig(args):
|
||||||
|
|
||||||
# Default to all kernel packages
|
# Default to all kernel packages
|
||||||
packages = []
|
packages = []
|
||||||
if args.package == "" or args.package is None:
|
if args.package:
|
||||||
for aport in pmb.helpers.pmaports.get_list(args, "linux-*"):
|
|
||||||
packages.append(aport.split("linux-")[1])
|
|
||||||
else:
|
|
||||||
packages = [args.package]
|
packages = [args.package]
|
||||||
|
else:
|
||||||
|
for aport in pmb.helpers.pmaports.get_list(args):
|
||||||
|
if aport.startswith("linux-"):
|
||||||
|
packages.append(aport.split("linux-")[1])
|
||||||
|
|
||||||
# Iterate over all kernels
|
# Iterate over all kernels
|
||||||
error = False
|
error = False
|
||||||
|
|
|
@ -12,34 +12,32 @@ import os
|
||||||
import pmb.parse
|
import pmb.parse
|
||||||
|
|
||||||
|
|
||||||
def _glob_apkbuilds(args, pkgname='*'):
|
def _find_apkbuilds(args):
|
||||||
# Try to get a cached result first (we assume, that the aports don't change
|
# Try to get a cached result first (we assume, that the aports don't change
|
||||||
# in one pmbootstrap call)
|
# in one pmbootstrap call)
|
||||||
if pkgname in args.cache["pmb.helpers.pmaports._glob_apkbuilds"]:
|
apkbuilds = args.cache.get("pmb.helpers.pmaports.apkbuilds")
|
||||||
return args.cache["pmb.helpers.pmaports._glob_apkbuilds"][pkgname]
|
if apkbuilds is not None:
|
||||||
|
return apkbuilds
|
||||||
|
|
||||||
ret = glob.glob(args.aports + "/**/" + pkgname + "/APKBUILD", recursive=True)
|
apkbuilds = {}
|
||||||
|
for apkbuild in glob.iglob(f"{args.aports}/**/*/APKBUILD", recursive=True):
|
||||||
|
package = os.path.basename(os.path.dirname(apkbuild))
|
||||||
|
if package in apkbuilds:
|
||||||
|
raise RuntimeError(f"Package {package} found in multiple aports "
|
||||||
|
"subfolders. Please put it only in one folder.")
|
||||||
|
apkbuilds[package] = apkbuild
|
||||||
|
|
||||||
|
# Sort dictionary so we don't need to do it over and over again in get_list()
|
||||||
|
apkbuilds = dict(sorted(apkbuilds.items()))
|
||||||
|
|
||||||
# Save result in cache
|
# Save result in cache
|
||||||
args.cache["pmb.helpers.pmaports._glob_apkbuilds"][pkgname] = ret
|
args.cache["pmb.helpers.pmaports.apkbuilds"] = apkbuilds
|
||||||
return ret
|
return apkbuilds
|
||||||
|
|
||||||
|
|
||||||
def get_list(args, pkgname='*'):
|
def get_list(args):
|
||||||
""" :returns: list of all pmaport pkgnames (["hello-world", ...]) """
|
""" :returns: list of all pmaport pkgnames (["hello-world", ...]) """
|
||||||
# Try to get a cached result first (we assume, that the aports don't change
|
return list(_find_apkbuilds(args).keys())
|
||||||
# in one pmbootstrap call)
|
|
||||||
if pkgname in args.cache["pmb.helpers.pmaports.get_list"]:
|
|
||||||
return args.cache["pmb.helpers.pmaports.get_list"][pkgname]
|
|
||||||
|
|
||||||
ret = []
|
|
||||||
for apkbuild in _glob_apkbuilds(args, pkgname):
|
|
||||||
ret.append(os.path.basename(os.path.dirname(apkbuild)))
|
|
||||||
ret.sort()
|
|
||||||
|
|
||||||
# Save result in cache
|
|
||||||
args.cache["pmb.helpers.pmaports.get_list"][pkgname] = ret
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def guess_main_dev(args, subpkgname):
|
def guess_main_dev(args, subpkgname):
|
||||||
|
@ -52,12 +50,11 @@ def guess_main_dev(args, subpkgname):
|
||||||
:returns: full path to the pmaport or None
|
:returns: full path to the pmaport or None
|
||||||
"""
|
"""
|
||||||
pkgname = subpkgname[:-4]
|
pkgname = subpkgname[:-4]
|
||||||
if pkgname in get_list(args):
|
path = _find_apkbuilds(args).get(pkgname)
|
||||||
paths = _glob_apkbuilds(args, pkgname)
|
if path:
|
||||||
if paths:
|
|
||||||
logging.debug(subpkgname + ": guessed to be a subpackage of " +
|
logging.debug(subpkgname + ": guessed to be a subpackage of " +
|
||||||
pkgname + " (just removed '-dev')")
|
pkgname + " (just removed '-dev')")
|
||||||
return os.path.dirname(paths[0])
|
return os.path.dirname(path)
|
||||||
|
|
||||||
logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname +
|
logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname +
|
||||||
", which we can't find in pmaports, so it's probably in"
|
", which we can't find in pmaports, so it's probably in"
|
||||||
|
@ -95,12 +92,11 @@ def guess_main(args, subpkgname):
|
||||||
pkgname = "-".join(words)
|
pkgname = "-".join(words)
|
||||||
|
|
||||||
# Look in pmaports
|
# Look in pmaports
|
||||||
if pkgname in get_list(args):
|
path = _find_apkbuilds(args).get(pkgname)
|
||||||
paths = _glob_apkbuilds(args, pkgname)
|
if path:
|
||||||
if paths:
|
|
||||||
logging.debug(subpkgname + ": guessed to be a subpackage of " +
|
logging.debug(subpkgname + ": guessed to be a subpackage of " +
|
||||||
pkgname)
|
pkgname)
|
||||||
return os.path.dirname(paths[0])
|
return os.path.dirname(path)
|
||||||
|
|
||||||
|
|
||||||
def find(args, package, must_exist=True):
|
def find(args, package, must_exist=True):
|
||||||
|
@ -122,18 +118,13 @@ def find(args, package, must_exist=True):
|
||||||
raise RuntimeError("Invalid pkgname: " + package)
|
raise RuntimeError("Invalid pkgname: " + package)
|
||||||
|
|
||||||
# Search in packages
|
# Search in packages
|
||||||
if package in get_list(args):
|
path = _find_apkbuilds(args).get(package)
|
||||||
paths = _glob_apkbuilds(args, package)
|
if path:
|
||||||
if len(paths) > 1:
|
ret = os.path.dirname(path)
|
||||||
raise RuntimeError("Package " + package + " found in multiple"
|
|
||||||
" aports subfolders. Please put it only in one"
|
|
||||||
" folder.")
|
|
||||||
elif len(paths) == 1:
|
|
||||||
ret = os.path.dirname(paths[0])
|
|
||||||
|
|
||||||
# Search in subpackages and provides
|
# Search in subpackages and provides
|
||||||
if not ret:
|
if not ret:
|
||||||
for path_current in _glob_apkbuilds(args):
|
for path_current in _find_apkbuilds(args).values():
|
||||||
apkbuild = pmb.parse.apkbuild(args, path_current)
|
apkbuild = pmb.parse.apkbuild(args, path_current)
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue