Compare commits

...

12 Commits

Author SHA1 Message Date
Mike Hiretsky c4d1eef457 Added iso creating and rescratch function
14 years ago
Mike Hiretsky d2c318118a Add cl-image script. Added fill methods for all variables.
14 years ago
Mike Hiretsky 5c395f76cb Added cl-builder, cl-image script
14 years ago
Mike Hiretsky d174fa5058 Start changes
14 years ago
Mike Hiretsky 10deb927f2 Change in detect chroot.
14 years ago
Mike Hiretsky 5589b29ddf Add new variable cl_kernel_suffix.
14 years ago
Mike Hiretsky 349ca70fff Added versionMigrage for performing symlink options.
14 years ago
Mike Hiretsky 0fa2e62240 Added new option symlink for change current kernel.
14 years ago
Mike Hiretsky d9c761ab2d Fix cl-builder for chroot.rc. Fix chroot detect.
14 years ago
Mike Hiretsky 3db65ea3a3 Update cl-builder from calculate repository.
14 years ago
Mike Hiretsky 7ebde813e3 Added modification for run cl-kernel from ebuild.
14 years ago
Mike Hiretsky 3af5051bce Added kernel compilation.
14 years ago

@ -0,0 +1,6 @@
#!/bin/bash
env-update &>/dev/null
source /etc/profile
PS1="\[\033[0;40;0;33m\]\H \W #\[\033[0m\] "

