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.
calculate-utils-3-update/pym/cl_kernel_cmd.py

130 lines
5.1 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.
from cl_kernel import cl_kernel, __app__, __version__
from cl_opt import opt
from cl_share_cmd import share_cmd
from os import path
from os import access,R_OK
import re
import sys
from cl_lang import lang
lang().setLanguage(sys.modules[__name__])
DESCRIPTION = _("The Calculate Linux kernel builder")
CMD_OPTIONS = [{'shortOption':"c",
'longOption':"kernel-config",
'optVal':"FILE",
'help':_("Kernel configuration file to use for compilation")
},
{'longOption':"dmraid",
'help':_("Include DMRAID support")
},
{'shortOption':"e",
'longOption':"extraversion",
'optVal':"VER",
'help':_("Specify extraversion for kernel")
},
{'shortOption':"k",
'longOption':"kerneldir",
'optVal':"DIR",
'help':_("Location of the kernel sources")
},
{'longOption':"lvm",
'help':_("Include LVM support")
},
{ 'longOption':"mdadm",
'help':_("Copy /etc/mdadm.conf to initramfs")
},
{'shortOption':"m",
'longOption':"menuconfig",
'help':_("Run menuconfig after oldconfig")
},
{'longOption':"no-clean",
'help':_("Do not run make clean before compilation")
},
{'shortOption':"o",
'longOption':"use-own-config",
'help':_("Use config from kernel directory")
},
{'shortOption':"q",
'help':_("Do not display kernel compilation process")
}]
class kernel_cmd(share_cmd):
"""Class for work with cl_install by console"""
def __init__(self):
self.optobj = opt(package=__app__,
version=__version__,
description=DESCRIPTION,
option_list= CMD_OPTIONS + opt.variable_control +
opt.color_control,
check_values=self.checkOpts)
self.logicObj = cl_kernel()
def _getNamesAllSetOptions(self):
"""Get list set options"""
setOptDict = self.optobj.values.__dict__.items()
defaultOptDict = self.optobj.get_default_values().__dict__.items()
return reduce(lambda x,y: x+[y[0][0]],
filter(lambda x:x[0][1] != x[1][1],
zip(setOptDict,defaultOptDict)), [])
def getStringIncompatibleOptions(self,listOpt):
"""Форматированная строка несовместимых опций разделенных ','"""
return ", ".join(map(lambda x: len(x) == 1 and "'-%s'"%x or "'--%s'"%x,
listOpt))
def checkIncompatibleLive(self):
"""Check incompatible options for option --live"""
incompatible = list(set(self._getNamesAllSetOptions()) &
set(self.optionsLiveIncompatible))
if incompatible:
self.optobj.error(_("incompatible options")+":"+" %s"\
%self.getStringIncompatibleOptions(incompatible+["live"]))
def checkOpts(self, values, args):
"""Check values all specified options."""
if values.k:
if not self.logicObj._testKernelDirectory(values.k):
self.optobj.error("%s:'%s'"%
(_("Wrong kernel source directory"),values.k))
else:
self.logic.clVars.Set('os_kernel_directory',values.k,True)
if values.c and values.o:
self.optobj.error(self.getStringIncompatibleOptions(["c","o"]))
if values.c:
if not path.exists(values.c):
self.optobj.error(_("Kernel config '%s' not found")%values.c)
else:
self.logic.clVars.Set('os_kernel_config',values.c,True)
elif values.o:
if not path.exists(
path.join(self.logic.clVars.Get('os_kernel_directory'),
".config")):
self.optobj.error(_("Kernel directory has not config"))
else:
self.logic.clVars.Set('os_kernel_config',
path.join(self.logic.clVars.Get('os_kernel_directory'),
".config.bak"),True)
return (values, args)
def makeKernel(self):
return self.logicObj.makeKernel()