Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Mike Hiretsky | c4d1eef457 | 14 years ago |
Mike Hiretsky | d2c318118a | 14 years ago |
Mike Hiretsky | 5c395f76cb | 14 years ago |
Mike Hiretsky | d174fa5058 | 14 years ago |
Mike Hiretsky | 10deb927f2 | 14 years ago |
Mike Hiretsky | 5589b29ddf | 14 years ago |
Mike Hiretsky | 349ca70fff | 14 years ago |
Mike Hiretsky | 0fa2e62240 | 14 years ago |
Mike Hiretsky | d9c761ab2d | 14 years ago |
Mike Hiretsky | 3db65ea3a3 | 14 years ago |
Mike Hiretsky | 7ebde813e3 | 14 years ago |
Mike Hiretsky | 3af5051bce | 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
|
@ -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
|
@ -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)
|
Loading…
Reference in new issue