@ -0,0 +1,337 @@
#-*- 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.
__version__ = "2.2.0.0"
__app__ = "calculate-builder"
import os
import re
import sys
import traceback
from os import path
from cl_utils import process,pathJoin
from subprocess import STDOUT,PIPE
from cl_print import color_print
from cl_datavars import DataVars
from shutil import copy2 as copy_with_perm
from cl_distr import IsoDistributive, DirectoryDistributive, \
DistributiveError
from cl_template import template
from cl_vars_share import varsShare
from cl_kernel_utils import KernelConfig,InitRamFs
from cl_lang import lang
from server.utils import dialogYesNo
import cl_overriding
class printNoColor:
def colorPrint(self,attr,fg,bg,string):
sys.stdout.write(string)
class BuilderError(Exception):
"""Installation Error"""
builder_errors = ""
def installExit(self,*args,**kwars):
raise BuilderError(self.__class__.builder_errors)
def overprintERROR(self,error):
self.__class__.builder_errors += str(error) + "\n"
def getBuilderErrors(self):
return self.__class__.builder_errors
def popBuilderErrors(self):
res = self.__class__.builder_errors
self.__class__.builder_errors = ""
return res
def getOverrideMethods(self):
return self.installExit, self.overprintERROR
cl_overriding.exit, cl_overriding.printERROR = \
BuilderError().getOverrideMethods()
class DataVarsBuilder(DataVars):
"""Variable class for installation"""
def importBuilder(self, **args):
'''Get variables for builder'''
# section name in calculate.env
envSection = "builder"
# import builder variables
self.importData(envSection, ('cl_vars_builder','cl_fill_builder'))
class cl_builder(color_print):
"""Primary class for image manipulation"""
def __init__(self):
self.clVars = None
self.startMessage = ""
def setNoColor(self):
self.color = False
def initVars(self):
"""Primary initialization of variables"""
self.clVars = DataVarsBuilder()
self.clVars.importBuilder()
self.clVars.flIniFile()
self.startMessage = ""
self.clTempl = None
self.force = False
def applyTemplatesForSquash(self,directory):
"""Apply templates for root of system."""
#self.clVars.Set("cl_root_path","/", True)
self.clVars.Set("cl_action","squash", True)
self.clVars.Set("cl_chroot_path",directory, True)
self.clTempl = template(self.clVars)
dirsFiles = self.clTempl.applyTemplates()
self.clTempl.closeFiles()
if self.clTempl.getError():
self.printERROR(self.clTempl.getError())
return False
else:
return dirsFiles
def applyTemplatesForIso(self,directory):
"""Apply templates for root of system."""
#self.clVars.Set("cl_root_path","/", True)
self.clVars.Set("cl_action","iso", True)
chrootPath=pathJoin(directory,
self.clVars.Get('cl_builder_squash_path'))
self.clVars.Set("cl_chroot_path",chrootPath, True)
self.clVars.Set("cl_root_path","..", True)
self.clTempl = template(self.clVars)
dirsFiles = self.clTempl.applyTemplates()
self.clTempl.closeFiles()
if self.clTempl.getError():
self.printERROR(self.clTempl.getError())
return False
else:
return dirsFiles
def printMessageForTest(self,message):
"""Print waiting message and OK or Error by func result"""
message = "%s ..." % message
self.printSUCCESS(message,printBR=False)
self.startMessage = message
def printByResult(self,result,failMessage=None):
"""Print message and result"""
if self.startMessage:
self.defaultPrint("\r")
self.printLine((('greenBr',' * '),
('',self.startMessage),
),
(('',''),
), 0, False)
self.printRight(self.lenString(self.startMessage)+5,4)
if result:
self.printLine((('blueBr','['),
('greenBr',' ok '),
('blueBr',']')),[])
else:
self.printLine((('blueBr','['),
('redBr',' !! '),
('blueBr',']')),[])
if failMessage:
self.printERROR(failMessage)
self.startMessage = ""
def prepareSourceDistributive(self,distr):
self.applyTemplatesForSquash(distr.convertToDirectory().getDirectory())
def isoPrepacking(self,directory):
self.printByResult(True)
self.applyTemplatesForIso(directory)
self.printMessageForTest(_("Releasing source data"))
self.sourceDistr.close()
self.printByResult(True)
self.sourceDistr = None
self.printMessageForTest(_("Creating iso image"))
def flashPrepacking(self,directory):
self.printByResult(True)
self.applyTemplatesForIso(directory)
self.printMessageForTest(_("Releasing source data"))
self.sourceDistr.close()
self.sourceDistr = None
def printInfo(self):
self.printSUCCESS(_("Creating image of") + " Calculate Linux")
self.defaultPrint("%s\n"%_("System information"))
subname = self.clVars.Get('os_builder_linux_subname')
subname = (" %s"%subname) if subname else ""
self.printSUCCESS(_("Building system")+": %s"%
self.clVars.Get('os_builder_linux_name')+subname)
self.printSUCCESS(_("System version")+": %s"%
self.clVars.Get('os_builder_linux_ver'))
self.printSUCCESS(_("Machine hardware name")+": %s"%
self.clVars.Get('os_builder_arch_machine'))
self.defaultPrint("%s\n"%_("Perform pre-install checkups"))
if self.clVars.Get('cl_builder_image'):
self.printSUCCESS(_("Image will be created at: %s\n")%
self.clVars.Get('cl_builder_image'))
else:
self.printWARNING("No path for image creating.")
def printRescratchInfo(self):
self.printSUCCESS(_("Rebuilding live image of") + " Calculate Linux")
self.defaultPrint("%s\n"%_("System information"))
subname = self.clVars.Get('os_builder_linux_subname')
subname = (" %s"%subname) if subname else ""
self.printSUCCESS(_("Building system")+": %s"%
self.clVars.Get('os_builder_linux_name')+subname)
self.printSUCCESS(_("System version")+": %s"%
self.clVars.Get('os_builder_linux_ver'))
self.printSUCCESS(_("Machine hardware name")+": %s"%
self.clVars.Get('os_builder_arch_machine'))
self.defaultPrint("%s\n"%_("Perform pre-install checkups"))
self.printSUCCESS(_("Image will be created in: %s\n")%
self.clVars.Get('cl_builder_iso_path'))
def checkVariables(self,rescratch=False):
"""Check values of variables"""
buildDirectory = self.clVars.Get('cl_builder_iso_path')
if path.realpath(self.clVars.Get('cl_builder_path')) == "/":
self.printERROR("Source system should not be '/'")
return False
if self.clVars.Get('os_builder_linux_ver') == "0":
self.printERROR("Can not found distributive version")
return False
elif not self.clVars.Get('os_builder_linux_shortname') in \
varsShare.dictNameSystem.keys():
self.printWARNING("Distributive is not Calculate Linux")
return False
elif not rescratch and path.exists(buildDirectory):
self.printWARNING(
_("Directory '%s' for building iso is already exists")%
buildDirectory)
return False
return True
def _isoLogic(self,force):
isoFile = self.clVars.Get('cl_builder_image')
buildDirectory = self.clVars.Get('cl_builder_iso_path')
sourceDirectory = self.clVars.Get('cl_builder_path')
bindDirectory = pathJoin(buildDirectory,
self.clVars.Get('cl_builder_squash_path'))
if not self.checkVariables():
return False
self.printInfo()
self.targetDistr = IsoDistributive(isoFile,bdirectory=buildDirectory)
self.sourceDistr = DirectoryDistributive(sourceDirectory,
mdirectory=bindDirectory)
if not force:
dialogMessage = _("Continue the creating image of the system") \
+ " (yes/no)"
dialogRes = dialogYesNo(dialogMessage)
if dialogRes in (None,False):
return True
self.printMessageForTest(_("Prepare data for live image"))
self.prepareSourceDistributive(self.sourceDistr)
self.printByResult(True)
self.targetDistr.prepareIso = self.isoPrepacking
self.printMessageForTest(_("Creating squash image"))
self.targetDistr.installFrom(self.sourceDistr)
self.printByResult(True)
return True
def _rescratchLogic(self,force=False):
self.clVars.Set('cl_builder_iso_path','/mnt/flash',True)
buildDirectory = self.clVars.Get('cl_builder_iso_path')
sourceDirectory = self.clVars.Get('cl_builder_path')
bindDirectory = pathJoin(buildDirectory,
self.clVars.Get('cl_builder_squash_path'))
if not self.checkVariables(rescratch=True):
return False
self.printRescratchInfo()
self.targetDistr = IsoDistributive(buildDirectory,
bdirectory=buildDirectory)
self.sourceDistr = DirectoryDistributive(sourceDirectory,
mdirectory=bindDirectory)
if not force:
dialogMessage = _("Continue the rebuilding flash live system") \
+ " (yes/no)"
dialogRes = dialogYesNo(dialogMessage)
if dialogRes in (None,False):
return True
self.printMessageForTest(_("Prepare data for live image"))
self.prepareSourceDistributive(self.sourceDistr)
self.printByResult(True)
self.targetDistr.prepareIso = self.flashPrepacking
self.printMessageForTest(_("Creating squash image"))
self.targetDistr.installFrom(self.sourceDistr)
self.printByResult(True)
return True
def makeIsoImage(self,force=False):
return self.makeImage(self._isoLogic,force)
def makeRescratch(self,force=False):
return self.makeImage(self._rescratchLogic,force)
def makeImage(self,logicFunc,*argv):
"""Make iso image by variables"""
self.sourceDistr = None
self.targetDistr = None
error = None
try:
if not logicFunc(*argv):
return False
except (EOFError), e:
error = e
except (BuilderError,DistributiveError),e:
error = e
except (Exception),e:
error = ""
for i in apply(traceback.format_exception, sys.exc_info()):
error += i
except KeyboardInterrupt,e:
self.printByResult(False)
self.printWARNING("Interrupting the iso building")
error = _("Iso building manually interrupt")
if error:
self.printByResult(False)
try:
if self.clTempl:
self.clTempl.closeFiles()
if self.sourceDistr:
self.printMessageForTest(_("Releasing source data"))
self.sourceDistr.close()
self.printByResult(True)
if self.targetDistr:
self.printMessageForTest(_("Unmount built system volume"))
self.targetDistr.close()
self.printByResult(True)
except (BuilderError,DistributiveError),e:
error = "%s\n%s" % (str(error),_("Unmounting error"))
except KeyboardInterrupt,e:
pass
if error:
self.printByResult(False)
if error:
for line in filter(lambda x: x,str(error).split('\n')):
self.printERROR(line)
self.printERROR(_("Iso building failed"))
return False
self.printSUCCESS(_("Iso has built successfully"))
return True

