From f115bf8d37f50d674ecfdf4faaca7576ade793e5 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: Mon, 7 Jun 2010 11:21:09 +0400 Subject: [PATCH] In the title of the configuration file, added the use of template files --- pym/cl_template.py | 72 ++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/pym/cl_template.py b/pym/cl_template.py index 4ff042f..c2c1c1f 100644 --- a/pym/cl_template.py +++ b/pym/cl_template.py @@ -329,32 +329,20 @@ class fileHeader(_terms): incorrectParams = set([]) # Удаление Заголовка Calculate if comment: + titleFirst = _("Modified") # В случае текста XML if type(comment) == types.TupleType and len(comment) == 2: - _titleList = (_("Modified"), _("File of a template")) reCalcHeader =\ - re.compile(u"\s*%s\s+%s.+Calculate.+\s+%s.+\s+%s\s?"%(\ - comment[0], - _titleList[0].decode("UTF-8"), - _titleList[1].decode("UTF-8"), - comment[1], - ), - re.M|re.I|re.U) - textUnicode = text.decode("UTF-8") - reS = reCalcHeader.search(textUnicode) + re.compile("\s*%s\s+%s.+\s+(.+\n)+%s\s?"\ + %(comment[0], titleFirst, comment[1]),re.M|re.I) + reS = reCalcHeader.search(text) if reS: - textBody = textUnicode[:reS.start()]+textUnicode[reS.end():] - if textBody: - self.body = textBody.encode("UTF-8") + self.body = text[:reS.start()]+text[reS.end():] else: - reCalcHeader =\ - re.compile("\s*%s\-+\s+%s.+Calculate.+\s+%s.+\s+%s\-+\s?"%(\ - comment, - comment, - comment, - comment, - ), - re.M|re.I) + reCalcHeader = re.compile(\ + "\s*%s\-+\s+%s\s+%s.+\s+(%s.+\s+)+%s\-+\s?"\ + %(comment, comment, titleFirst ,comment,comment), + re.M|re.I) reS = reCalcHeader.search(text) if reS: self.body = text[reS.end():] @@ -3042,7 +3030,7 @@ class template(_file, _terms, xmlShare, templateFormat, _shareTemplate): self.__titleHead = "--------------------------------------\ ----------------------------------------" self._titleBody = "" - self._titleList = (_("Modified"), _("File of a template")) + self._titleList = (_("Modified"), _("Processed template files") + ":") self._reVar = re.compile(("%s[a-zA-Z0-9_-]+%s")%(self.varStart, self.varEnd),re.M) # Условия @@ -3090,6 +3078,9 @@ re.M|re.S) self.uid, self.gid, self.homeDir = self.getDataUser() # Домашняя директория, плюс базовая директория self.homeDir = os.path.join(self._baseDir, self.homeDir[1:]) + # Глобальный словарь обработанных шаблонов файлов + # {путь к конф. файлу:[имена шаблонов] ...} + self.dictProcessedTemplates = {} # Преобразование восьмеричного в целое (ввод строка, вывод число) @@ -3263,14 +3254,19 @@ re.M|re.S) else: self._titleBody = commentFirst + self.__titleHead + "\n" z = 0 - lenCommentList = len(commentList) - 1 - for com in self._titleList: - if lenCommentList < z: - self._titleBody += commentInsert + " " + com + "\n" + flagFirst = True + for com in list(self._titleList) + [""]*(len(commentList)): + if com: + if flagFirst: + self._titleBody += commentInsert + " " + com + " "+\ + self.programVersion + "\n" + flagFirst = False + else: + self._titleBody += commentInsert + " " + com + "\n" else: - self._titleBody += commentInsert + " " + com +\ - " " + commentList[z] + "\n" - z += 1 + self._titleBody += commentInsert + " " +\ + commentList[z] + "\n" + z += 1 if flagList: self._titleBody += commentLast +"\n" else: @@ -3440,16 +3436,13 @@ re.M|re.S) # файл в системе без условий nameFileConfig = "/".join(map(lambda x:x.split("?")[0],\ nameFileConfig.split("/"))) - listTemplTitle = prefix.split("/")[-2:] - templTitle = '"' + "/".join(listTemplTitle) + '"' # Записываем в переменную обрабатываемый файл self.objVar.Set("cl_pass_file",nameFileConfig) # Пишем время модификации *.env файлов if nameFileConfig.endswith(".env"): nameEnvFile = os.path.split(nameFileConfig)[1] self.functObj.timeConfigsIni[nameEnvFile] = float(time.time()) - filesApl = self.join(path, nameFileConfig,(self.programVersion, - templTitle), optFile) + filesApl = self.joinTemplate(path, nameFileConfig, optFile) if self.getError(): return False if filesApl: @@ -3994,6 +3987,9 @@ re.M|re.S) not objHeadNew.params.has_key("symbolic") and\ objHeadNew.params.has_key("link"): return (applyFiles, False) + if not pathOldFile in self.dictProcessedTemplates: + self.dictProcessedTemplates[pathOldFile] = [] + self.dictProcessedTemplates[pathOldFile].append(nameFileTemplate) return (applyFiles, objHeadNew) def createNewClass(self, name, bases, attrs={}): @@ -4032,7 +4028,7 @@ re.M|re.S) return False return True - def join(self, nameFileTemplate, nameFileConfig, ListOptTitle, optFile): + def joinTemplate(self,nameFileTemplate, nameFileConfig ,optFile): """Объединения шаблона и конф. файла join(nameFileTemplate, nameFileConfig, ListOptTitle) @@ -4086,12 +4082,14 @@ re.M|re.S) if not self.fileIsUtf(nameFileConfig): flagNotUtf8Old = True self.textTemplate = objHeadNew.body - + # Список примененных шаблонов + ListOptTitle = [] + if nameFileConfig in self.dictProcessedTemplates: + ListOptTitle = self.dictProcessedTemplates[nameFileConfig] # Титл конфигурационного файла title = "" if ListOptTitle: - title = self.getTitle(objHeadNew.comment, - ListOptTitle) + title = self.getTitle(objHeadNew.comment, ListOptTitle) title = title.encode("UTF-8") objHeadOld = False