def initVars(self): """Primary initialization of variables""" self.clVars = DataVarsBuilder() self.clVars.importBuilder() self.clVars.flIniFile()
class cl_kernel(color_print): """Primary class for kernel manipulation""" kernelCurPath = '/usr/src/linux' def __init__(self): self.clVars = None self.startMessage = "" def _testKernelDirectory(self,dirpath): """Test directory for kernel sources""" makefilepath = path.join(dirpath,'Makefile') kbuildpath = path.join(dirpath,'Kbuild') if path.exists(makefilepath) \ and path.exists(kbuildpath) \ and "Kbuild for top-level directory of the kernel" in \ open(kbuildpath,'r').read(): return True return False def _testFullKernelDirectory(self,dirpath): """To check the directory for full kernel sources Kernel may be installed with minimal (later vmlinuz) flag""" documentationPath = path.join(dirpath,'Documentation') driversPath = path.join(dirpath,'drivers') if path.exists(documentationPath) \ and path.exists(driversPath): return True return False def setNoColor(self): self.color = False def initVars(self): """Primary initialization of variables""" self.clVars = DataVarsBuilder() self.clVars.importBuilder() self.clVars.flIniFile() def makeKernel(self,quiet=True,showMenuConfig=False,noClean=False, lvmOpt=False,dmraidOpt=False,mdadmOpt=False, mrproper=False,target="all"): """Run kernel compilation""" clVars = self.clVars themeName = "calculate" standardParams = ["--splash=%s"%themeName, "--unionfs", "--all-ramdisk-modules","--disklabel", "--no-save-config", "--firmware","--udev", "--lspci"] kernelDir = ["--kerneldir=%s"%clVars.Get('cl_kernel_src_path')] kernelDestination = clVars.Get('cl_kernel_install_path') modulePrefix = ["--module-prefix=%s"%kernelDestination] if not path.exists(kernelDestination): self.printERROR("Not found destination directory '%s'"% kernelDestination) return False logLevel = ["--loglevel=%d"%(1 if quiet else 2)] makeOpts = clVars.Get('os_builder_makeopts') if makeOpts: makeOpts = ["--makeopts=%s"%makeOpts] else: makeOpts = [] menuConfig = ["--menuconfig"] if showMenuConfig else [] noClean = ["--no-clean"] if noClean else [] bootDir = clVars.Get('cl_kernel_boot_path') if not path.exists(bootDir): os.makedirs(bootDir,mode=0755) bootDir = ["--bootdir=%s"%bootDir] lvmOpt = ["--lvm"] if lvmOpt else [] dmraidOpt = ["--dmraid"] if dmraidOpt else [] mdadmOpt = ["--mdadm"] if mdadmOpt else [] mrproperOpt = ["--mrproper"] if mrproper else ["--no-mrproper"] stdConfigPath = \ path.join(clVars.Get('cl_kernel_src_path'), ".config") if clVars.Get('cl_kernel_config') == stdConfigPath: kernelConfig = [] if mrproper: self.printERROR(_("Cannot use the current kernel configuration" " with option'%s'")% "--mrproper") return False else: kernelConfig = ["--kernel-config=%s"%clVars.Get('cl_kernel_config')] kernelName = ["--kernname=%s"%clVars.Get('os_linux_system')] cachedir = ["--cachedir=%s"%clVars.Get('cl_kernel_cache_path')] tempdir = ["--tempdir=%s"%clVars.Get('cl_kernel_temp_path')] params = ["genkernel"]+cachedir+tempdir+\ standardParams+kernelDir+modulePrefix+\ logLevel+makeOpts+menuConfig+noClean+kernelConfig+\ bootDir+lvmOpt+dmraidOpt+mdadmOpt+mrproperOpt+[target] try: genkernelProcess = process(*params,stdout=None,stderr=STDOUT, stdin=None,envdict=os.environ) return genkernelProcess.success() except KeyboardInterrupt: self.printERROR("Keyboard interrupt") return False def prepareBoot(self): """Rename received by genkernel files""" clVars = self.clVars bootDir = clVars.Get('cl_kernel_boot_path') if not os.access(bootDir,os.W_OK): self.printERROR(_("No permission to write to '%s'")% bootDir) return False march = clVars.Get('os_arch_machine') if re.match("^i.86$",march): march = "x86" baseConfigName = path.join(clVars.Get('cl_kernel_src_path'), ".config") if path.exists(baseConfigName): clVars.Set('cl_kernel_config',baseConfigName,True) kernelFullVer = clVars.Get('cl_kernel_full_ver') suffixName = "genkernel-%(march)s-%(fullver)s"%\ {"march":march, "fullver":kernelFullVer} baseInitrdName = path.join(bootDir,"initramfs-%s"%suffixName) baseKernelName = path.join(bootDir,"kernel-%s"%suffixName) baseSystemMap = path.join(bootDir,"System.map-%s"%suffixName) newInitrdName = self._getName("initramfs") newKernelName = self._getName("vmlinuz") newSystemMap = self._getName("System.map") newConfigName = self._getName("config") try: os.rename(baseInitrdName,newInitrdName) os.rename(baseKernelName,newKernelName) os.rename(baseSystemMap,newSystemMap) copy_with_perm(baseConfigName,newConfigName) except OSError,e: self.printERROR(_("Failed to rename kernel files: %s")%e.strerror) return False return True