@ -17,36 +17,74 @@
import os
import re
import cl_overriding
from cl_datavars import glob_attr
from cl_vars_share import varsShare
from cl_kernel import cl_kernel
from os import access, R_OK
from os import access, R_OK,W_OK
from os import path
from cl_distr import Distributive
from cl_utils import getTupleVersion,genpassword,pathJoin
from operator import itemgetter
from types import ListType
class fillVars(object, glob_attr):
class fillVars(object, varsShare):
def get_cl_kernel_directory(self):
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,os.listdir('/usr/src'))
kernelDirs = filter(kernel._testKernelDirectory,
map(lambda x:path.join(defaultKernelPath,x),
os.listdir(defaultKernelPath)))
if kernelDirs:
if "linux" in kernelDirs:
return path.join(defaultKernelPath,"linux")
if priorityDir in kernelDirs:
return priorityDir
else:
return path.join(defaultKernelPath,kernelDirs[0])
return ""
def get_cl_kernel_version(self):
kernelMakefile = path.join(self.Get('cl_kernel_directory'),'Makefile')
reVerPart = re.compile("^(?:VERSION|^PATCHLEVEL|^SUBLEVEL)\s*=",re.I)
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:
return "%(VERSION)s.%(PATCHLEVEL)s.%(SUBLEVEL)s"% \
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 ""
@ -55,10 +93,203 @@ class fillVars(object, glob_attr):
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':self.Get('cl_kernel_version')}
if path.exists(configName):
'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"""
if self.Get('cl_action')=='iso':
return "up"
return ""
def get_cl_builder_squash_action(self):
"""Need perform templates for builder:squahs"""
if self.Get('cl_action')=='squash':
return "up"
return ""
def get_cl_builder_kernel(self):
"""Kernel image"""
bootdir = path.join(self.Get('cl_builder_path'),'boot')
modulesdir = path.join(self.Get('cl_builder_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])),
path.getmtime(x[0]))),
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 path.split(max(kernelsWithVer,key=itemgetter(1))[0])[-1]
return ""
def get_cl_builder_initrd_install(self):
return self.getInitrd(self.Get('os_builder_arch_machine'),
self.Get('os_builder_linux_shortname'),
self.Get('cl_builder_path'),
self.Get('cl_builder_kernel'),
suffix="install") or ""
def get_os_builder_linux_name(self):
"""Build system name"""
linuxShortName = self.Get("os_builder_linux_shortname")
return self.dictLinuxName.get(linuxShortName,"Linux")
def get_os_builder_linux_subname(self):
"""Build system subname"""
linuxShortName = self.Get("os_builder_linux_shortname")
return self.dictLinuxSubName.get(linuxShortName,"")
def get_os_builder_linux_shortname(self):
"""Build system shortname"""
systemRoot = self.Get('cl_builder_path')
return self.getShortnameByMakeprofile(systemRoot) or \
self.getShortnameByIni(systemRoot) or \
self.detectOtherShortname(systemRoot) or \
"Linux"
def get_os_builder_linux_ver(self):
"""Build system ver"""
linuxShortName = self.Get("os_builder_linux_shortname")
rootSystem = self.Get('cl_builder_path')
return self.getVersionFromMetapackage(rootSystem,linuxShortName) or \
self.getVersionFromCalculateIni(rootSystem) or \
self.getVersionFromGentooFiles(rootSystem) or "0"
def get_os_builder_arch_machine(self):
"""Build system arch"""
rootSystem = self.Get('cl_builder_path')
lib64path = path.join(rootSystem,"lib64")
return 'x86_64' if path.lexists(lib64path) else "i686"
def get_os_builder_linux_system(self):
"""Build linux system type"""
shortName = self.Get('os_builder_linux_shortname')
return self.dictNameSystem.get(shortName,"")
def get_cl_builder_cdname(self):
"""Cd size specified by name (DVD/CD)"""
squashfile = pathJoin(self.Get('cl_builder_iso_path'),
self.Get('cl_builder_current_squash'))
kernelfile = pathJoin(self.Get('cl_builder_iso_path'),
self.Get('cl_builder_squash_path'),
'boot',
self.Get('cl_builder_kernel'))
initrdfile = pathJoin(self.Get('cl_builder_iso_path'),
self.Get('cl_builder_squash_path'),
'boot',
self.Get('cl_builder_initrd_install'))
if os.access(squashfile,R_OK) and os.access(kernelfile,R_OK) and \
os.access(initrdfile,R_OK):
isosize = path.getsize(squashfile)+path.getsize(kernelfile)+ \
path.getsize(initrdfile)+2*1024*1024
if isosize > 700*1024*1024:
return "DVD"
else:
return "CD"
return ""
def getSquashNum(self,reMatch):
if reMatch.groups()[1] and reMatch.groups()[1].isdigit():
return int(reMatch.groups()[1])
else:
return 0
def get_cl_builder_remove_squash(self):
"""Livecd.squashfs name for del(may be livecd.squashfs.2 and etc)"""
directory = self.Get('cl_builder_iso_path')
if not os.access(directory,R_OK):
return ""
squashfiles = filter(lambda x:x,
map(Distributive.reLive.search,
os.listdir(directory)))
if squashfiles:
return map(lambda x:x.group(),
sorted(squashfiles, key=self.getSquashNum))[:-1]
return ""
def get_cl_builder_current_squash(self):
"""Livecd.squashfs name (may be livecd.squashfs.2 and etc)"""
directory = self.Get('cl_builder_iso_path')
if not os.access(directory,R_OK):
return ""
squashfiles = filter(lambda x:x,
map(Distributive.reLive.search,
os.listdir(directory)))
if squashfiles:
return max(squashfiles, key=self.getSquashNum).group()
return ""
def get_cl_builder_iso_path(self):
directory = "/var/calculate/tmp/iso"
newDirectoryName = directory
while path.exists(newDirectoryName):
newDirectoryName = "%s.%s"%(directory,genpassword(8))
return newDirectoryName
def get_cl_builder_image(self):
"""Iso image full path"""
imagepath = self.Get('cl_builder_image_path')
if type(imagepath) != ListType:
imagepath = [imagepath]
paths = filter(lambda x:os.access(x,W_OK), imagepath)
if paths:
return path.join(paths[0],"%(shortname)s-%(ver)s-%(march)s.iso"%
{'shortname':self.Get('os_builder_linux_shortname').lower(),
'ver':self.Get('os_builder_linux_ver'),
'march':self.Get('os_builder_arch_machine')})
return ""

@ -0,0 +1,84 @@
#-*- 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_builder import cl_builder, __app__, __version__
from cl_opt import opt
from cl_share_cmd import share_cmd
import os
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 image builder")
CMD_OPTIONS = [{'shortOption':"f",
'longOption':"force",
'help':_("no questions during the creating process")
}]
USAGE = _("%prog [options] iso|squash")
class image_cmd(share_cmd):
"""Class for work with cl_builder by console"""
def __init__(self):
self.optobj = opt(package=__app__,
version=__version__,
description=DESCRIPTION,
usage=USAGE,
option_list= CMD_OPTIONS + opt.variable_control +
opt.color_control,
check_values=self.checkOpts)
self.logicObj = cl_builder()
self.commands = ["iso","squash"]
#self.optionsInitrdIncompatible = ["o","no_clean","m","mdadm","lvm",
# "k", "e","dmraid","c","ebuild",
# "symlink"]
def checkOpts(self, values, args):
"""Check values all specified options."""
if len(args) > 1:
self.optobj.error(_("unrecognized option") + ": %s"% "".join(args))
if len(args) < 1 and not values.v:
self.optobj.error(_("missing command argument"))
if args and not args[0] in self.commands:
self.optobj.error(_("invalid command: '%s' (choose from %s)")%
(args[0],", ".join(map(lambda x:"'%s'"%x,self.commands))))
# for work with v param
if args:
self.logicObj.clVars.Set('cl_action',args[0],True)
self.logicObj.clVars.Set('cl_builder_iso_path','/mnt/flash',True)
self.optobj.checkVarSyntax(values)
return (values, args)
def performActionByCommand(self,options,args):
action = {'iso':self.makeIso,
'squash':self.makeSquash}
action[args[0]](options)
def makeIso(self,options):
"""Make iso"""
if not self.logicObj.makeIsoImage(options.f):
return False
return True
def makeSquash(self,options):
"""Make squash (rescratch)"""
if not self.logicObj.makeRescratch(options.f):
return False
return True

