|
|
|
@ -20,9 +20,12 @@ import cl_overriding
|
|
|
|
|
from cl_datavars import glob_attr
|
|
|
|
|
from os.path import join as pathjoin, exists as pathexists
|
|
|
|
|
from os import readlink,listdir,access,R_OK
|
|
|
|
|
from cl_utils import isMount
|
|
|
|
|
from cl_utils import isMount,typeFile,getTupleVersion
|
|
|
|
|
from cl_distr import DistributiveRepository
|
|
|
|
|
from cl_fill import clLocale
|
|
|
|
|
from operator import itemgetter
|
|
|
|
|
from cl_template import _terms
|
|
|
|
|
from subprocess import PIPE, Popen
|
|
|
|
|
|
|
|
|
|
class fillVars(object, glob_attr):
|
|
|
|
|
nonTransferedDirs = ["/","/bin", "/dev", "/etc",
|
|
|
|
@ -732,6 +735,12 @@ class fillVars(object, glob_attr):
|
|
|
|
|
else:
|
|
|
|
|
return self.Get('os_root_type')
|
|
|
|
|
|
|
|
|
|
def get_os_install_dev_from(self):
|
|
|
|
|
if self.Get('os_root_type') == "hdd":
|
|
|
|
|
return self.Get('os_root_dev')
|
|
|
|
|
else:
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def get_os_install_makeopts(self):
|
|
|
|
|
"""Get makeopts for make.conf file"""
|
|
|
|
|
cpunum = self.Get('hr_cpu_num')
|
|
|
|
@ -739,3 +748,78 @@ class fillVars(object, glob_attr):
|
|
|
|
|
return "-j1"
|
|
|
|
|
else:
|
|
|
|
|
return "-j%d"%(cpunum+1)
|
|
|
|
|
|
|
|
|
|
reFindVer = re.compile(
|
|
|
|
|
"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)")
|
|
|
|
|
|
|
|
|
|
def getFilesByType(self,path,descr):
|
|
|
|
|
"""Get files from "path" has "descr" in descriptions"""
|
|
|
|
|
filelist = map(lambda x:pathjoin(path,x),os.listdir(path))
|
|
|
|
|
ftype = typeFile(magic=0x4).getMType
|
|
|
|
|
filesWithType = map(lambda x:(x,ftype(x)), filelist)
|
|
|
|
|
return filter(lambda x:descr in x[1],filesWithType)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_os_install_kernel(self):
|
|
|
|
|
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
|
|
|
|
|
modulesdir = pathjoin(self.Get('cl_chroot_path'),'lib/modules')
|
|
|
|
|
validKernel = os.listdir(modulesdir)
|
|
|
|
|
kernelFiles = self.getFilesByType(bootdir,"Linux kernel")
|
|
|
|
|
kernelsWithVer = \
|
|
|
|
|
map(lambda x:(x[0],getTupleVersion("".join(x[1].groups()[0:3:2]))),
|
|
|
|
|
filter(lambda x:x[1] and x[1].group() in validKernel,
|
|
|
|
|
map(lambda x:(x[0],self.reFindVer.search(x[1])),
|
|
|
|
|
kernelFiles)))
|
|
|
|
|
if kernelsWithVer:
|
|
|
|
|
return os.path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
|
|
|
|
|
else:
|
|
|
|
|
return "vmlinuz"
|
|
|
|
|
|
|
|
|
|
def getInitrd(self,suffix=""):
|
|
|
|
|
"""Get initrd for kernel"""
|
|
|
|
|
#def initrd_version_by_content(filename):
|
|
|
|
|
# p1 = Popen(["/bin/gzip","-dc",filename],stdout=PIPE,stderr=PIPE)
|
|
|
|
|
# p2 = Popen(["/bin/cpio","-tf"],stdin=p1.stdout,stdout=PIPE,
|
|
|
|
|
# stderr=PIPE)
|
|
|
|
|
# result = filter(lambda x: "lib/modules/" in x,
|
|
|
|
|
# p2.communicate()[0].split('\n'))
|
|
|
|
|
# if result:
|
|
|
|
|
# splitresult = result[0].split('/')
|
|
|
|
|
# if len(splitresult)>2:
|
|
|
|
|
# return splitresult[2]
|
|
|
|
|
# return ""
|
|
|
|
|
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 = pathjoin(self.Get('cl_chroot_path'),'/boot',
|
|
|
|
|
self.Get('os_install_kernel'))
|
|
|
|
|
resKernelVer = self.reFindVer.search(ftype(kernelfile))
|
|
|
|
|
if resKernelVer:
|
|
|
|
|
kernelVersion = resKernelVer.group()
|
|
|
|
|
|
|
|
|
|
bootdir = pathjoin(self.Get('cl_chroot_path'),'boot')
|
|
|
|
|
initramfsFiles = self.getFilesByType(bootdir,"ASCII cpio archive")
|
|
|
|
|
initramfsWithVer = \
|
|
|
|
|
filter(lambda x: x[1] == kernelVersion and \
|
|
|
|
|
x[0].endswith(suffix),
|
|
|
|
|
map(lambda x:(x[0],initrd_version_by_name(x[0])),
|
|
|
|
|
initramfsFiles))
|
|
|
|
|
if initramfsWithVer:
|
|
|
|
|
return os.path.split(min(initramfsWithVer,
|
|
|
|
|
key=itemgetter(0))[0])[-1]
|
|
|
|
|
if suffix:
|
|
|
|
|
return "initrd-%s"%suffix
|
|
|
|
|
else:
|
|
|
|
|
return "initrd"
|
|
|
|
|
|
|
|
|
|
def get_os_install_initrd(self):
|
|
|
|
|
return self.getInitrd(suffix="")
|
|
|
|
|
#return self.Get('os_install_initrd_install').strip('-install')
|
|
|
|
|
|
|
|
|
|
def get_os_install_initrd_install(self):
|
|
|
|
|
return self.getInitrd(suffix="install")
|
|
|
|
|