treebuilder: improve findkernels() initrd search

This makes findkernels() look for any image named something like:

  $PREFIX-$KERNELVER.img

and adds a corresponding entry to its returned data like:

  kernel.$PREFIX.path = [path]

As a special backwards-compatibility case we use 'initrd' for the
attribute name if $PREFIX is 'initramfs'.

This gives us any extra initramfs images that may have been built using
the 'prefix' argument to rebuild_initrds().
This commit is contained in:
Will Woods 2012-11-13 01:33:15 -05:00 committed by Dennis Gilmore
parent 5b48574d5e
commit 1c91eab12b
1 changed files with 10 additions and 7 deletions

View File

@ -266,20 +266,23 @@ def findkernels(root="/", kdir="boot"):
kre = re.compile(r"vmlinuz-(?P<version>.+?\.(?P<arch>[a-z0-9_]+)" kre = re.compile(r"vmlinuz-(?P<version>.+?\.(?P<arch>[a-z0-9_]+)"
r"(\.(?P<flavor>{0}))?)$".format("|".join(flavors))) r"(\.(?P<flavor>{0}))?)$".format("|".join(flavors)))
kernels = [] kernels = []
for f in os.listdir(joinpaths(root, kdir)): bootfiles = os.listdir(joinpaths(root, kdir))
for f in bootfiles:
match = kre.match(f) match = kre.match(f)
if match: if match:
kernel = DataHolder(path=joinpaths(kdir, f)) kernel = DataHolder(path=joinpaths(kdir, f))
kernel.update(match.groupdict()) # sets version, arch, flavor kernel.update(match.groupdict()) # sets version, arch, flavor
kernels.append(kernel) kernels.append(kernel)
# look for associated initrd/initramfs # look for associated initrd/initramfs/etc.
for kernel in kernels: for kernel in kernels:
# NOTE: if both exist, the last one found will win for f in bootfiles:
for imgname in ("initrd", "initramfs"): if f.endswith('-'+kernel.version+'.img'):
i = kernel.path.replace("vmlinuz", imgname, 1) + ".img" imgtype, rest = f.split('-',1)
if os.path.exists(joinpaths(root, i)): # special backwards-compat case
kernel.initrd = DataHolder(path=i) if imgtype == 'initramfs':
imgtype = 'initrd'
kernel[imgtype] = DataHolder(path=joinpaths(kdir, f))
return kernels return kernels