diff --git a/i18n/cl_builder_ru.mo b/i18n/cl_builder_ru.mo index fb7542d..8cb38be 100644 Binary files a/i18n/cl_builder_ru.mo and b/i18n/cl_builder_ru.mo differ diff --git a/pym/cl_builder.py b/pym/cl_builder.py index 564a7dd..95a0fd7 100644 --- a/pym/cl_builder.py +++ b/pym/cl_builder.py @@ -23,21 +23,23 @@ import sys import traceback from os import path from cl_utils import process,pathJoin,getRunCommands,getTupleVersion,\ - childMounts + childMounts,_toUNICODE,isMount 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_template import template,iniParser from cl_vars_share import varsShare +from datetime import datetime from cl_kernel_utils import KernelConfig,InitRamFs -from cl_lang import lang from server.utils import dialogYesNo import cl_overriding +from cl_lang import lang +lang().setLanguage(sys.modules[__name__]) class printNoColor: def colorPrint(self,attr,fg,bg,string): @@ -86,6 +88,7 @@ class cl_builder(color_print): self.startMessage = "" self.clTempl = None self.force = False + self.assembleIso = False def setNoColor(self): self.color = False @@ -286,6 +289,7 @@ class cl_builder(color_print): return False elif not self.clVars.Get('cl_builder_kernel'): self.printERROR(_("Can not detect kernel")) + return False elif not self.clVars.Get('cl_builder_initrd_install'): self.printERROR(_("Can not detect initramfs")) return False @@ -322,13 +326,13 @@ class cl_builder(color_print): self.targetDistr.installFrom(self.sourceDistr) self.printByResult(True) - self.targetDistr = PartitionDistributive(rootPartdev,flagRemoveDir=False) - dd = DirectoryDistributive(mp,parent=self.targetDistr) - self.removeVars('os_assemble_linux_ver', 'os_assemble_linux_shortname', - 'cl_assemble_image', 'cl_assemble_step_system', - 'cl_assemble_make', 'cl_assemble_step_world', - 'cl_assemble_step_newuse', 'cl_assemble_step_update', - 'cl_assemble_path') + #self.targetDistr = PartitionDistributive(rootPartdev,flagRemoveDir=False) + #dd = DirectoryDistributive(mp,parent=self.targetDistr) + #self.removeVars('os_assemble_linux_ver', 'os_assemble_linux_shortname', + # 'cl_assemble_image', 'cl_assemble_step_system', + # 'cl_assemble_make', 'cl_assemble_step_world', + # 'cl_assemble_step_newuse', 'cl_assemble_step_update', + # 'cl_assemble_path') return True def removeVars(self,*varsname): @@ -424,6 +428,8 @@ class cl_builder(color_print): self.printMessageForTest(_("Unmount built system volume")) self.targetDistr.close() self.printByResult(True) + if self.assembleIso: + self.restoreMount() except (BuilderError,DistributiveError),e: error = "%s\n%s" % (str(error),_("Unmounting error")) except KeyboardInterrupt,e: @@ -437,3 +443,44 @@ class cl_builder(color_print): return False self.printSUCCESS(_("System has built successfully")) return True + + def restoreMount(self): + """Mount /proc,/sys, remote, /dev to chroot""" + mountResources = (("/dev",None,None), + ("/dev/shm",None,None), + ("/dev/pts",None,None), + (None,"-t proc","/proc"), + (None,"-t sysfs","/sys"), + ("/var/calculate/remote",None,None)) + assemblePath = self.clVars.Get('cl_builder_path') + 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) + if source == isMount(target): + continue + args = ["mount"]+opts.split()+[str(source).lower(),target] + mountProcess = process(*args) + if mountProcess.failed(): + raise BuilderError(_("Can not mount %(from)s to %(to)s")% + {'from':source,'to':target}) + self.printByResult(True) + + def setAssembleData(self): + """Get assemble data from assemble.env""" + self.assembleIso = True + section = (self.clVars.Get('os_builder_linux_shortname'), + self.clVars.Get('os_builder_arch_machine')) + envFile = '/etc/calculate/assemble.env' + envData = iniParser(envFile) + self.clVars.Set('cl_builder_path', _toUNICODE(envData.getVar(section, + 'cl_assemble_path')).encode('utf-8'),True) + linuxver = _toUNICODE(envData.getVar(section, + 'os_assemble_linux_ver')).encode('utf-8') + if not linuxver: + curdate = datetime.now() + linuxver = "%04d%02d%02d"%(curdate.year,curdate.month,curdate.day) + self.clVars.Set('os_builder_linux_ver',linuxver ,True) diff --git a/pym/cl_image_cmd.py b/pym/cl_image_cmd.py index 154577a..42604e7 100644 --- a/pym/cl_image_cmd.py +++ b/pym/cl_image_cmd.py @@ -17,6 +17,8 @@ from cl_builder import cl_builder, __app__, __version__ from cl_opt import opt from cl_share_cmd import share_cmd +from cl_vars_share import varsShare +from cl_utils import _toUNICODE import os from os import path from os import access,R_OK @@ -28,11 +30,27 @@ from cl_template import iniParser from cl_lang import lang lang().setLanguage(sys.modules[__name__]) +OSSYSTEM_LIST=sorted(varsShare.dictNameSystem.keys()) DESCRIPTION = _("The Calculate Linux image builder") CMD_OPTIONS = [{'shortOption':"f", 'longOption':"force", 'help':_("no questions during the creating process") + }, + {'shortOption':"s", + 'longOption':"os", + 'optVal':"SYSTEM", + 'type':'choice', + 'choices_regignore':OSSYSTEM_LIST, + 'help':_("select operation system")+ + " (%s)"%",".join(OSSYSTEM_LIST) + }, + {'longOption':"march", + 'optVal':"ARCH", + 'type':'choice', + 'choices':['x86_64','i686'], + 'help':_("select arch for operation system") + + " (%s)"%_("i686 or x86_64") }] USAGE = _("%prog [options] iso|squash") @@ -48,28 +66,39 @@ class image_cmd(share_cmd): check_values=self.checkOpts) self.logicObj = cl_builder() self.commands = ["iso","squash"] + self.envFile = "/etc/calculate/assemble.env" #self.optionsInitrdIncompatible = ["o","no_clean","m","mdadm","lvm", # "k", "e","dmraid","c","ebuild", # "symlink"] - def isScratch(self): + def __sectionName(self): + """Get section name of assemble.env by shortname and arch""" + return (self.logicObj.clVars.Get('os_builder_linux_shortname'), + self.logicObj.clVars.Get('os_builder_arch_machine')) + + def isScratch(self,showError=True): """Detect scartch system""" - if self.logicObj.clVars.Get('os_scratch') == 'on': - return True - else: - self.printERROR(_("You should load system in the builder mode.")) - return False + if not path.exists(self.envFile) \ + or not self.logicObj.clVars.Get('cl_builder_path'): + if self.logicObj.clVars.Get('os_scratch') == 'on': + return True + else: + if showError: + self.printERROR( + _("You should load system in the builder mode")) + return False + return False - def isAssemble(self): + def isAssemble(self,showError=True): """Detect system assembling""" - detectAssemble = re.compile("^\[assemble\]",re.S) - if filter(detectAssemble.search, - open("/etc/calculate/calculate2.env",'r')): - inidata = iniParser(inifile) - res = inidata.getVar("assemble","cl_assemble_step_world", + if path.exists(self.envFile) \ + and self.logicObj.clVars.Get('cl_builder_path'): + inidata = iniParser(self.envFile) + res = inidata.getVar(self.__sectionName(),"cl_assemble_step_world", checkExistVar=True) if not res[0] or not "finish" in _toUNICODE(res[1]).encode('utf-8'): - self.printERROR(_("System assembling was not completed.")) + if showError: + self.printERROR(_("System assembling was not completed.")) return False return True else: @@ -90,6 +119,21 @@ class image_cmd(share_cmd): if args: self.logicObj.clVars.Set('cl_action',args[0],True) + if values.s: + if self.isScratch(False): + self.optobj.error(_("'-s' not used in scratch mode")) + self.logicObj.clVars.Set('os_builder_linux_shortname', + values.s.upper(),True) + if values.march: + if self.isScratch(False): + self.optobj.error(_("'--march' not used in scratch mode")) + self.logicObj.clVars.Set('os_builder_arch_machine', + values.march.lower(),True) + + if not self.isScratch(False) \ + and path.exists(self.envFile): + self.logicObj.setAssembleData() + if args and args[0] == "squash": self.logicObj.clVars.Set('cl_builder_iso_path','/mnt/flash',True) self.optobj.checkVarSyntax(values)