From 0fa2e622409767f9855a6a045117cb7b02e5913e Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Tue, 21 Sep 2010 10:16:01 +0400 Subject: [PATCH] Added new option symlink for change current kernel. Refactoring some methods. For named kernel object used _getName, _getNewName, _getSymlink. --- pym/cl_kernel.py | 126 +++++++++++++++++++++++++++++-------------- pym/cl_kernel_cmd.py | 38 ++++++++++--- scripts/cl-builder | 4 ++ scripts/cl-kernel | 3 ++ 4 files changed, 123 insertions(+), 48 deletions(-) diff --git a/pym/cl_kernel.py b/pym/cl_kernel.py index 73306db..f9cb99b 100644 --- a/pym/cl_kernel.py +++ b/pym/cl_kernel.py @@ -142,18 +142,14 @@ class cl_kernel(color_print): suffixName = "genkernel-%(march)s-%(fullver)s"%\ {"march":march, "fullver":kernelFullVer} - fullVerWithoutCalculate = kernelFullVer.replace("-calculate","") - newSuffixName = "%s-%s-%s-installed"%(fullVerWithoutCalculate, - clVars.Get('os_arch_machine'), - clVars.Get('os_linux_shortname')) baseInitrdName = path.join(bootDir,"initramfs-%s"%suffixName) baseKernelName = path.join(bootDir,"kernel-%s"%suffixName) baseSystemMap = path.join(bootDir,"System.map-%s"%suffixName) - newInitrdName = path.join(bootDir,"initramfs-%s"%newSuffixName) - newKernelName = path.join(bootDir,"vmlinuz-%s"%newSuffixName) - newSystemMap = path.join(bootDir,"System.map-%s"%newSuffixName) - newConfigName = path.join(bootDir,"config-%s"%newSuffixName) + newInitrdName = self._getName("initramfs") + newKernelName = self._getName("vmlinuz") + newSystemMap = self._getName("System.map") + newConfigName = self._getName("config") try: os.rename(baseInitrdName,newInitrdName) @@ -163,7 +159,6 @@ class cl_kernel(color_print): except OSError,e: self.printERROR(_("Can not rename kernel files: %s")%e.strerror) return False - return True def _installFile(self,source,target,removeSource=True,symlink=False): @@ -198,16 +193,9 @@ class cl_kernel(color_print): if oldtarget: map(os.unlink,targetLinkFiles) map(lambda x:os.symlink(path.basename(oldtarget),x),targetLinkFiles) - - def installBootFiles(self): - """Copy -install files to without suffix name, and save old copy. - - initramfs, vmlinuz, System.map, config with suffix installed copy - withou suffix. Save old files by append suffix .old. - Search link files boot directory link to oldfiles and fix symlink. - Create link iniramfs-UUID,vmlinuz-UUID,System.map-UUID. - Create initramfs install (copy of initramfs) - """ + def _getName(self,obj): + """Get names for (initramfs,initramfs-install,vmlinuz,System.map, + config) after kernel compilation (installed)""" clVars = self.clVars bootDir = clVars.Get('cl_kernel_boot_path') kernelFullVer = clVars.Get('cl_kernel_full_ver') @@ -215,39 +203,95 @@ class cl_kernel(color_print): suffixName = "%s-%s-%s-installed"%(fullVerWithoutCalculate, clVars.Get('os_arch_machine'), clVars.Get('os_linux_shortname')) + return path.join(bootDir,{"initramfs":"initramfs-%s", + "initramfs-install":"initramfs-%s", + "vmlinuz":"vmlinuz-%s", + "System.map":"System.map-%s", + "config":"config-%s"}[obj]%suffixName) + + def _getNewName(self,obj): + """Get new names for (initramfs,initramfs-install,vmlinuz,System.map, + config) which they have after renaming""" + clVars = self.clVars + bootDir = clVars.Get('cl_kernel_boot_path') + kernelFullVer = clVars.Get('cl_kernel_full_ver') + fullVerWithoutCalculate = kernelFullVer.replace("-calculate","") newSuffixName = "%s-%s-%s"%(fullVerWithoutCalculate, clVars.Get('os_arch_machine'), clVars.Get('os_linux_shortname')) - initrdName = path.join(bootDir,"initramfs-%s"%suffixName) - kernelName = path.join(bootDir,"vmlinuz-%s"%suffixName) - systemMap = path.join(bootDir,"System.map-%s"%suffixName) - configName = path.join(bootDir,"config-%s"%suffixName) - newInitrdName = path.join(bootDir,"initramfs-%s"%newSuffixName) - newInitrdNameInstall = path.join(bootDir, - "initramfs-%s-install"%newSuffixName) - newKernelName = path.join(bootDir,"vmlinuz-%s"%newSuffixName) - newSystemMap = path.join(bootDir,"System.map-%s"%newSuffixName) - newConfigName = path.join(bootDir,"config-%s"%newSuffixName) + return path.join(bootDir,{"initramfs":"initramfs-%s", + "initramfs-install":"initramfs-%s-install", + "vmlinuz":"vmlinuz-%s", + "System.map":"System.map-%s", + "config":"config-%s"}[obj]%newSuffixName) + def _getSymlink(self,obj): + """Get uid symlinks (initramfs,initramfs-install,vmlinuz,System.map) + they pointet to object by _getNewName""" + clVars = self.clVars + bootDir = clVars.Get('cl_kernel_boot_path') kernelUid = clVars.Get('cl_kernel_uid') - symlinkInitrdName = path.join(bootDir,"initrd-%s"%kernelUid) - symlinkInitrdNameInstall = path.join(bootDir, - "initrd-%s-install"%kernelUid) - symlinkKernelName = path.join(bootDir,"vmlinuz-%s"%kernelUid) - symlinkSystemMap = path.join(bootDir,"System.map-%s"%kernelUid) + return path.join(bootDir,{"initramfs":"initrd-%s", + "initramfs-install":"initrd-%s-install", + "vmlinuz":"vmlinuz-%s", + "System.map":"System.map-%s"}[obj]%kernelUid) + + def createUidSymlinks(self): + """Create link iniramfs-UUID,vmlinuz-UUID,System.map-UUID.""" + if self.skipByChrootAndShortname(): + return True + newInitrdName = self._getNewName("initramfs") + newInitrdNameInstall = self._getNewName("initramfs-install") + newKernelName = self._getNewName("vmlinuz") + newSystemMap = self._getNewName("System.map") + symlinkInitrdName = self._getSymlink("initramfs") + symlinkInitrdNameInstall = self._getSymlink("initramfs-install") + symlinkKernelName = self._getSymlink("vmlinuz") + symlinkSystemMap = self._getSymlink("System.map") + + try: + self._installFile(newInitrdName,symlinkInitrdName, symlink=True) + self._installFile(newInitrdNameInstall,symlinkInitrdNameInstall, + symlink=True) + self._installFile(newKernelName,symlinkKernelName, symlink=True) + self._installFile(newSystemMap, symlinkSystemMap, symlink=True) + except IOError,e: + self.printERROR( + _("Can not create symlink to current kernel: %s '%s'")% + (e.strerror,e.filename)) + self.printERROR(_("May be kernel was not compiled")) + return False + except OSError,e: + self.printERROR(_("Can not create symlink to current kernel: %s")% + e.strerror) + return False + return True + + + def installBootFiles(self): + """Copy -install files to without suffix name, and save old copy. + + initramfs, vmlinuz, System.map, config with suffix installed copy + withou suffix. Save old files by append suffix .old. + Search link files boot directory link to oldfiles and fix symlink. + Create initramfs install (copy of initramfs) + """ + initrdName = self._getName("initramfs") + kernelName = self._getName("vmlinuz") + systemMap = self._getName("System.map") + configName = self._getName("config") + newInitrdName = self._getNewName("initramfs") + newInitrdNameInstall = self._getNewName("initramfs-install") + newKernelName = self._getNewName("vmlinuz") + newSystemMap = self._getNewName("System.map") + newConfigName = self._getNewName("config") + try: self._installFile(initrdName,newInitrdName,removeSource=False) self._installFile(initrdName,newInitrdNameInstall) self._installFile(kernelName,newKernelName) self._installFile(systemMap,newSystemMap) self._installFile(configName,newConfigName) - - if not self.skipByChrootAndShortname(): - self._installFile(newInitrdName,symlinkInitrdName, symlink=True) - self._installFile(newInitrdNameInstall,symlinkInitrdNameInstall, - symlink=True) - self._installFile(newKernelName,symlinkKernelName, symlink=True) - self._installFile(newSystemMap, symlinkSystemMap, symlink=True) except (OSError,IOError),e: self.printERROR(_("Can not install kernel files: %s")%e.strerror) return False diff --git a/pym/cl_kernel_cmd.py b/pym/cl_kernel_cmd.py index ee70bc2..6b5b4c0 100644 --- a/pym/cl_kernel_cmd.py +++ b/pym/cl_kernel_cmd.py @@ -71,7 +71,11 @@ CMD_OPTIONS = [{'shortOption':"c", {'longOption':"initrd", 'help':_("perform current initramfs optimization")}, {'longOption':"ebuild", - 'help':_("build kernel by ebuild phase (need ebuild enviroment)")} + 'help': + _("build kernel by ebuild phase (need ebuild enviroment)")}, + {'longOption':"symlink", + 'help': + _("set uid symlinks for current kernel in boot directory")} ] @@ -86,7 +90,10 @@ class kernel_cmd(share_cmd): check_values=self.checkOpts) self.logicObj = cl_kernel() self.optionsInitrdIncompatible = ["o","no_clean","m","mdadm","lvm", - "k", "e","dmraid","c" ] + "k", "e","dmraid","c","ebuild", + "symlink"] + self.optionsSymlinkIncompatible = ["o","no_clean","m","mdadm","lvm", + "e","dmraid","c","ebuild","initrd" ] def _getNamesAllSetOptions(self): """Get list set options""" @@ -101,13 +108,14 @@ class kernel_cmd(share_cmd): return ", ".join(map(lambda x: len(x) == 1 and "'-%s'"%x or "'--%s'"%x, listOpt)) - def checkIncompatibleInitrd(self): - """Check incompatible options for option --live""" + def checkIncompatibleParam(self,param): + """Check incompatible options for option specified by param""" incompatible = list(set(self._getNamesAllSetOptions()) & - set(self.optionsInitrdIncompatible)) + set(getattr(self,"options%sIncompatible"% + param.capitalize()))) if incompatible: self.optobj.error(_("incompatible options")+":"+" %s"\ - %self.getStringIncompatibleOptions(incompatible+["initrd"])) + %self.getStringIncompatibleOptions(incompatible+[param])) def checkEnviromentForEbuild(self): """Check current enviroment for ebuild enviroment variables""" @@ -125,7 +133,9 @@ class kernel_cmd(share_cmd): if values.ebuild: self.checkEnviromentForEbuild() if values.initrd: - self.checkIncompatibleInitrd() + self.checkIncompatibleParam("initrd") + if values.symlink: + self.checkIncompatibleParam("symlink") if values.k: if not self.logicObj._testKernelDirectory(values.k): self.optobj.error("%s:'%s'"% @@ -187,6 +197,9 @@ class kernel_cmd(share_cmd): if not self.logicObj.installBootFiles(): self.printERROR(_("Failed kernel install")) return False + if not self.logicObj.createUidSymlinks(): + self.printERROR(_("Failed create uid symlinks")) + return False if not self.logicObj.versionMigrate(): self.printERROR(_("Failed kernel nomenclature update")) return False @@ -196,3 +209,14 @@ class kernel_cmd(share_cmd): self.printWARNING(_("Failed change '%s'")%"/usr/scr/linux") return True + def makeSymlink(self,options): + """Set specified kernel to default""" + if not self.logicObj.createUidSymlinks(): + self.printERROR(_("Failed create uid symlinks")) + return False + if not self.logicObj.setKernelForCurrent(): + self.printWARNING(_("Failed change '%s'")%"/usr/scr/linux") + return False + self.printSUCCESS(_("Kernel was changed to '%s'")% + path.basename(self.logicObj._getNewName("vmlinuz"))) + return True diff --git a/scripts/cl-builder b/scripts/cl-builder index 966e382..58da0b7 100644 --- a/scripts/cl-builder +++ b/scripts/cl-builder @@ -187,6 +187,7 @@ try_update_file() { # same files in the second directory #------------------------------------------------------------------------------ update_from_builder() { + waschange= basesrc=${1%/} basedest=${2%/} shift 2 @@ -199,8 +200,11 @@ update_from_builder() { do dstfile=${dest}/${srcfile#${src}/} try_update_file $srcfile $dstfile + waschange=1 done done + [[ -n $waschange ]] && \ + echo "For used the new kernel in the workspace perform 'cl-kernel --symlink'." } update_from_builder $BUILDER $ROOTDIR $UPDATE_DIRS diff --git a/scripts/cl-kernel b/scripts/cl-kernel index e8da802..c06aed7 100644 --- a/scripts/cl-kernel +++ b/scripts/cl-kernel @@ -52,6 +52,9 @@ if __name__ == "__main__": if options.initrd: kernel.cleanInitrd(options) + elif options.symlink: + if not kernel.makeSymlink(options): + sys.exit(1) elif not kernel.makeKernel(options): sys.exit(1)