def initVars(self,datavars=None): """Primary initialization of variables""" if not datavars: self.clVars = DataVarsInstall() self.clVars.importInstall() self.clVars.flIniFile() else: self.clVars = datavars
class Install(color_print): """Primary class for templates appling and system installation""" def __init__(self): self.clVars = None self.clTempl = None self.listDisksOptions = [] self.listBindsOptions = [] self.listSwapsOptions = [] self.startMessage = "" self.lenStartMessage = 0 self.stdoutHide = None self.stderrHide = None # refresh information about LVM refreshLVM() # refresh information about device in udevadm info refreshUdev() def setNoColor(self): self.color = False def initVars(self,datavars=None): """Primary initialization of variables""" if not datavars: self.clVars = DataVarsInstall() self.clVars.importInstall() self.clVars.flIniFile() else: self.clVars = datavars def canInstallGrub2(self,target): """Check that system has grub2 in current and installed system""" if self.clVars.Get('os_grub2_path'): return bool( filter(lambda x:x.startswith('grub-1.99') or \ x.startswith('grub-2'), listDirectory('/var/db/pkg/sys-boot'))) return False def prepareBoot(self,targetDistr): """Prepare system for boot""" if self.clVars.Get('os_install_root_type') == "flash": self.installSyslinuxBootloader(targetDistr) else: if self.canInstallGrub2(targetDistr): self.installGrub2Bootloader(targetDistr) else: self.installLegacyGrubBootloader(targetDistr) def closeClTemplate(self,error=None): if self.clTempl: if self.clTempl.cltObj: self.clTempl.cltObj.closeFiles() self.clTempl.closeFiles() self.clTempl = None def applyTemplatesStartup(self): """Apply templates for root of system.""" #self.clVars.Set("cl_root_path","/", True) self.clVars.Set("cl_chroot_path","/", True) templates_locate = self.clVars.Get('cl_templates_locate') # cltObj = True if 'clt' in templates_locate else False dirs_list, files_list = ([],[]) useClt = "clt" in templates_locate self.clVars.Set("cl_template_path", map(lambda x:x[1], filter(lambda x:x[0] in templates_locate, zip(self.clVars.Get('cl_template_location'), self.clVars.Get('cl_template_path')))), True) self.clTempl = ProgressTemplate(self.setProgress, self.clVars, cltObj=useClt, cltFilter=True if self.clVars.Get('cl_merge_set') == "on" \ else False, printSUCCESS=self.printSUCCESS, printWARNING=self.printWARNING, askConfirm=self.askConfirm, dispatchConf=self.dispatchConf, printERROR=self.printERROR) dirsFiles = self.clTempl.applyTemplates() try: if self.clTempl.getError(): self.printERROR(self.clTempl.getError()) return False except AttributeError: pass return dirsFiles def applyTemplatesFlash(self,directory): """Apply templates for root of system.""" #self.clVars.Set("cl_root_path",directory, True) self.clVars.Set("cl_chroot_path","/", True) self.clVars.Set("cl_chroot_grub","/", True) self.clVars.Set("cl_root_path",directory, True) self.clTempl = ProgressTemplate(self.setProgress,self.clVars, cltObj=False, printSUCCESS=self.printSUCCESS, printWARNING=self.printWARNING, askConfirm=self.askConfirm, printERROR=self.printERROR) dirsFiles = self.clTempl.applyTemplates() if self.clTempl.getError(): raise InstallError(self.clTempl.getError()) else: return dirsFiles def applyTemplates(self,directory,grubDirectory): """Apply templates for root of system.""" self.clVars.Set("cl_chroot_path",directory, True) self.clVars.Set("cl_chroot_grub",grubDirectory, True) clTemplateCltPath = \ filter(lambda x:path.exists(x), map(lambda x:pathJoin(directory,x), self.clVars.Get('cl_template_clt_path'))) self.clVars.Set('cl_template_clt_path',clTemplateCltPath,True) self.clTempl = ProgressTemplate(self.setProgress,self.clVars, cltFilter=False, printSUCCESS=self.printSUCCESS, printWARNING=self.printWARNING, askConfirm=self.askConfirm, printERROR=self.printERROR) dirsFiles = self.clTempl.applyTemplates() if self.clTempl.getError(): raise InstallError(self.clTempl.getError()) else: return dirsFiles def checkDuplicate(self,datalist,name,key=lambda x:x): """Check on duplicate and print error""" keydata = map(key,datalist) dupKey = set(filter(lambda x:keydata.count(x)>1, keydata)) if dupKey: self.printERROR(_("Duplicated {keyname}: {keylist}").format( keyname=name,keylist=",".join(dupKey))) return False return True def setVarList(self,varsList,matrix): """Set matrix to vars""" if not matrix: map(lambda x:self.clVars.Set(x,[],True),varsList) else: map(lambda x:self.clVars.Set(x[0],list(x[1]),True), zip(varsList,zip(*matrix))) def setDisks(self): """ TODO: remove check grub2_path in disk variables """ try: if not self.clVars.Get('os_grub2_path'): self.checkForLegacyGrub() else: self.checkForGrub2() except InstallError,e: error.append(e) return True