From 9e87227802822396bb5b858947fde0cd2a030647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=83=D0=BA=D0=B8=D0=BD=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Fri, 17 Dec 2010 11:17:54 +0300 Subject: [PATCH] After compiling any package will not apply templates with unknown variables. --- pym/cl_template.py | 8 +-- pym/update_config/cl_update_config.py | 91 ++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/pym/cl_template.py b/pym/cl_template.py index ed5119f..4f9181b 100644 --- a/pym/cl_template.py +++ b/pym/cl_template.py @@ -4028,7 +4028,7 @@ variable 'cl-name'")) newDir = "/".join(map(lambda x:x.split("?")[0], newDir.split("/"))) # Применяем шаблон pathDir, objHeadDir, createdDirs =\ - self.__getApplyHeadDir(newDir, dirInfoFile, opt) + self.getApplyHeadDir(newDir, dirInfoFile, opt) if createdDirs: self.createdDirs += createdDirs if objHeadDir: @@ -4041,7 +4041,7 @@ variable 'cl-name'")) self.numberProcessTempl += self.dictTemplates[path] return None - def __getApplyHeadDir(self, newDir, templateDirFile, optDir): + def getApplyHeadDir(self, newDir, templateDirFile, optDir): """Применяет шаблон к директории (права, владелец, и.т. д)""" def function(text): @@ -4261,7 +4261,7 @@ variable 'cl-name'")) applyDir = "" return (applyDir, objHead, createdDirs) - def __getApplyHeadTemplate(self, nameFileTemplate, nameFileConfig, + def getApplyHeadTemplate(self, nameFileTemplate, nameFileConfig, templateFileType, optFile): """Применяет заголовок к шаблону (права, владелец, и.т. д)""" def function(text): @@ -4696,7 +4696,7 @@ variable 'cl-name'")) flagCopyTemplate = False if not optFile: optFile = {"path":os.path.split(nameFileConfig)[0]} - filesApply, objHeadNew = self.__getApplyHeadTemplate(nameFileTemplate, + filesApply, objHeadNew = self.getApplyHeadTemplate(nameFileTemplate, nameFileConfig, templateFileType, optFile) diff --git a/pym/update_config/cl_update_config.py b/pym/update_config/cl_update_config.py index 5df98c2..4122b9c 100644 --- a/pym/update_config/cl_update_config.py +++ b/pym/update_config/cl_update_config.py @@ -44,6 +44,79 @@ class writeLog: formatter="%(asctime)s - %(levelname)s - %(message)s") +class DataVars(cl_datavars.DataVars): + + flagNotFoundVar = False + + def Get(self, *args, **kwargs): + try: + valVars = cl_datavars.DataVars.Get(self, *args, **kwargs) + except self.DataVarsError, e: + valVars = "" + self.flagNotFoundVar = True + return valVars + + def Set(self, *args, **kwargs): + try: + valVars = cl_datavars.DataVars.Set(self, *args, **kwargs) + except self.DataVarsError, e: + valVars = "" + self.flagNotFoundVar = True + return valVars + +class template(cl_template.template): + + def getApplyHeadTemplate(self, *args, **kwargs): + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ([], False) + filesApply, objHeadNew =\ + cl_template.template.getApplyHeadTemplate(self, *args, **kwargs) + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ([], False) + else: + return filesApply, objHeadNew + + def getApplyHeadDir(self, *args, **kwargs): + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ("", False, []) + pathDir, objHeadDir, createdDirs =\ + cl_template.template.getApplyHeadDir(self, *args, **kwargs) + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ("", False, []) + else: + return pathDir, objHeadDir, createdDirs + + +class templateClt(cl_template.templateClt): + + def getApplyHeadTemplate(self, *args, **kwargs): + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ([], False) + filesApply, objHeadNew =\ + cl_template.templateClt.getApplyHeadTemplate(self, *args, **kwargs) + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ([], False) + else: + return filesApply, objHeadNew + + def getApplyHeadDir(self, *args, **kwargs): + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ("", False, []) + pathDir, objHeadDir, createdDirs =\ + cl_template.templateClt.getApplyHeadDir(self, *args, **kwargs) + if self.objVar.flagNotFoundVar: + self.objVar.flagNotFoundVar = False + return ("", False, []) + else: + return pathDir, objHeadDir, createdDirs + class color_print(old_color_print, writeLog): """Класс для переопределения печати сообщений""" _printObj = old_color_print() @@ -78,12 +151,12 @@ class color_print(old_color_print, writeLog): self.logger.error(arg[0]) self._printObj.printNotOK(*arg, **argv) -class DataVarsObject(cl_datavars.DataVars): +class DataVarsObject(DataVars): """Класс переменных для десктопа""" packagePath = "/usr/lib/calculate-2.2" def __init__(self, nameProgram): - cl_datavars.DataVars.__init__(self) + DataVars.__init__(self) self.nameProgram = nameProgram def findPathVars(self): @@ -114,7 +187,7 @@ class shareUpdateConfigs(color_print, writeLog): """Получаем флаг обновления и установленные программы работающие с шаблонами""" - clVars = cl_datavars.DataVars() + clVars = DataVars() clVars.flIniFile() flagUpdate = clVars.Get("cl_autoupdate_set") in self._tupleOn return flagUpdate, clVars.GetList("cl_merges") @@ -178,7 +251,7 @@ class updateUserConfigs(shareUpdateConfigs): clVars.Set("ur_login", userName, True) clVars.Set("cl_action", "desktop", True) clVars.Set("cl_belong_pkg", nameProgram, True) - clTempl = cl_template.template(clVars, printWarning=False) + clTempl = template(clVars, printWarning=False) dirsFiles = clTempl.applyTemplates() if dirsFiles is False: self.printERROR(\ @@ -322,13 +395,13 @@ class updateSystemConfigs(shareUpdateConfigs): if nameProg == "calculate-install": configFiles = self.scanProtectDirs(configPath) if configFiles: - cltObject = cl_template.templateClt(clVars) + cltObject = templateClt(clVars) cltObject.filterApplyTemplates = configFiles - clTempl = cl_template.template(clVars, cltObj=cltObject, - printWarning=False) + clTempl = template(clVars, cltObj=cltObject, + printWarning=False) else: - clTempl = cl_template.template(clVars, cltObj=False, - printWarning=False) + clTempl = template(clVars, cltObj=False, + printWarning=False) dirsFiles = clTempl.applyTemplates() nameAndVerPkg = nameProg + "-"+clVars.Get("cl_ver") if dirsFiles is False: