You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
6.8 KiB
207 lines
6.8 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import os
|
|
import re
|
|
import cl_overriding
|
|
from cl_datavars import glob_attr
|
|
from cl_kernel import cl_kernel
|
|
from os import access, R_OK
|
|
from os import path
|
|
|
|
class fillVars(object, glob_attr):
|
|
|
|
def get_cl_kernel_src_path(self):
|
|
defaultKernelPath = '/usr/src'
|
|
priorityDir = path.join(defaultKernelPath,"linux")
|
|
if not access(defaultKernelPath,R_OK):
|
|
return ""
|
|
kernel = cl_kernel()
|
|
kernelDirs = filter(kernel._testKernelDirectory,
|
|
map(lambda x:path.join(defaultKernelPath,x),
|
|
os.listdir(defaultKernelPath)))
|
|
if kernelDirs:
|
|
if priorityDir in kernelDirs:
|
|
return priorityDir
|
|
else:
|
|
return path.join(defaultKernelPath,kernelDirs[0])
|
|
return ""
|
|
|
|
def get_cl_kernel_full_ver(self):
|
|
if self.Get('cl_kernel_config') \
|
|
and os.access(self.Get('cl_kernel_config'),os.R_OK):
|
|
localVer = self.getValueFromConfig(
|
|
self.Get('cl_kernel_config'),
|
|
'CONFIG_LOCALVERSION')
|
|
if not localVer:
|
|
localVer=""
|
|
else:
|
|
localVer = ""
|
|
kernelMakefile = path.join(self.Get('cl_kernel_src_path'),'Makefile')
|
|
if os.access(kernelMakefile,os.R_OK):
|
|
extraVer = ""
|
|
for line in open(kernelMakefile,'r'):
|
|
if "EXTRAVERSION" in line:
|
|
extraVer = line.partition('=')[2].strip()
|
|
break
|
|
else:
|
|
localVer = ""
|
|
return "%s%s%s"%(self.Get('cl_kernel_ver'), extraVer, localVer)
|
|
|
|
def get_cl_kernel_suffix(self):
|
|
kernelFullVer = self.Get('cl_kernel_full_ver')
|
|
fullVerWithoutCalculate = kernelFullVer.replace("-calculate","")
|
|
return "%s-%s-%s"%(fullVerWithoutCalculate,
|
|
self.Get('os_arch_machine'),
|
|
self.Get('os_linux_shortname'))
|
|
|
|
def get_cl_kernel_ver(self):
|
|
kernelMakefile = path.join(self.Get('cl_kernel_src_path'),'Makefile')
|
|
reVerPart = re.compile(
|
|
"^(?:VERSION|^PATCHLEVEL|^SUBLEVEL)\s*=",re.I)
|
|
if access(kernelMakefile,R_OK):
|
|
try:
|
|
makeVer = \
|
|
"%(VERSION)s.%(PATCHLEVEL)s.%(SUBLEVEL)s"% \
|
|
dict(map(lambda x:(x[0].strip(),x[2].strip()),
|
|
map(lambda x:x.partition('='),
|
|
filter(reVerPart.search,
|
|
open(kernelMakefile,'r')))))
|
|
return makeVer
|
|
except:
|
|
pass
|
|
return ""
|
|
|
|
def get_cl_kernel_config(self):
|
|
kernelDirs = self.Get('cl_kernel_config_path')
|
|
if not access(kernelDirs,R_OK):
|
|
return ""
|
|
shortVerSearch = re.search("^\d+\.\d+.\d+",self.Get('cl_kernel_ver'),re.I)
|
|
if shortVerSearch:
|
|
shortVer = shortVerSearch.group()
|
|
else:
|
|
return ""
|
|
configName = "config-%(system)s-%(march)s-%(ver)s" % \
|
|
{'system':self.Get('os_linux_system'),
|
|
'march':self.Get('os_arch_machine'),
|
|
'ver':shortVer}
|
|
if path.exists(path.join(kernelDirs,configName)):
|
|
return path.join(kernelDirs,configName)
|
|
return ""
|
|
|
|
def get_os_builder_makeopts(self):
|
|
makeconf = '/etc/make.conf'
|
|
if access(makeconf,R_OK):
|
|
makeopts = self.getValueFromConfig('/etc/make.conf',"MAKEOPTS")
|
|
if makeopts:
|
|
return makeopts
|
|
return ""
|
|
|
|
def get_cl_kernel_boot_path(self):
|
|
return path.join(self.Get('cl_kernel_install_path'),"boot")
|
|
|
|
def get_cl_kernel_cache_path(self):
|
|
cacheDir = self.getValueFromConfig('/etc/genkernel.conf','CACHE_DIR')
|
|
if cacheDir == False:
|
|
return "/var/cache/genkernel"
|
|
else:
|
|
return cacheDir
|
|
|
|
reChroot = re.compile("^(?:_=.*bin/chroot|CHROOT=on)$",re.S)
|
|
|
|
def isChroot(self,pid):
|
|
"""Recursive detect chroot mode"""
|
|
if not os.access('/proc/%d/environ'%pid,R_OK):
|
|
return False
|
|
if filter(self.reChroot.match,
|
|
open('/proc/%d/environ'%pid,'r').read().split('\x00')):
|
|
return True
|
|
else:
|
|
ppid = filter(lambda x:x.startswith('PPid:'),
|
|
open('/proc/%d/status'%pid,'r').readlines())[0]
|
|
ppid = int(ppid.strip().partition('\t')[2])
|
|
if ppid == 0:
|
|
return False
|
|
else:
|
|
return self.isChroot(ppid)
|
|
|
|
def get_cl_chroot_status(self):
|
|
"""Detect chroot mode by mtab content"""
|
|
try:
|
|
return "on" if self.isChroot(os.getpid()) else "off"
|
|
except:
|
|
return "off"
|
|
|
|
def get_cl_builder_iso_action(self):
|
|
"""Need perform templates for builder:iso"""
|
|
pass
|
|
|
|
def get_cl_builder_squash_action(self):
|
|
"""Need perform templates for builder:squahs"""
|
|
pass
|
|
|
|
def get_cl_builder_squash_path(self):
|
|
"""Directory of system for livecd.squashfs"""
|
|
pass
|
|
|
|
def get_cl_builder_iso_path(self):
|
|
"""Directory for iso building"""
|
|
pass
|
|
|
|
def get_cl_builder_kernel(self):
|
|
"""Kernel image"""
|
|
pass
|
|
|
|
def get_cl_builder_initrd_install(self):
|
|
"""Initramfs image"""
|
|
pass
|
|
|
|
def get_os_builder_linux_name(self):
|
|
"""Build system name"""
|
|
pass
|
|
|
|
def get_os_builder_linux_subname(self):
|
|
"""Build system subname"""
|
|
pass
|
|
|
|
def get_os_builder_linux_shortname(self):
|
|
"""Build system shortname"""
|
|
pass
|
|
|
|
def get_os_builder_linux_ver(self):
|
|
"""Build system ver"""
|
|
pass
|
|
|
|
def get_os_builder_arch_machine(self):
|
|
"""Build system arch"""
|
|
pass
|
|
|
|
def get_os_builder_linux_system(self):
|
|
"""Build linux system type"""
|
|
pass
|
|
|
|
def get_cl_builder_cdname(self):
|
|
"""Cd size specified by name (DVD/CD)"""
|
|
pass
|
|
|
|
def get_cl_builder_current_squash(self):
|
|
"""Livecd.squashfs name (may be livecd.squashfs.2 and etc)"""
|
|
pass
|
|
|
|
def get_cl_builder_image(self):
|
|
"""Iso image full path"""
|
|
pass
|