Add variables and action for unpack stage image into assembling root.

develop
parent ada501e527
commit 0df7f999b6

Binary file not shown.

@ -23,15 +23,18 @@ import sys
import traceback
from os import path
from cl_template import template
from cl_utils import process,pathJoin,getRunCommands,getTupleVersion
from cl_utils import process,pathJoin,getRunCommands,getTupleVersion,isMount,\
isFstabMount
from subprocess import STDOUT,PIPE
from cl_print import color_print
from cl_datavars import DataVars
from cl_distr import IsoDistributive, DirectoryDistributive, \
DistributiveError
DistributiveError, PartitionDistributive, \
DistributiveRepository, ArchiveDistributive
from cl_vars_share import varsShare
from cl_lang import lang
lang().setLanguage(sys.modules[__name__])
from server.utils import dialogYesNo
import cl_overriding
@ -136,6 +139,100 @@ class cl_assemble(color_print):
self.startMessage = ""
self.lenStartMessage = 0
def printInfo(self):
self.printSUCCESS(_("Preparing for 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(_("Stage for assembling: %s")%
self.clVars.Get('cl_assemble_image'))
self.printSUCCESS(_("Portage snapshot for assembling: %s")%
self.clVars.Get('cl_assemble_snapshot_portage'))
self.defaultPrint("%s\n"%_("Perform pre-assemble checkups"))
self.defaultPrint("\n")
if not self.clVars.Get('cl_assemble_image'):
self.printWARNING("No path for image creating.")
def preassembleCheckups(self):
dev = self.clVars.Get('os_assemble_root_dev')
mp = isFstabMount(dev)
if mp:
self.printERROR(
_("'%(dev)s' is used as '%(mp)s' in current system")%
{'dev':dev,'mp':mp})
return False
mp = isMount(dev)
if mp:
self.printERROR(_("'%(dev)s' already mounted to '%(mp)s'")%
{'dev':dev,'mp':mp})
return False
return True
def configureFunc(self,force=False):
rootPartdev = self.clVars.Get('os_assemble_root_dev')
formatId = PartitionDistributive.formatId
fileSystem = self.clVars.Get('os_assemble_root_format')
self.printInfo()
if not self.preassembleCheckups():
return False
self.targetDistr = PartitionDistributive(rootPartdev,
mdirectory=self.clVars.Get('cl_assemble_path'),
check=True, fileSystem=fileSystem, isFormat=True,
systemId=formatId.get(fileSystem,"83"),
rootLabel="%s-%s"%
(self.clVars.Get('os_assemble_linux_shortname'),
self.clVars.Get('os_assemble_linux_ver')))
distRep = DistributiveRepository()
distName = self.clVars.Get('cl_assemble_image')
stageName = self.clVars.Get('cl_assemble_snapshot_portage')
if distName:
# print info
self.sourceDistr = distRep.getDistributiveByFile(distName)
if not force:
dialogMessage = \
_("Continue with the 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 assembling"))
return False
self.printMessageForTest(_("Formating partitions"))
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"))
portageSources = ArchiveDistributive(stageName)
portageTarget = DirectoryDistributive(
path.join(assemblePath+"usr/portage"))
portageTarget.installFrom(portageSources)
self.printByResult(True)
return True
return False
def configureSystem(self,force):
"""Unpack stage or cls|css and prepare for assemble"""
return self.make(self.configureFunc,force)
def make(self,logicFunc,*argv):
"""Make iso image by variables"""
self.sourceDistr = None
@ -156,9 +253,14 @@ class cl_assemble(color_print):
self.printByResult(False)
self.printWARNING("Interrupting the system assembling")
error = _("System assembling manually interrupt")
if error:
self.printByResult(False)
try:
if error:
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:

@ -26,7 +26,11 @@ from cl_lang import lang
lang().setLanguage(sys.modules[__name__])
DESCRIPTION = _("The Calculate Linux system assemble")
CMD_OPTIONS = [{'shortOption':"f",
CMD_OPTIONS = [{'shortOption':"d",
'longOption':"disk",
'help':_("building system volume")
},
{'shortOption':"f",
'longOption':"force",
'help':_("no questions during the creating process")
},
@ -36,8 +40,20 @@ CMD_OPTIONS = [{'shortOption':"f",
'type':'choice',
'choices':['cld','cds','cls','css','cldg','cldx'],
'help':_("select operation system")
},
{'shortOption':"c",
'longOption':"configure",
'help':_("prepare system for building")
},
{'shortOption':"m",
'longOption':"make",
'help':_("make system")
},
{'longOption':"linuxver",
'optVal':"VER",
'help':_("version of assembling system")
}]
USAGE = _("%prog [options]")
USAGE = _("%prog [options] -m|-c")
class assemble_cmd(share_cmd):
"""Class for work with cl_assemble by console"""
@ -50,6 +66,7 @@ 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"]
@ -58,12 +75,38 @@ class assemble_cmd(share_cmd):
"""Check values all specified options."""
if len(args) > 0:
self.optobj.error(_("unrecognized option") + ": %s"% "".join(args))
if not values.v:
if values.m:
self.checkIncompatibleParam("make")
if not (values.c or values.m):
self.optobj.error(
_("need specify action: configure (-c) or make (-m)"))
if values.c and not values.d and \
not self.logicObj.clVars.Get('os_assemble_root_dev'):
self.optobj.error(
_("need specify disk by '-d' option"))
if values.d:
self.logicObj.clVars.Set('os_assemble_root_dev',values.d,True)
if values.s:
self.logicObj.clVars.Set('os_assemble_linux_shortname',
values.s.upper(),True)
if values.linuxver:
self.logicObj.clVars.Set('os_assemble_linux_ver',
values.linuxver,True)
self.optobj.checkVarSyntax(values)
return (values, args)
def setAction(self):
"""Set action by configuration or install system"""
self.logicObj.clVars.Set('cl_action', "configure",True)
def configureSystem(self,force):
"""Unpack stage and prepare for assemble"""
if not self.logicObj.configureSystem(force):
return False
return True
def compileSystem(self):
"""Compile all packages for system"""
self.printERROR(_("Make system has not supported yet."))
return False

@ -21,9 +21,12 @@ import operator
from cl_vars_share import varsShare
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 datetime import datetime
class fillVars(object, varsShare):
class fillVars(installFillVars):
def get_os_assemble_linux_shortname(self):
"""Get short system name"""
if self.Get('cl_action') == 'configure':
@ -61,7 +64,8 @@ class fillVars(object, varsShare):
if self.Get('os_assemble_linux_shortname') == \
self.Get('os_linux_shortname'):
return self.Get('os_linux_ver')
return ""
curdate = datetime.now()
return "%d.%d"%(curdate.year-2000,curdate.month)
def get_os_assemble_arch_machine(self):
"""Marching architecture for assembling"""
@ -113,3 +117,24 @@ class fillVars(object, varsShare):
return DistributiveRepository()._findLatestFile(snapshotPaths,
re.compile(r'^.*/portage-(\d+)\.tar\.bz2$',re.S),
lambda x:x.groups()[0])
def get_os_assemble_root_dev(self):
"""Get device for assembling"""
paths = map(lambda x:x[1],reversed(self.Get('cl_env_data')))
for inifile in paths:
if os.access(inifile,os.R_OK):
inidata = iniParser(inifile)
res = inidata.getVar("install","os_install_dev_from",
checkExistVar=True)
if res[0]:
return _toUNICODE(res[1]).encode('utf-8')
return ""
def get_os_disk_dev(self):
reSdaPart = re.compile("^/dev/sd([a-z])(\d+)$")
devices = self.Get('os_device_hash').keys()
disks = reduce( lambda x,y: x +
map( lambda x: "/dev/%s"%x,
filter(lambda x: y in x,os.listdir('/sys/block/%s'%y))),
devices, [] )
return disks

@ -90,4 +90,25 @@ class share_cmd(color_print, _error):
if optObj.color and optObj.color=="never":
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):
"""Formated string incompatible options which separated ','"""
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]))

@ -62,3 +62,21 @@ class Data:
# arch of assembling os
os_assemble_arch_machine = {}
# device for assembling
os_assemble_root_dev = {}
os_assemble_root_format = {'mode':'w',
'value':'reiserfs'}
# infomation about disk in hash
os_device_hash = {'hide':True}
# devices
os_device_dev = {}
# device type (hdd,cdrom,usb-flash)
os_device_type = {}
# list of available partition devices
os_disk_dev = {}

@ -49,4 +49,10 @@ if __name__ == "__main__":
# check root
if not assemble.isRoot():
sys.exit(1)
if options.c:
if not assemble.configureSystem(options.f):
sys.exit(1)
if options.m:
if not assemble.compileSystem():
sys.exit(1)
sys.exit(0)

Loading…
Cancel
Save