Пример #1
0
 def applyTemplates(self):
     """Apply templates"""
     clTempl = template(self.clVars)
     dirsFiles = clTempl.applyTemplates()
     if clTempl.getError():
         self.printERROR(clTempl.getError().strip())
         return False
     else:
         return dirsFiles
Пример #2
0
 def applyTemplatesFromSystem(self):
     """Применяем шаблоны для cистемы"""
     # Cоздаем объект обработки шаблонов
     clTempl = template(self.clVars)
     # Объединяем шаблоны
     dirsFiles = clTempl.applyTemplates()
     if clTempl.getError():
         self.printERROR(clTempl.getError().strip())
         return False
     else:
         return dirsFiles
Пример #3
0
 def createLdif(self, ldifFile):
     """Cоздает ldif из ldif - шаблона"""
     if not os.access(ldifFile, os.F_OK):
         self.setError(_("File not found") + ":\n  " + ldifFile)
         return False
     FD = open (ldifFile)
     ldifTemplate = FD.read()
     FD.close()
     clTempl = template(self.clVars)
     # Применяем условия к шаблону
     ldifTemplate = clTempl.applyTermsTemplate(ldifTemplate, ldifFile)
     # Заменяем переменные в шаблоне
     ldifTemplate = clTempl.applyVarsTemplate(ldifTemplate, ldifFile)
     return ldifTemplate
Пример #4
0
 def applyTemplatesFromUser(self, progress=False):
     """Применяем шаблоны для пользователя"""
     # Cоздаем объект обработки шаблонов
     if progress:
         clTempl = ProgressTemplate(self.clVars)
     else:
         clTempl = template(self.clVars, cltObj=False)
     # Объединяем шаблоны
     dirsFiles = clTempl.applyTemplates()
     if progress:
         clTempl.close()
     if clTempl.getError():
         self.printERROR(clTempl.getError().strip())
         return False
     else:
         if self.verbose:
             self.displayTemplatesApplied(dirsFiles)
         return dirsFiles
    def applyAllTemplates(self, location="all", package=None):
        """Обновление конфигурационных файлов"""
        if not "calculate-install" in self.installProgs:
            self.printERROR(_("Failed to install %s")
                              %"calculate-install")
            self.printWARNING(\
                       _("To install the program, run 'cl-install --install'"))
            return False

        if package and "/" in package:
            package = package.partition('/')[2]
        sectionsWork = map(lambda x: x.rpartition("-")[2], self.installProgs)
        dictPakkages = {}
        oldPymPath = ""
        listIndex = []
        clTempl = False
        for sectName in sectionsWork:
            realPath = "/usr/lib/calculate-2.2/calculate-%s"%sectName
            pymPath = os.path.join(realPath,"pym")
            if not os.path.isdir(pymPath):
                continue
            if len(filter(lambda x:x.startswith("cl_vars_") and\
                x.endswith(".py") or x.startswith("cl_fill_") and\
                x.endswith(".py"), os.listdir(pymPath)))==2:
                if oldPymPath:
                    sys.path = filter(lambda x: x!=oldPymPath, sys.path)
                sys.path.insert(0, os.path.abspath(pymPath))
                oldPymPath = os.path.abspath(pymPath)
                clVars = DataVarsObject(sectName)
                clVars.importDataObject()
                if location in ("local", "remote"):
                    listTemplatePaths = clVars.Get("cl_template_path")
                    if len(listTemplatePaths) != 3:
                        self.printERROR(\
                        _("Error in template variable 'cl_template_path=%s'")\
                        %str(listTemplatePaths))
                        return False
                    elif location == "local":
                        clVars.Set("cl_template_path", [listTemplatePaths[1]],
                                   True)
                    elif location == "remote":
                        clVars.Set("cl_template_path", [listTemplatePaths[2]],
                                   True)
                # merge
                clVars.Set("cl_action", "merge" ,True)
                # будут применены все шаблоны .clt (cltFilter=False)
                # и обычные шаблоны
                clTempl = template(clVars, cltFilter=False,
                                   printWarning=False)
                error = None

                if(package):
                    clVars.Set("cl_belong_pkg",package,True)
                try:
                    if location=="clt":
                        # apply clt templates
                        dirsFiles = clTempl.cltObj.applyTemplates()
                    else:
                        # apply all templates
                        dirsFiles = clTempl.applyTemplates()
                except InstallError,e:
                    error = e
                except (Exception),e:
                    error = ""
                    for i in apply(traceback.format_exception, sys.exc_info()):
                        error += i
                finally: