Пример #1
0
 def _installFile(self,source,target,removeSource=True,symlink=False):
     """Copy, move or create symlink source file to target. Save old."""
     def getLinkForTarget(target):
         """Get symlinks from target dirname which point to target"""
         baseDir = path.dirname(path.normpath(target))
         linkFiles = filter(path.islink,map(lambda x:path.join(baseDir,x),
                                            os.listdir(baseDir)))
         return filter(lambda x:path.join(baseDir,
                                   os.readlink(x))==target, linkFiles)
     # raise IOError if source is not exists
     open(source,'r').close()
     targetLinkFiles = getLinkForTarget(target)
     oldtarget = ""
     if path.lexists(target):
         oldtarget = "%s.old" % target
         if path.lexists(oldtarget):
             oldTargetLinkFiles = getLinkForTarget(oldtarget)
             map(os.unlink,oldTargetLinkFiles)
             os.unlink(oldtarget)
         os.rename(target,oldtarget)
     if symlink:
         if path.dirname(source)==path.dirname(target):
             os.symlink(path.basename(source),target)
         else:
             os.symlink(source,target)
     elif removeSource:
         os.rename(source,target)
     else:
         copy_with_perm(source,target)
     if oldtarget:
         map(os.unlink,targetLinkFiles)
         map(lambda x:os.symlink(path.basename(oldtarget),x),targetLinkFiles)
Пример #2
0
    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