|
|
|
@ -24,7 +24,7 @@ import traceback
|
|
|
|
|
from os import path
|
|
|
|
|
from cl_template import template
|
|
|
|
|
from cl_utils import process,pathJoin,getRunCommands,getTupleVersion,isMount,\
|
|
|
|
|
isFstabMount
|
|
|
|
|
isFstabMount,childMounts
|
|
|
|
|
from subprocess import STDOUT,PIPE
|
|
|
|
|
from cl_print import color_print
|
|
|
|
|
from cl_datavars import DataVars
|
|
|
|
@ -36,6 +36,7 @@ from cl_vars_share import varsShare
|
|
|
|
|
from cl_lang import lang
|
|
|
|
|
lang().setLanguage(sys.modules[__name__])
|
|
|
|
|
from server.utils import dialogYesNo
|
|
|
|
|
import cl_install
|
|
|
|
|
import cl_overriding
|
|
|
|
|
|
|
|
|
|
class printNoColor:
|
|
|
|
@ -95,10 +96,8 @@ class cl_assemble(color_print):
|
|
|
|
|
self.clVars.importAssemble()
|
|
|
|
|
self.clVars.flIniFile()
|
|
|
|
|
|
|
|
|
|
def applyTemplatesForSquash(self,directory):
|
|
|
|
|
def applyConfigureTemplates(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()
|
|
|
|
@ -110,6 +109,7 @@ class cl_assemble(color_print):
|
|
|
|
|
|
|
|
|
|
def printMessageForTest(self, message, lenMsg=False):
|
|
|
|
|
"""Print waiting message and OK or Error by func result"""
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
message = "%s ..." % message
|
|
|
|
|
self.printSUCCESS(message,printBR=False)
|
|
|
|
|
self.startMessage = message
|
|
|
|
@ -162,6 +162,24 @@ class cl_assemble(color_print):
|
|
|
|
|
if not self.clVars.Get('cl_assemble_image'):
|
|
|
|
|
self.printWARNING("No path for image creating.")
|
|
|
|
|
|
|
|
|
|
def printBreakInfo(self):
|
|
|
|
|
self.printSUCCESS(_("Breaking assembling of") + " Calculate Linux")
|
|
|
|
|
self.defaultPrint("%s\n"%_("System information"))
|
|
|
|
|
subname = self.clVars.Get('os_assemble_linux_subname')
|
|
|
|
|
subname = (" %s"%subname) if subname else ""
|
|
|
|
|
self.printSUCCESS(_("Assembling system")+": %s"%
|
|
|
|
|
self.clVars.Get('os_assemble_linux_name')+subname)
|
|
|
|
|
self.printSUCCESS(_("System version")+": %s"%
|
|
|
|
|
self.clVars.Get('os_assemble_linux_ver'))
|
|
|
|
|
self.printSUCCESS(_("Machine hardware name")+": %s"%
|
|
|
|
|
self.clVars.Get('os_assemble_arch_machine'))
|
|
|
|
|
self.printSUCCESS(_("Partition for assembling: %s")%
|
|
|
|
|
self.clVars.Get('os_assemble_root_dev'))
|
|
|
|
|
self.printSUCCESS(_("System is assembled into directory: %s")%
|
|
|
|
|
self.clVars.Get('cl_assemble_path'))
|
|
|
|
|
|
|
|
|
|
self.defaultPrint("\n")
|
|
|
|
|
|
|
|
|
|
def preassembleCheckups(self):
|
|
|
|
|
dev = self.clVars.Get('os_assemble_root_dev')
|
|
|
|
|
mp = isFstabMount(dev)
|
|
|
|
@ -211,36 +229,106 @@ class cl_assemble(color_print):
|
|
|
|
|
if dialogRes in (None,False):
|
|
|
|
|
self.printERROR(_("Interrupting the assembling"))
|
|
|
|
|
return False
|
|
|
|
|
self.printMessageForTest(_("Formating partitions"))
|
|
|
|
|
# format partion
|
|
|
|
|
self.printMessageForTest(_("Formating partition"))
|
|
|
|
|
self.targetDistr.performFormat()
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
|
|
|
|
|
self.printMessageForTest(_("Unpacking stage image into target"))
|
|
|
|
|
self.targetDistr.installFrom(self.sourceDistr)
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
assemblePath = self.targetDistr.convertToDirectory().getDirectory()
|
|
|
|
|
self.clVars.Set('cl_assemble_path', assemblePath, True)
|
|
|
|
|
|
|
|
|
|
self.printMessageForTest(_("Unpacking portage"))
|
|
|
|
|
assemblePath = \
|
|
|
|
|
self.targetDistr.convertToDirectory().getDirectory()
|
|
|
|
|
self.clVars.Set('cl_assemble_path', assemblePath, True)
|
|
|
|
|
portageSources = ArchiveDistributive(stageName)
|
|
|
|
|
portageTarget = DirectoryDistributive(
|
|
|
|
|
path.join(assemblePath+"usr/portage"))
|
|
|
|
|
path.join(assemblePath,"usr"))
|
|
|
|
|
portageTarget.installFrom(portageSources)
|
|
|
|
|
|
|
|
|
|
self.printMessageForTest(_("Configurate assembling system"))
|
|
|
|
|
self.applyConfigureTemplates(assemblePath)
|
|
|
|
|
|
|
|
|
|
mountResources = ((None,"-t proc","/proc"),
|
|
|
|
|
(None,"-t sysfs","/sys"),
|
|
|
|
|
("/var/calculate/remote",None,None),
|
|
|
|
|
("/dev",None,None),
|
|
|
|
|
("/dev/pts",None,None))
|
|
|
|
|
for source,opts,target in mountResources:
|
|
|
|
|
opts = opts or "-o bind"
|
|
|
|
|
target = target or source
|
|
|
|
|
self.printMessageForTest(_("Mounting %s")%(source or target))
|
|
|
|
|
target = pathJoin(assemblePath,target)
|
|
|
|
|
if not path.exists(target):
|
|
|
|
|
os.makedirs(target,mode=0755)
|
|
|
|
|
args = ["mount"]+opts.split()+[str(source).lower(),target]
|
|
|
|
|
mountProcess = process(*args)
|
|
|
|
|
if mountProcess.failed():
|
|
|
|
|
raise AssembleError(_("Can not mount %(from)s to %(to)s")%
|
|
|
|
|
{'from':source,'to':target})
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def configureSystem(self,force):
|
|
|
|
|
"""Unpack stage or cls|css and prepare for assemble"""
|
|
|
|
|
self.msgOperationComplete = \
|
|
|
|
|
_("System was have prepared for assembling successfully")
|
|
|
|
|
self.msgOperationFailed = \
|
|
|
|
|
_("Preparing for assembling failed")
|
|
|
|
|
return self.make(self.configureFunc,force)
|
|
|
|
|
|
|
|
|
|
def breakFunc(self,force):
|
|
|
|
|
rootPartdev = self.clVars.Get('os_assemble_root_dev')
|
|
|
|
|
mp = isMount(rootPartdev)
|
|
|
|
|
if not mp:
|
|
|
|
|
self.printERROR(_("For performance of operation it is "
|
|
|
|
|
"necessary to configure system")+".")
|
|
|
|
|
self.printERROR(_('Execute with parameter')+' "--configure".')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
self.printBreakInfo()
|
|
|
|
|
if not force:
|
|
|
|
|
dialogMessage = \
|
|
|
|
|
_("Continue breaking assembling of the system") + \
|
|
|
|
|
" (yes/no)"
|
|
|
|
|
try:
|
|
|
|
|
dialogRes = dialogYesNo(dialogMessage)
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
self.defaultPrint("\n")
|
|
|
|
|
raise KeyboardInterrupt
|
|
|
|
|
if dialogRes in (None,False):
|
|
|
|
|
self.printERROR(_("Interrupting the breaking"))
|
|
|
|
|
return False
|
|
|
|
|
mps = filter(lambda x:x!=mp,map(lambda x:x[1],childMounts(mp)))
|
|
|
|
|
for target in sorted(mps, reverse=True):
|
|
|
|
|
self.printMessageForTest(_("Unmounting %s")%(target[len(mp):]))
|
|
|
|
|
umountProcess = process("umount",target)
|
|
|
|
|
if umountProcess.failed():
|
|
|
|
|
raise AssembleError(_("Can not umount %s")%target)
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
self.targetDistr = PartitionDistributive(rootPartdev)
|
|
|
|
|
dd = DirectoryDistributive(mp,parent=self.targetDistr)
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def breakAssembling(self,force):
|
|
|
|
|
self.msgOperationComplete = \
|
|
|
|
|
_("Break of system assembling is successfully")
|
|
|
|
|
self.msgOperationFailed = \
|
|
|
|
|
_("Breaking of system assembling failed")
|
|
|
|
|
return self.make(self.breakFunc,force)
|
|
|
|
|
|
|
|
|
|
def make(self,logicFunc,*argv):
|
|
|
|
|
"""Make iso image by variables"""
|
|
|
|
|
self.sourceDistr = None
|
|
|
|
|
self.targetDistr = None
|
|
|
|
|
error = None
|
|
|
|
|
try:
|
|
|
|
|
if not logicFunc(*argv):
|
|
|
|
|
return False
|
|
|
|
|
try:
|
|
|
|
|
if not logicFunc(*argv):
|
|
|
|
|
return False
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
raise KeyboardInterrupt
|
|
|
|
|
except (EOFError), e:
|
|
|
|
|
error = e
|
|
|
|
|
except (AssembleError,DistributiveError),e:
|
|
|
|
@ -250,34 +338,51 @@ class cl_assemble(color_print):
|
|
|
|
|
for i in apply(traceback.format_exception, sys.exc_info()):
|
|
|
|
|
error += i
|
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
|
self.defaultPrint("\b\b")
|
|
|
|
|
self.printByResult(False)
|
|
|
|
|
self.printWARNING("Interrupting the system assembling")
|
|
|
|
|
self.printWARNING(_("Interrupting the system assembling"))
|
|
|
|
|
error = _("System assembling manually interrupt")
|
|
|
|
|
try:
|
|
|
|
|
if error:
|
|
|
|
|
if self.clTempl:
|
|
|
|
|
self.clTempl.closeFiles()
|
|
|
|
|
if error or logicFunc == self.breakFunc:
|
|
|
|
|
self.printByResult(False)
|
|
|
|
|
if self.targetDistr:
|
|
|
|
|
self.printMessageForTest(
|
|
|
|
|
_("Releasing partition for assembling"))
|
|
|
|
|
self.targetDistr.close()
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
if self.clTempl:
|
|
|
|
|
self.clTempl.closeFiles()
|
|
|
|
|
if self.sourceDistr:
|
|
|
|
|
self.printMessageForTest(_("Releasing source data"))
|
|
|
|
|
self.sourceDistr.close()
|
|
|
|
|
self.printByResult(True)
|
|
|
|
|
except (AssembleError,DistributiveError),e:
|
|
|
|
|
error = "%s\n%s" % (str(error),_("Unmounting error"))
|
|
|
|
|
if error:
|
|
|
|
|
error = "%s\n%s" % (str(error),_("Unmounting error"))
|
|
|
|
|
else:
|
|
|
|
|
error = _("Unmounting error")
|
|
|
|
|
except KeyboardInterrupt,e:
|
|
|
|
|
pass
|
|
|
|
|
self.defaultPrint("\b\b")
|
|
|
|
|
error = _("Unmounting error")
|
|
|
|
|
if error:
|
|
|
|
|
self.printByResult(False)
|
|
|
|
|
if error:
|
|
|
|
|
for line in filter(lambda x: x,str(error).split('\n')):
|
|
|
|
|
self.printERROR(line)
|
|
|
|
|
self.printERROR(_("Preparing for assembling failed"))
|
|
|
|
|
self.printERROR(self.msgOperationFailed)
|
|
|
|
|
return False
|
|
|
|
|
self.printSUCCESS(
|
|
|
|
|
_("System was have prepared for assembling successfully"))
|
|
|
|
|
self.printSUCCESS(self.msgOperationComplete)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def setAction(self,action):
|
|
|
|
|
if action == "break":
|
|
|
|
|
self.clVars.Set("cl_action","break",True)
|
|
|
|
|
rootPartdev = self.clVars.Get('os_assemble_root_dev')
|
|
|
|
|
mp = isMount(rootPartdev)
|
|
|
|
|
if mp:
|
|
|
|
|
envData = map(lambda x:map(lambda x:pathJoin(mp,x),x),
|
|
|
|
|
self.clVars.Get('cl_env_data'))
|
|
|
|
|
self.clVars.Set('cl_env_data', envData,True)
|
|
|
|
|
self.clVars.flIniFile()
|
|
|
|
|
else:
|
|
|
|
|
self.clVars.Set("cl_action","configure",True)
|
|
|
|
|