Пример #1
0
    def getInitrd(self,arch,shortname,chroot,kernel,suffix="",notsuffix=""):
        """Get initrd for kernel"""
        reInitrdVer = re.compile("(initrd|initramfs)-(.+?)(-install)?$",re.S)
        def initrd_version_by_name(filename):
            resInitrdVer = reInitrdVer.search(filename)
            if resInitrdVer:
                return resInitrdVer.groups()[1]
            return ""

        ftype = typeFile(magic=0x4).getMType
        kernelfile = path.join(chroot,'boot',kernel)
        typeKernelFile = ftype(kernelfile)
        if typeKernelFile == None:
            return ""
        resKernelVer = self.reFindVer.search(ftype(kernelfile))
        if resKernelVer:
            kernelVersion = "%s-%s-%s"% \
               (resKernelVer.group().replace('-calculate',''),
                arch, shortname)
            origKernelVer = resKernelVer.group()

            bootdir = path.join(chroot,'boot')
            initramfsFiles = self.getFilesByType(bootdir,"ASCII cpio archive")
            initramfsWithVer = \
                    filter(lambda x: (kernelVersion in x[1] or 
                              origKernelVer in x[1]) and \
                              x[0].endswith(suffix) and \
                              (not notsuffix or not x[0].endswith(notsuffix)),
                           map(lambda x:(x[0],initrd_version_by_name(x[0])),
                           initramfsFiles))
            if initramfsWithVer:
                return path.split(min(initramfsWithVer,
                                     key=itemgetter(0))[0])[-1]
        return ""
Пример #2
0
 def _processConfig(self,configFile):
     fileType = typeFile().getMType(configFile).partition(';')[0].strip()
     if fileType == "application/x-gzip":
         config = gzip.open(configFile)
     else:
         config = open(configFile,'r')
     reEmptyString = re.compile("^(#\s*|\s*)$")
     # discard empty strings
     data = filter(lambda x:not reEmptyString.match(x),config.readlines())
     # convert param names
     data = map(lambda x:x.strip().replace("=y","=Y"
                 ).replace("=m","=M"
                 ).replace(" is not set","=N"), data)
     # fix data
     data = ["# Root"]+map(lambda x: x[2:] if "=N" in x else x,data)[3:]
     
     config = []
     curSect = None
     for line in data:
         if line.startswith('#'):
             curSect = line[2:]
         else:
             config.append([curSect]+line.split('='))
     return config
Пример #3
0
 def getFilesByType(self,pathname,descr):
     """Get files from "pathname" has "descr" in descriptions"""
     filelist = map(lambda x:path.join(pathname,x),os.listdir(pathname))
     ftype = typeFile(magic=0x4).getMType
     filesWithType = map(lambda x:(x,ftype(x)), filelist)
     return filter(lambda x:descr in x[1],filesWithType)