Add calculate param to grub.conf modification.

master
Mike Hiretsky 13 years ago
parent 84893e61af
commit 20299952c4

@ -31,6 +31,20 @@ from cl_kernel_utils import KernelConfig,InitRamFs
from cl_lang import lang
lang().setLanguage(sys.modules[__name__])
class changer:
initReduce = [False,[]]
def __call__(self,x,y):
if self.drop(y):
x[0] = False
if self.up(y):
x[0] = True
if x[0]:
y = self.change(y)
return [x[0],x[1] + [y]]
def reduce(self,obj):
return reduce(self,obj,self.initReduce)[1]
class cl_kernel(color_print):
"""Primary class for kernel manipulation"""
kernelCurPath = '/usr/src/linux'
@ -323,43 +337,46 @@ class cl_kernel(color_print):
clVars = self.clVars
clKernelUid = clVars.Get('cl_kernel_uid')
clVars.Write('cl_kernel_uid',clKernelUid,force=True)
reChangeKernel = \
re.compile("(/boot/(?:vmlinuz))(?:-\S+?)?((?:-install)?) ")
reChangeInitrd = \
re.compile("(/boot/)(?:initrd|initramfs)(?:-\S+?)?((?:-install)?)$")
grubconf = '/boot/grub/grub.conf'
rootdev = clVars.Get('os_root_dev')
def grubsetUID(x,y):
if y.startswith('title'):
x[0] = False
elif y.startswith('kernel') and "root=%s"%rootdev in y:
x[0] = True
if x[0]:
x11video = clVars.Get('os_x11_video_drv')
class grubsetUID(changer):
reChangeKernel = \
re.compile("(/boot/(?:vmlinuz))(?:-\S+?)?((?:-install)?) ")
reChangeInitrd = \
re.compile("(/boot/)(?:initrd|initramfs)"
"(?:-\S+?)?((?:-install)?)$")
drop = lambda self,y: y.startswith('title')
up = lambda self,y: y.startswith('kernel') and \
"root=%s"%rootdev in y
def change(self,y):
y = reChangeKernel.sub("\\1-%s\\2 "%clKernelUid,y)
y = reChangeInitrd.sub("\\1initrd-%s\\2"%clKernelUid,y)
return [x[0],x[1] + [y]]
def grubchangeCONSOLE(x,y):
if y.startswith('title'):
x[0] = False
elif y.startswith('kernel') and "/boot/vmlinuz-%s"%clKernelUid in y:
x[0] = True
if x[0]:
y = y.replace('CONSOLE=/dev/','console=')
return [x[0],x[1] + [y]]
class grubchangeCONSOLE(grubsetUID):
up = lambda self,y: y.startswith('kernel') and \
"/boot/vmlinuz-%s"%clKernelUid in y
change = lambda self,y: y.replace('CONSOLE=/dev/','console=')
class grubchangeVideo(grubchangeCONSOLE):
reChangeCalculate = re.compile(r'(?: calculate=\S+|$)')
drop = lambda self,y: not y.startswith('kernel')
change = lambda self,y:self.reChangeCalculate.sub(
' calculate=video:%s'%x11video,y,1)
if not os.access(grubconf,os.W_OK):
self.printERROR(_("No permissions to write to '%s'")%grubconf)
return False
newGrub = reduce(grubsetUID,open(grubconf,'r'),[False,[]])[1]
calcKernel = filter(lambda x:x['PN'] == 'calckernel',
map(reVerSplitToPV,
filter(lambda x:x,
map(lambda x:reVerSplit.search(x),
listDirectory('/var/db/pkg/sys-kernel')))))
newGrub = grubsetUID().reduce(open(grubconf,'r'))
if calcKernel and cmpVersion(calcKernel[-1]['PVR'],"3.4.14") >= 0:
newGrub = reduce(grubchangeCONSOLE,newGrub,[False,[]])[1]
newGrub = grubchangeCONSOLE().reduce(newGrub)
newGrub = grubchangeVideo().reduce(newGrub)
open(grubconf,'w').writelines(newGrub)
return True

Loading…
Cancel
Save