refactor: move big code chunks from Lorax.run to installtree
Move package removal code to installtree.remove_package and the module install loop to installtree.install_kernel_modules.
This commit is contained in:
parent
a82da40015
commit
051af505ae
@ -221,7 +221,7 @@ class Lorax(BaseLoraxClass):
|
||||
buildstamp.write()
|
||||
shutil.copy2(buildstamp.path, self.installtree.root)
|
||||
|
||||
# DEBUG save list of installed packages
|
||||
logger.debug("saving pkglists to %s", self.workdir)
|
||||
dname = joinpaths(self.workdir, "pkglists")
|
||||
os.makedirs(dname)
|
||||
for pkgname, pkgobj in self.installtree.yum.installed_packages.items():
|
||||
@ -245,23 +245,11 @@ class Lorax(BaseLoraxClass):
|
||||
# Need a list to pass to cleanup_kernel_modules, not a generator
|
||||
modules = list(template.getdata("module"))
|
||||
|
||||
self.installtree.move_modules()
|
||||
self.installtree.install_kernel_modules(modules)
|
||||
|
||||
for kernel in self.installtree.kernels:
|
||||
logger.info("cleaning up kernel modules")
|
||||
self.installtree.cleanup_kernel_modules(modules, kernel)
|
||||
|
||||
logger.info("compressing modules")
|
||||
self.installtree.compress_modules(kernel)
|
||||
|
||||
logger.info("running depmod")
|
||||
self.installtree.run_depmod(kernel)
|
||||
|
||||
# move repos
|
||||
logger.info("moving anaconda repos")
|
||||
self.installtree.move_repos()
|
||||
|
||||
# create depmod conf
|
||||
logger.info("creating depmod.conf")
|
||||
self.installtree.create_depmod_conf()
|
||||
|
||||
@ -310,36 +298,7 @@ class Lorax(BaseLoraxClass):
|
||||
|
||||
logger.info("getting list of not required packages")
|
||||
remove = template.getdata("remove", mode="lines")
|
||||
|
||||
rdb = {}
|
||||
order = []
|
||||
for item in remove:
|
||||
package = None
|
||||
pattern = None
|
||||
|
||||
if item[0] == "--path":
|
||||
# remove files
|
||||
package = None
|
||||
pattern = item[1]
|
||||
else:
|
||||
# remove package
|
||||
package = item[0]
|
||||
|
||||
try:
|
||||
pattern = item[1]
|
||||
except IndexError:
|
||||
pattern = None
|
||||
|
||||
if package not in rdb:
|
||||
rdb[package] = [pattern]
|
||||
order.append(package)
|
||||
elif pattern not in rdb[package]:
|
||||
rdb[package].append(pattern)
|
||||
|
||||
for package in order:
|
||||
pattern_list = rdb[package]
|
||||
logger.debug("{0}\t{1}".format(package, pattern_list))
|
||||
self.installtree.yum.remove(package, pattern_list)
|
||||
self.installtree.remove_packages(remove)
|
||||
|
||||
# cleanup python files
|
||||
logger.info("cleaning up python files")
|
||||
|
@ -130,6 +130,37 @@ class LoraxInstallTree(BaseLoraxClass):
|
||||
dst = joinpaths(path, "site-packages")
|
||||
shutil.move(src, dst)
|
||||
|
||||
def remove_packages(self, remove):
|
||||
rdb = {}
|
||||
order = []
|
||||
for item in remove:
|
||||
package = None
|
||||
pattern = None
|
||||
|
||||
if item[0] == "--path":
|
||||
# remove files
|
||||
package = None
|
||||
pattern = item[1]
|
||||
else:
|
||||
# remove package
|
||||
package = item[0]
|
||||
|
||||
try:
|
||||
pattern = item[1]
|
||||
except IndexError:
|
||||
pattern = None
|
||||
|
||||
if package not in rdb:
|
||||
rdb[package] = [pattern]
|
||||
order.append(package)
|
||||
elif pattern not in rdb[package]:
|
||||
rdb[package].append(pattern)
|
||||
|
||||
for package in order:
|
||||
pattern_list = rdb[package]
|
||||
logger.debug("{0}\t{1}".format(package, pattern_list))
|
||||
self.yum.remove(package, pattern_list)
|
||||
|
||||
def cleanup_python_files(self):
|
||||
for root, _, fnames in os.walk(self.root):
|
||||
for fname in fnames:
|
||||
@ -153,6 +184,7 @@ class LoraxInstallTree(BaseLoraxClass):
|
||||
os.symlink("../firmware", joinpaths(self.root, "lib/firmware"))
|
||||
|
||||
def cleanup_kernel_modules(self, keepmodules, kernel):
|
||||
logger.info("cleaning up kernel modules for %s", kernel.version)
|
||||
moddir = joinpaths(self.root, "modules", kernel.version)
|
||||
fwdir = joinpaths(self.root, "firmware")
|
||||
|
||||
@ -281,6 +313,7 @@ class LoraxInstallTree(BaseLoraxClass):
|
||||
fobj.write(modlist[modname])
|
||||
|
||||
def compress_modules(self, kernel):
|
||||
logger.debug("compressing modules for %s", kernel.version)
|
||||
moddir = joinpaths(self.root, "modules", kernel.version)
|
||||
|
||||
for root, _, fnames in os.walk(moddir):
|
||||
@ -296,6 +329,7 @@ class LoraxInstallTree(BaseLoraxClass):
|
||||
os.unlink(path)
|
||||
|
||||
def run_depmod(self, kernel):
|
||||
logger.debug("running depmod for %s", kernel.version)
|
||||
systemmap = "System.map-{0.version}".format(kernel)
|
||||
systemmap = joinpaths(self.root, "boot", systemmap)
|
||||
|
||||
@ -536,6 +570,13 @@ class LoraxInstallTree(BaseLoraxClass):
|
||||
|
||||
return True, elapsed
|
||||
|
||||
def install_kernel_modules(self, keepmodules):
|
||||
self.move_modules()
|
||||
for kernel in self.kernels:
|
||||
self.cleanup_kernel_modules(keepmodules, kernel)
|
||||
self.compress_modules(kernel)
|
||||
self.run_depmod(kernel)
|
||||
|
||||
@property
|
||||
def kernels(self):
|
||||
kerneldir = "boot"
|
||||
|
Loading…
Reference in New Issue
Block a user