In the title of the configuration file, added the use of template files

develop
Самоукин Алексей 14 years ago
parent 0b43a41eb8
commit f115bf8d37

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

Loading…
Cancel
Save