Append action for configure, add action break.

To configure append applying templates and mounting directories.
develop
parent 0df7f999b6
commit 5722537a5a

Binary file not shown.

@ -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)

@ -49,11 +49,14 @@ CMD_OPTIONS = [{'shortOption':"d",
'longOption':"make",
'help':_("make system")
},
{'longOption':"break",
'help':_("break system assembling")
},
{'longOption':"linuxver",
'optVal':"VER",
'help':_("version of assembling system")
}]
USAGE = _("%prog [options] -m|-c")
USAGE = _("%prog [options] -make|-configure|--break")
class assemble_cmd(share_cmd):
"""Class for work with cl_assemble by console"""
@ -66,10 +69,8 @@ class assemble_cmd(share_cmd):
opt.color_control,
check_values=self.checkOpts)
self.logicObj = cl_assemble()
self.optionsMakeIncompatible=["c"]
#self.optionsInitrdIncompatible = ["o","no_clean","m","mdadm","lvm",
# "k", "e","dmraid","c","ebuild",
# "symlink"]
self.optionsMakeIncompatible=["c","break"]
self.optionsBreakIncompatible=["m","c","s","linuxver"]
def checkOpts(self, values, args):
"""Check values all specified options."""
@ -78,9 +79,12 @@ class assemble_cmd(share_cmd):
if not values.v:
if values.m:
self.checkIncompatibleParam("make")
if not (values.c or values.m):
if getattr(values,"break"):
self.checkIncompatibleParam("break")
if not (values.c or values.m or getattr(values,"break")):
self.optobj.error(
_("need specify action: configure (-c) or make (-m)"))
_("need specify action: configure (-c), make (-m) or"
" break (--break)"))
if values.c and not values.d and \
not self.logicObj.clVars.Get('os_assemble_root_dev'):
self.optobj.error(
@ -98,7 +102,10 @@ class assemble_cmd(share_cmd):
def setAction(self):
"""Set action by configuration or install system"""
self.logicObj.clVars.Set('cl_action', "configure",True)
if getattr(self.optobj.values,"break"):
self.logicObj.setAction("break")
else:
self.logicObj.setAction("configure")
def configureSystem(self,force):
"""Unpack stage and prepare for assemble"""
@ -110,3 +117,9 @@ class assemble_cmd(share_cmd):
"""Compile all packages for system"""
self.printERROR(_("Make system has not supported yet."))
return False
def breakAssembling(self,force):
"""Perform break assembling: unmount all resourse for assembling"""
if not self.logicObj.breakAssembling(force):
return False
return True

@ -23,10 +23,18 @@ from os import path
from cl_distr import DistributiveRepository
from cl_template import iniParser
from cl_fill_install import fillVars as installFillVars
from cl_utils import _toUNICODE
from cl_vars import Data as libData
from cl_utils import _toUNICODE,isMount,pathJoin
from datetime import datetime
class fillVars(installFillVars):
def get_cl_assemble_prepare_action(self):
"""Need perform templates for assemble:prepare"""
if self.Get('cl_action') == 'configure':
return "up"
else:
return ""
def get_os_assemble_linux_shortname(self):
"""Get short system name"""
if self.Get('cl_action') == 'configure':
@ -78,6 +86,8 @@ class fillVars(installFillVars):
'/usr/calculate/share/linux',
'/var/calculate/remote/stages/',
'/usr/calculate/share/stages/']
else:
return []
def get_os_assemble_linux_system(self):
"""Get assemble linux system (server or desktop)"""
@ -120,7 +130,7 @@ class fillVars(installFillVars):
def get_os_assemble_root_dev(self):
"""Get device for assembling"""
paths = map(lambda x:x[1],reversed(self.Get('cl_env_data')))
paths = map(lambda x:x[1],reversed(libData.cl_env_data['value']))
for inifile in paths:
if os.access(inifile,os.R_OK):
inidata = iniParser(inifile)
@ -130,6 +140,14 @@ class fillVars(installFillVars):
return _toUNICODE(res[1]).encode('utf-8')
return ""
def get_cl_assemble_path(self):
rootDev = self.Get('os_assemble_root_dev')
if rootDev:
mp = isMount(rootDev)
if mp:
return mp
return '/mnt/builder'
def get_os_disk_dev(self):
reSdaPart = re.compile("^/dev/sd([a-z])(\d+)$")
devices = self.Get('os_device_hash').keys()
@ -138,3 +156,5 @@ class fillVars(installFillVars):
filter(lambda x: y in x,os.listdir('/sys/block/%s'%y))),
devices, [] )
return disks
get_os_assemble_makeopts = installFillVars.get_os_install_makeopts

@ -31,6 +31,9 @@ class Data:
# program version
cl_ver = {'value':__version__}
# need perform templates for assemble:prepare
cl_assemble_prepare_action = {}
# system image for installation
cl_assemble_image = {}
@ -43,7 +46,7 @@ class Data:
# path which contains images
cl_assemble_image_path = {}
cl_assemble_path = {'value':'/mnt/builder'}
cl_assemble_path = {}
# linux version of assembling system
os_assemble_linux_ver = {'mode':'w'}
@ -80,3 +83,6 @@ class Data:
# list of available partition devices
os_disk_dev = {}
# makeconf makeopts
os_assemble_makeopts = {'mode':'w'}

@ -55,4 +55,7 @@ if __name__ == "__main__":
if options.m:
if not assemble.compileSystem():
sys.exit(1)
if getattr(options,"break"):
if not assemble.breakAssembling(options.f):
sys.exit(1)
sys.exit(0)

Loading…
Cancel
Save