@ -23,29 +23,18 @@ import sys
import traceback
from os import path
from cl_utils import process
from subprocess import STDOUT,PIPE
from cl_print import color_print
from cl_datavars import DataVars
from shutil import copy2 as copy_with_perm
from cl_kernel_utils import KernelConfig,InitRamFs
from cl_builder import DataVarsBuilder, printNoColor
from cl_lang import lang
class printNoColor:
def colorPrint(self,attr,fg,bg,string):
sys.stdout.write(string)
class DataVarsBuilder(DataVars):
"""Variable class for installation"""
def importBuilder(self, **args):
'''Get variables for builder'''
# section name in calculate.env
envSection = "builder"
# import builder variables
self.importData(envSection, ('cl_vars_builder','cl_fill_builder'))
class cl_kernel(color_print):
"""Primary class for kernel manipulation"""
kernelCurPath = '/usr/src/linux'
def __init__(self):
self.clVars = None
@ -71,3 +60,318 @@ class cl_kernel(color_print):
self.clVars.importBuilder()
self.clVars.flIniFile()
def makeKernel(self,quiet=True,showMenuConfig=False,noClean=False,
lvmOpt=False,dmraidOpt=False,mdadmOpt=False,
mrproper=False):
"""Run kernel compilation"""
clVars = self.clVars
standardParams = ["--splash=tty1", "--unionfs",
"--all-ramdisk-modules","--disklabel",
"--slowusb", "--no-save-config"]
kernelDir = ["--kerneldir=%s"%clVars.Get('cl_kernel_src_path')]
kernelDestination = clVars.Get('cl_kernel_install_path')
modulePrefix = ["--module-prefix=%s"%kernelDestination]
if not path.exists(kernelDestination):
self.printERROR("Not found destination directory '%s'"%
kernelDestination)
return False
logLevel = ["--loglevel=%d"%(1 if quiet else 2)]
makeOpts = clVars.Get('os_builder_makeopts')
if makeOpts:
makeOpts = ["--makeopts=%s"%makeOpts]
else:
makeOpts = []
menuConfig = ["--menuconfig"] if showMenuConfig else []
noClean = ["--no-clean"] if noClean else []
kernelConfig = ["--kernel-config=%s"%clVars.Get('cl_kernel_config')]
bootDir = clVars.Get('cl_kernel_boot_path')
if not path.exists(bootDir):
os.makedirs(bootDir,mode=0755)
bootDir = ["--bootdir=%s"%bootDir]
lvmOpt = ["--lvm"] if lvmOpt else []
dmraidOpt = ["--dmraid"] if dmraidOpt else []
mdadmOpt = ["--mdadm"] if mdadmOpt else []
mrproperOpt = ["--mrproper"] if mrproper else []
kernelName = ["--kernname=%s"%clVars.Get('os_linux_system')]
cachedir = ["--cachedir=%s"%clVars.Get('cl_kernel_cache_path')]
tempdir = ["--tempdir=%s"%clVars.Get('cl_kernel_temp_path')]
params = ["genkernel"]+cachedir+tempdir+\
standardParams+kernelDir+modulePrefix+\
logLevel+makeOpts+menuConfig+noClean+kernelConfig+\
bootDir+lvmOpt+dmraidOpt+mdadmOpt+mrproperOpt+["all"]
try:
genkernelProcess = process(*params,stdout=None,stderr=STDOUT,
stdin=None,envdict=os.environ)
return genkernelProcess.success()
except KeyboardInterrupt:
self.printERROR("Keyboard interrupt")
return False
def prepareBoot(self):
"""Rename received by genkernel files"""
clVars = self.clVars
bootDir = clVars.Get('cl_kernel_boot_path')
if not os.access(bootDir,os.W_OK):
self.printERROR(_("No permissions to write to '%s'")% bootDir)
return False
march = clVars.Get('os_arch_machine')
if re.match("^i.86$",march):
march = "x86"
baseConfigName = path.join(clVars.Get('cl_kernel_src_path'),
".config")
if path.exists(baseConfigName):
clVars.Set('cl_kernel_config',baseConfigName,True)
kernelFullVer = clVars.Get('cl_kernel_full_ver')
suffixName = "genkernel-%(march)s-%(fullver)s"%\
{"march":march,
"fullver":kernelFullVer}
baseInitrdName = path.join(bootDir,"initramfs-%s"%suffixName)
baseKernelName = path.join(bootDir,"kernel-%s"%suffixName)
baseSystemMap = path.join(bootDir,"System.map-%s"%suffixName)
newInitrdName = self._getName("initramfs")
newKernelName = self._getName("vmlinuz")
newSystemMap = self._getName("System.map")
newConfigName = self._getName("config")
try:
os.rename(baseInitrdName,newInitrdName)
os.rename(baseKernelName,newKernelName)
os.rename(baseSystemMap,newSystemMap)
copy_with_perm(baseConfigName,newConfigName)
except OSError,e:
self.printERROR(_("Can not rename kernel files: %s")%e.strerror)
return False
return True
def _installFile(self,source,target,removeSource=True,symlink=False):
"""Copy, move or create symlink source file to target. Save old."""
def getLinkForTarget(target):
"""Get symlinks from target dirname which point to target"""
baseDir = path.dirname(path.normpath(target))
linkFiles = filter(path.islink,map(lambda x:path.join(baseDir,x),
os.listdir(baseDir)))
return filter(lambda x:path.join(baseDir,
os.readlink(x))==target, linkFiles)
# raise IOError if source is not exists
open(source,'r').close()
targetLinkFiles = getLinkForTarget(target)
oldtarget = ""
if path.lexists(target):
oldtarget = "%s.old" % target
if path.lexists(oldtarget):
oldTargetLinkFiles = getLinkForTarget(oldtarget)
map(os.unlink,oldTargetLinkFiles)
os.unlink(oldtarget)
os.rename(target,oldtarget)
if symlink:
if path.dirname(source)==path.dirname(target):
os.symlink(path.basename(source),target)
else:
os.symlink(source,target)
elif removeSource:
os.rename(source,target)
else:
copy_with_perm(source,target)
if oldtarget:
map(os.unlink,targetLinkFiles)
map(lambda x:os.symlink(path.basename(oldtarget),x),targetLinkFiles)
def _getName(self,obj):
"""Get names for (initramfs,initramfs-install,vmlinuz,System.map,
config) after kernel compilation (installed)"""
clVars = self.clVars
bootDir = clVars.Get('cl_kernel_boot_path')
kernelFullVer = clVars.Get('cl_kernel_full_ver')
fullVerWithoutCalculate = kernelFullVer.replace("-calculate","")
suffixName = "%s-%s-%s-installed"%(fullVerWithoutCalculate,
clVars.Get('os_arch_machine'),
clVars.Get('os_linux_shortname'))
return path.join(bootDir,{"initramfs":"initramfs-%s",
"initramfs-install":"initramfs-%s",
"vmlinuz":"vmlinuz-%s",
"System.map":"System.map-%s",
"config":"config-%s"}[obj]%suffixName)
def _getNewName(self,obj):
"""Get new names for (initramfs,initramfs-install,vmlinuz,System.map,
config) which they have after renaming"""
clVars = self.clVars
bootDir = clVars.Get('cl_kernel_boot_path')
kernelFullVer = clVars.Get('cl_kernel_full_ver')
fullVerWithoutCalculate = kernelFullVer.replace("-calculate","")
newSuffixName = "%s-%s-%s"%(fullVerWithoutCalculate,
clVars.Get('os_arch_machine'),
clVars.Get('os_linux_shortname'))
return path.join(bootDir,{"initramfs":"initramfs-%s",
"initramfs-install":"initramfs-%s-install",
"vmlinuz":"vmlinuz-%s",
"System.map":"System.map-%s",
"config":"config-%s"}[obj]%newSuffixName)
def _getSymlink(self,obj):
"""Get uid symlinks (initramfs,initramfs-install,vmlinuz,System.map)
they pointet to object by _getNewName"""
clVars = self.clVars
bootDir = clVars.Get('cl_kernel_boot_path')
kernelUid = clVars.Get('cl_kernel_uid')
return path.join(bootDir,{"initramfs":"initrd-%s",
"initramfs-install":"initrd-%s-install",
"vmlinuz":"vmlinuz-%s",
"System.map":"System.map-%s"}[obj]%kernelUid)
def createUidSymlinks(self):
"""Create link iniramfs-UUID,vmlinuz-UUID,System.map-UUID."""
if self.skipByChrootAndShortname():
return True
newInitrdName = self._getNewName("initramfs")
newInitrdNameInstall = self._getNewName("initramfs-install")
newKernelName = self._getNewName("vmlinuz")
newSystemMap = self._getNewName("System.map")
symlinkInitrdName = self._getSymlink("initramfs")
symlinkInitrdNameInstall = self._getSymlink("initramfs-install")
symlinkKernelName = self._getSymlink("vmlinuz")
symlinkSystemMap = self._getSymlink("System.map")
try:
self._installFile(newInitrdName,symlinkInitrdName, symlink=True)
self._installFile(newInitrdNameInstall,symlinkInitrdNameInstall,
symlink=True)
self._installFile(newKernelName,symlinkKernelName, symlink=True)
self._installFile(newSystemMap, symlinkSystemMap, symlink=True)
except IOError,e:
self.printERROR(
_("Can not create symlink to current kernel: %s '%s'")%
(e.strerror,e.filename))
self.printERROR(_("May be kernel was not compiled"))
return False
except OSError,e:
self.printERROR(_("Can not create symlink to current kernel: %s")%
e.strerror)
return False
return True
def installBootFiles(self):
"""Copy -install files to without suffix name, and save old copy.
initramfs, vmlinuz, System.map, config with suffix installed copy
withou suffix. Save old files by append suffix .old.
Search link files boot directory link to oldfiles and fix symlink.
Create initramfs install (copy of initramfs)
"""
initrdName = self._getName("initramfs")
kernelName = self._getName("vmlinuz")
systemMap = self._getName("System.map")
configName = self._getName("config")
newInitrdName = self._getNewName("initramfs")
newInitrdNameInstall = self._getNewName("initramfs-install")
newKernelName = self._getNewName("vmlinuz")
newSystemMap = self._getNewName("System.map")
newConfigName = self._getNewName("config")
try:
self._installFile(initrdName,newInitrdName,removeSource=False)
self._installFile(initrdName,newInitrdNameInstall)
self._installFile(kernelName,newKernelName)
self._installFile(systemMap,newSystemMap)
self._installFile(configName,newConfigName)
except (OSError,IOError),e:
self.printERROR(_("Can not install kernel files: %s")%e.strerror)
return False
return True
def skipByChrootAndShortname(self):
"""Return true if run from chroot or system not Calculate"""
clVars = self.clVars
return clVars.Get('cl_chroot_status') == 'on' or \
clVars.Get('os_linux_shortname') in ('Gentoo','Linux')
def versionMigrate(self):
clVars = self.clVars
if self.skipByChrootAndShortname():
return True
calculate2env = clVars.Get('cl_env_path')[0]
if not path.exists(calculate2env) or \
not filter(lambda x:x.startswith('cl_kernel_uid'),
open(calculate2env,'r')):
return self.performVersionMigrate()
return True
def performVersionMigrate(self):
"""Generate cl_kernel_uid, write to calculate2.env, fix grub.conf"""
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 grubreduce(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]:
y = reChangeKernel.sub("\\1-%s\\2 "%clKernelUid,y)
y = reChangeInitrd.sub("\\1initrd-%s\\2"%clKernelUid,y)
return [x[0],x[1] + [y]]
if not os.access(grubconf,os.W_OK):
self.printERROR(_("No permissions to write to '%s'")%grubconf)
return False
newGrub = reduce(grubreduce,open(grubconf,'r'),[False,[]])[1]
open(grubconf,'w').writelines(newGrub)
return True
def setKernelForCurrent(self):
"""Set compiled kernel to current"""
clVars = self.clVars
if self.skipByChrootAndShortname():
return True
# compiling kernel not current.
clKernelPath = clVars.Get('cl_kernel_src_path')
if not clKernelPath in (self.kernelCurPath,
path.realpath(self.kernelCurPath)) and \
path.islink(self.kernelCurPath):
os.unlink(self.kernelCurPath)
kernelName = path.basename(path.normpath(clKernelPath))
try:
os.symlink(kernelName,self.kernelCurPath)
except (IOError,OSError),e:
self.printERROR(str(e))
return False
return True
def cleanInitrd(self):
"""Discard from initrd non-critical modules"""
clVars = self.clVars
if self.skipByChrootAndShortname():
return True
bootDir = clVars.Get('cl_kernel_boot_path')
clKernelUid = clVars.Get('cl_kernel_uid')
initrdName = path.join(bootDir,"initramfs-%s-install"%clKernelUid)
optInitrdName = path.join(bootDir,"initramfs-%s"%clKernelUid)
# old mode (for compatibility)
if not path.lexists(initrdName) or not path.lexists(optInitrdName):
kernelFullVer = clVars.Get('cl_kernel_full_ver')
fullVerWithoutCalculate = kernelFullVer.replace("-calculate","")
suffixName = "%s-%s-%s"%(fullVerWithoutCalculate,
clVars.Get('os_arch_machine'),
clVars.Get('os_linux_shortname'))
initrdName = path.join(bootDir,"initramfs-%s-install"%suffixName)
optInitrdName = path.join(bootDir,"initramfs-%s"%suffixName)
if path.exists(path.realpath(optInitrdName)):
os.unlink(path.realpath(optInitrdName))
try:
initRamFs = InitRamFs(initrdName)
return initRamFs.cleanInitRamFs(path.realpath(optInitrdName))
except (OSError,IOError),e:
self.printERROR(str(e))
return False

@ -17,6 +17,7 @@
from cl_kernel import cl_kernel, __app__, __version__
from cl_opt import opt
from cl_share_cmd import share_cmd
import os
from os import path
from os import access,R_OK
import re
@ -29,41 +30,53 @@ DESCRIPTION = _("The Calculate Linux kernel builder")
CMD_OPTIONS = [{'shortOption':"c",
'longOption':"kernel-config",
'optVal':"FILE",
'help':_("Kernel configuration file to use for compilation")
'help':_("kernel configuration file to use for compilation")
},
{'longOption':"dmraid",
'help':_("Include DMRAID support")
'help':_("include DMRAID support")
},
{'shortOption':"e",
'longOption':"extraversion",
'optVal':"VER",
'help':_("Specify extraversion for kernel")
'help':_("specify extraversion for kernel")
},
{'shortOption':"k",
'longOption':"kerneldir",
'optVal':"DIR",
'help':_("Location of the kernel sources")
'help':_("location of the kernel sources")
},
{'longOption':"lvm",
'help':_("Include LVM support")
'help':_("include LVM support")
},
{ 'longOption':"mdadm",
'help':_("Copy /etc/mdadm.conf to initramfs")
'help':_("copy /etc/mdadm.conf to initramfs")
},
{'shortOption':"m",
'longOption':"menuconfig",
'help':_("Run menuconfig after oldconfig")
'help':_("run menuconfig after oldconfig")
},
{'longOption':"mrproper",
'help':_("run make mrproper before compilation")
},
{'longOption':"no-clean",
'help':_("Do not run make clean before compilation")
'help':_("do not run make clean before compilation")
},
{'shortOption':"o",
'longOption':"use-own-config",
'help':_("Use config from kernel directory")
'help':_("use config from kernel directory")
},
{'shortOption':"q",
'help':_("Do not display kernel compilation process")
}]
'help':_("do not display kernel compilation process")
},
{'longOption':"initrd",
'help':_("perform current initramfs optimization")},
{'longOption':"ebuild",
'help':
_("build kernel by ebuild phase (need ebuild enviroment)")},
{'longOption':"symlink",
'help':
_("set uid symlinks for current kernel in boot directory")}
]
class kernel_cmd(share_cmd):
@ -76,54 +89,115 @@ class kernel_cmd(share_cmd):
opt.color_control,
check_values=self.checkOpts)
self.logicObj = cl_kernel()
self.optionsInitrdIncompatible = ["o","no_clean","m","mdadm","lvm",
"k", "e","dmraid","c","ebuild",
"symlink"]
self.optionsSymlinkIncompatible = ["o","no_clean","m","mdadm","lvm",
"e","dmraid","c","ebuild","initrd" ]
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 checkEnviromentForEbuild(self):
"""Check current enviroment for ebuild enviroment variables"""
missedEnvVar = filter(lambda x:not x in os.environ,
['S','T','D','ROOT','WORKDIR',
'EBUILD_PHASE'])
if missedEnvVar:
self.optobj.error(_("Can not read some ebuild variable: %s")%
", ".join(missedEnvVar))
def checkOpts(self, values, args):
"""Check values all specified options."""
if len(args) > 0:
self.optobj.error(_("unrecognized option") + ": %s"% "".join(args))
if values.ebuild:
self.checkEnviromentForEbuild()
if values.initrd:
self.checkIncompatibleParam("initrd")
if values.symlink:
self.checkIncompatibleParam("symlink")
if values.k:
if not self.logicObj._testKernelDirectory(values.k):
self.optobj.error("%s:'%s'"%
(_("Wrong kernel source directory"),values.k))
(_("wrong kernel source directory"),values.k))
else:
self.logic.clVars.Set('os_kernel_directory',values.k,True)
self.logicObj.clVars.Set('cl_kernel_src_path',values.k,True)
if values.c and values.o:
self.optobj.error(self.getStringIncompatibleOptions(["c","o"]))
self.optobj.error("%s: %s"%(_("incompatible options"),
self.getStringIncompatibleOptions(["c","o"])))
if values.c:
if not path.exists(values.c):
self.optobj.error(_("Kernel config '%s' not found")%values.c)
self.optobj.error(_("kernel config '%s' not found")%values.c)
else:
self.logic.clVars.Set('os_kernel_config',values.c,True)
if values.c == path.join(
self.logicObj.clVars.Get('cl_kernel_src_path'),".config"):
configFile = "%s.bak"%values.c
else:
configFile = values.c
self.logicObj.clVars.Set('cl_kernel_config',configFile,True)
elif values.o:
if not path.exists(
path.join(self.logic.clVars.Get('os_kernel_directory'),
if path.exists(
path.join(self.logicObj.clVars.Get('cl_kernel_src_path'),
".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'),
self.logicObj.clVars.Set('cl_kernel_config',
path.join(self.logicObj.clVars.Get('cl_kernel_src_path'),
".config.bak"),True)
self.optobj.checkVarSyntax(values)
return (values, args)
def makeKernel(self):
return self.logicObj.makeKernel()
def cleanInitrd(self,options):
if not self.logicObj.cleanInitrd():
self.printERROR(_("Failed to optimize initramfs"))
return False
else:
self.printSUCCESS(_("Initramfs successfully optimized"))
return True
def checkEbuildParam(self,options,phase):
return not options.ebuild or os.environ["EBUILD_PHASE"] == phase
def makeKernel(self,options):
"""Run kernel compilation, installation, optimization"""
# if set ebuild param check cur EBUILD_PHASE, run kernel compilation
if self.checkEbuildParam(options,"compile"):
if not self.logicObj.makeKernel(quiet=options.q,
showMenuConfig=options.m,
noClean=options.no_clean,
lvmOpt=options.lvm,
dmraidOpt=options.dmraid,
mdadmOpt=options.mdadm,
mrproper=options.mrproper):
self.printERROR(_("Failed kernel compilation"))
return False
if not self.logicObj.prepareBoot():
self.printERROR(_("Failed prepare boot directory"))
return False
if self.checkEbuildParam(options,"postinst"):
if not self.logicObj.installBootFiles():
self.printERROR(_("Failed kernel install"))
return False
if not self.logicObj.createUidSymlinks():
self.printERROR(_("Failed create uid symlinks"))
return False
if not self.logicObj.versionMigrate():
self.printERROR(_("Failed kernel nomenclature update"))
return False
if not self.logicObj.cleanInitrd():
self.printWARNING(_("Failed initramfs optimization"))
if not self.logicObj.setKernelForCurrent():
self.printWARNING(_("Failed change '%s'")%"/usr/scr/linux")
return True
def makeSymlink(self,options):
"""Set specified kernel to default"""
if not self.logicObj.createUidSymlinks():
self.printERROR(_("Failed create uid symlinks"))
return False
if not self.logicObj.setKernelForCurrent():
self.printWARNING(_("Failed change '%s'")%"/usr/scr/linux")
return False
if not self.logicObj.versionMigrate():
self.printERROR(_("Failed kernel nomenclature update"))
return False
self.printSUCCESS(_("Kernel was changed to '%s'")%
path.basename(self.logicObj._getNewName("vmlinuz")))
return True

@ -19,6 +19,7 @@ import os
from cl_print import color_print
from cl_utils import _error
from cl_builder import BuilderError
# Перевод сообщений для программы
from cl_lang import lang
@ -63,6 +64,8 @@ class share_cmd(color_print, _error):
k,o,v = val.partition('=')
if self.logicObj.clVars.exists(k):
if not self.logicObj.clVars.SetWriteVar(k,v):
self.printERROR(
BuilderError().popBuilderErrors().strip())
return False
else:
self.printERROR(_('variable %s not found')%k)
@ -85,3 +88,24 @@ class share_cmd(color_print, _error):
color_print.colorPrint = lambda *arg : sys.stdout.write(arg[-1]) or\
sys.stdout.flush()
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 checkIncompatibleParam(self,param):
"""Check incompatible options for option specified by param"""
incompatible = list(set(self._getNamesAllSetOptions()) &
set(getattr(self,"options%sIncompatible"%
param.capitalize())))
if incompatible:
self.optobj.error(_("incompatible options")+":"+" %s"\
%self.getStringIncompatibleOptions(incompatible+[param]))

@ -19,7 +19,7 @@
# select - list of posible values for variable
# official - flag, if it is True, then the variable is not printable
# printval - print value of variable
from cl_install import __version__, __app__
from cl_builder import __version__, __app__
class Data:
# relative path for apply templates on files of system
@ -31,11 +31,98 @@ class Data:
# program version
cl_ver = {'value':__version__}
cl_kernel_directory = {}
# kernel sources path
cl_kernel_src_path = {}
# kernel config path
cl_kernel_config = {}
# path which has configs
cl_kernel_config_path = {'mode':'w',
'value':'/var/lib/layman/calculate/profiles/kernel'}
cl_kernel_version = {}
# suffix of kernel
cl_kernel_suffix = {}
# kernel version
cl_kernel_ver = {}
# kernel full version (added extraversion and localversion)
cl_kernel_full_ver = {}
# make opts received from make.conf
os_builder_makeopts = {'mode':'w'}
# path for vmlinuz,initramfs,system.map and config
cl_kernel_boot_path = {'mode':'w'}
# root path for kernel installation (value+lib/modules)
cl_kernel_install_path = {'mode':'w','value':'/'}
# override location of Calckernel's temporary directory
cl_kernel_temp_path = {'mode':'w','value':'/var/calculate/tmp/genkernel'}
# override the default cache location for calckernel
cl_kernel_cache_path = {'mode':'w'}
# is shell in chroot
cl_chroot_status = {}
# need perform templates for builder:iso
cl_builder_iso_action = {}
# need perform templates for builder:squahs
cl_builder_squash_action = {}
# directory for packing
cl_builder_path = {'mode':'w',
'value':'/mnt/builder'}
# directory of system for livecd.squashfs
cl_builder_squash_path = {'mode':'w',
'value':"/livecd.squashfs.dir"}
# directory for iso building
cl_builder_iso_path = {'mode':'w'}
# kernel image
cl_builder_kernel = {}
# initramfs image
cl_builder_initrd_install = {}
# build system name
os_builder_linux_name = {}
# build system subname
os_builder_linux_subname = {}
# build system shortname
os_builder_linux_shortname = {}
# build system ver
os_builder_linux_ver = {'mode':'r'}
# build system arch
os_builder_arch_machine = {}
# build linux system type
os_builder_linux_system = {}
# cd size specified by name (DVD/CD)
cl_builder_cdname = {}
# livecd.squashfs name (may be livecd.squashfs.2 and etc)
cl_builder_current_squash = {}
# livecd.squashfs name for remove (may be livecd.squashfs.2 and etc)
cl_builder_remove_squash = {}
# iso image full path
cl_builder_image = {}
# path which contains images
cl_builder_image_path = {'mode':'w',
'value':['/var/calculate/linux',
'/var/calculate/remote/linux',
'/usr/calculate/share/linux']}

@ -1,7 +1,7 @@
#!/bin/bash
#------------------------------------------------------------------------------
# cl-builder
# Copyright ©2009 Mir Calculate Ltd.
# Copyright ©2009 Calculate Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -51,7 +51,6 @@ watching() {
#------------------------------------------------------------------------------
mountres() {
mount -o bind /var/calculate/remote ${BUILDER}/var/calculate/remote
mount -o bind /usr/calculate/share ${BUILDER}/usr/calculate/share
mount -t proc none ${BUILDER}/proc && mount -o bind /dev ${BUILDER}/dev &&
mount -t sysfs none ${BUILDER}/sys &&
mount -o bind /dev/pts ${BUILDER}/dev/pts && return 0
@ -64,7 +63,7 @@ mountres() {
runchroot() {
touch $EMERGELOG
watching & 2>/dev/null
chroot $BUILDER /bin/bash --rcfile /usr/calculate/install/config/chroot.rc
chroot $BUILDER /bin/bash --rcfile /usr/share/calculate/config/chroot.rc
WATCHINGPID=`ps axo pid,cmd | sed -nr "s|^\s*([0-9]+)\s+${TAILEMERGELOG}.*|\1|p"`
[ "${WATCHINGPID}" ] && kill -9 $WATCHINGPID &>/dev/null
$REMOUNT &>/dev/null
@ -188,6 +187,7 @@ try_update_file() {
# same files in the second directory
#------------------------------------------------------------------------------
update_from_builder() {
waschange=
basesrc=${1%/}
basedest=${2%/}
shift 2
@ -200,8 +200,16 @@ update_from_builder() {
do
dstfile=${dest}/${srcfile#${src}/}
try_update_file $srcfile $dstfile
waschange=1
done
done
curkernellink=$(readlink /boot/vmlinuz-$(cl-kernel -v --filter cl_kernel_uid | \
sed -nr 's/.*\[.\]\s//p'))
newkernellink=vmlinuz-$(cl-kernel -v --filter cl_kernel_suffix | \
sed -nr 's/.*\[.\]\s//p')
[[ "$curkernellink" != "$newkernellink" ]] && \
echo "For used the new kernel in the workspace perform 'cl-kernel --symlink'."
}
update_from_builder $BUILDER $ROOTDIR $UPDATE_DIRS

@ -0,0 +1,54 @@
#!/usr/bin/python
#-*- 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 sys
import os
from os import path
sys.path.insert(0, path.abspath('/usr/lib/calculate-2.2/calculate-lib/pym'))
sys.path.insert(0, path.abspath('/usr/lib/calculate-2.2/calculate-install/pym'))
sys.path.insert(0, path.abspath('/usr/lib/calculate-2.2/calculate-builder/pym'))
from cl_image_cmd import image_cmd
from cl_lang import lang
tr = lang()
tr.setGlobalDomain('cl_builder')
tr.setLanguage(sys.modules[__name__])
if __name__ == "__main__":
image = image_cmd()
image.logicObj.initVars()
# set lang
ret = image.optobj.parse_args()
if ret is False:
sys.exit(1)
options, args = ret
# set color/nocolor for display messages
image.setPrintNoColor(options)
# set values to variables
if not image.setVars(options):
sys.exit(1)
# print variables
if options.v or options.filter or options.xml:
image.printVars(options)
sys.exit(0)
# check root
if not image.isRoot():
sys.exit(1)
if not image.performActionByCommand(options,args):
sys.exit(1)
sys.exit(0)

@ -50,7 +50,12 @@ if __name__ == "__main__":
if not kernel.isRoot():
sys.exit(1)
if not kernel.makeKernel():
if options.initrd:
kernel.cleanInitrd(options)
elif options.symlink:
if not kernel.makeSymlink(options):
sys.exit(1)
elif not kernel.makeKernel(options):
sys.exit(1)
sys.exit(0)

@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# setup.py --- Setup script for calculate-builder
# setup.py --- Setup script for calculate-client
# Copyright 2010 Calculate Ltd. http://www.calculate-linux.org
#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.
@ -19,15 +19,19 @@
import os
import stat
from distutils.core import setup, Extension
from distutils.core import setup
from distutils.command.install_data import install_data
__app__ = "calculate-builder"
__version__ = "2.2.0.0"
data_files = []
var_data_files = []
share_calculate_dir = "/usr/share/calculate"
data_dirs_share = ['i18n']
share_calculate_dir = "/usr/share/calculate"
def __scanDir(scanDir, prefix, replace_dirname, dirData, flagDir=False):
@ -50,7 +54,7 @@ def __scanDir(scanDir, prefix, replace_dirname, dirData, flagDir=False):
scanDir = os.path.join(prefix,scanDir)
dirData.append((scanDir, files))
for sDir in dirs:
__scanDir(sDir, prefix, replace_dirname,dirData, True)
__scanDir(sDir, prefix, replace_dirname, dirData, True)
return dirData
def create_data_files(data_dirs, prefix="", replace_dirname=""):
@ -61,11 +65,40 @@ def create_data_files(data_dirs, prefix="", replace_dirname=""):
data_files += __scanDir(data_dir, prefix, replace_dirname, data)
return data_files
data_files += create_data_files (data_dirs_share, share_calculate_dir)
data_files += create_data_files(data_dirs_share, share_calculate_dir)
data_files += [('/usr/share/calculate/config', ['data/chroot.rc',])]
class cl_install_data(install_data):
def run (self):
install_data.run(self)
data_file = []
fileNames = map(lambda x: os.path.split(x[0])[1], data_file)
listNames = map(lambda x: filter(lambda y: y, x[0].split("/")),data_file)
data_find = {}
for i in range(len(fileNames)):
listNames[i].reverse()
data_find[fileNames[i]] =[listNames[i],data_file[i][1]]
for path in self.get_outputs():
nameFile = os.path.split(path)[1]
if nameFile in data_find.keys():
data = data_find[nameFile][0]
mode = data_find[nameFile][1]
flagFound = True
iMax = len(data)
pathFile = path
for i in range(iMax):
if data[i] != os.path.split(pathFile)[1]:
flagFound = False
break
pathFile = os.path.split(pathFile)[0]
if flagFound:
os.chmod(path, mode)
setup(
name = 'calculate-builder',
version = "2.2.0",
name = __app__,
version = __version__,
description = "Calculate Linux builder",
author = "Calculate Ltd.",
author_email = "support@calculate.ru",
@ -74,6 +107,7 @@ setup(
package_dir = {'calculate-builder': "."},
packages = ['calculate-builder.pym'],
data_files = data_files,
scripts=["./scripts/cl-kernel",
"./scripts/cl-builder"]
scripts=["./scripts/cl-kernel","./scripts/cl-builder",
"./scripts/cl-image"],
cmdclass={'install_data': cl_install_data},
)

Loading…
Cancel
Save