|
|
|
@ -301,13 +301,14 @@ class fileHeader(_terms):
|
|
|
|
|
# Тип вставки шаблона
|
|
|
|
|
typeAppend = ""
|
|
|
|
|
# Возможные типы вставки шаблонов
|
|
|
|
|
_fileAppend = "join", "before", "after", "replace", "remove", "skip"
|
|
|
|
|
_fileAppend = "join", "before", "after", "replace", "remove", "skip",\
|
|
|
|
|
"patch"
|
|
|
|
|
# Интерпретатор (#!/bin/bash) (#!/usr/bin/python)
|
|
|
|
|
execStr = ""
|
|
|
|
|
# Символ комментария
|
|
|
|
|
comment = False
|
|
|
|
|
# Выражение для поиска строки интерпретатора
|
|
|
|
|
reExecStr = re.compile("^#!.+\s*",re.I)
|
|
|
|
|
reExecStr = re.compile("^#!.+\s*",re.M)
|
|
|
|
|
# условные операторы
|
|
|
|
|
terms = ('>', '<', '==', '!=', '>=', '<=')
|
|
|
|
|
# параметры без значения
|
|
|
|
@ -323,7 +324,14 @@ class fileHeader(_terms):
|
|
|
|
|
# Параметры описанные в заголовке файла шаблона
|
|
|
|
|
self.params = {}
|
|
|
|
|
# некорректные параметры
|
|
|
|
|
incorrectParams = set([])
|
|
|
|
|
incorrectParams = []
|
|
|
|
|
# Поиск строки запустка (#!/bin/bash и.т. д)
|
|
|
|
|
if comment or fileType!="bin":
|
|
|
|
|
reExecRes = self.reExecStr.search(self.body)
|
|
|
|
|
if reExecRes:
|
|
|
|
|
self.execStr = self.body[reExecRes.start():reExecRes.end()]
|
|
|
|
|
self.body = self.body[:reExecRes.start()] +\
|
|
|
|
|
self.body[reExecRes.end():]
|
|
|
|
|
# Удаление Заголовка Calculate
|
|
|
|
|
if comment:
|
|
|
|
|
titleFirst = _("Modified")
|
|
|
|
@ -332,25 +340,24 @@ class fileHeader(_terms):
|
|
|
|
|
reCalcHeader =\
|
|
|
|
|
re.compile("\s*%s\s+%s.+\s+(.+\n)+%s\s?"\
|
|
|
|
|
%(comment[0], titleFirst, comment[1]),re.M|re.I)
|
|
|
|
|
reS = reCalcHeader.search(text)
|
|
|
|
|
reS = reCalcHeader.search(self.body)
|
|
|
|
|
if reS:
|
|
|
|
|
self.body = text[:reS.start()]+text[reS.end():]
|
|
|
|
|
self.body = self.body[:reS.start()]+self.body[reS.end():]
|
|
|
|
|
else:
|
|
|
|
|
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)
|
|
|
|
|
reS = reCalcHeader.search(self.body)
|
|
|
|
|
if reS:
|
|
|
|
|
self.body = text[reS.end():]
|
|
|
|
|
|
|
|
|
|
self.body = self.body[reS.end():]
|
|
|
|
|
if fileType != False:
|
|
|
|
|
if fileType=="bin":
|
|
|
|
|
self.params["format"] = fileType
|
|
|
|
|
self.fileType = self._getType()
|
|
|
|
|
self.typeAppend = self._getAppend()
|
|
|
|
|
else:
|
|
|
|
|
textLines = text.splitlines()
|
|
|
|
|
textLines = self.body.splitlines()
|
|
|
|
|
if textLines:
|
|
|
|
|
textLine = textLines[0]
|
|
|
|
|
rePar = re.compile("\s*#\s*calculate\s+",re.I)
|
|
|
|
@ -358,17 +365,17 @@ class fileHeader(_terms):
|
|
|
|
|
if reP:
|
|
|
|
|
reL = False
|
|
|
|
|
reLns = re.compile(r"\A([^\\\n]*\\\n)+[^\n]*\n*",re.M)
|
|
|
|
|
reLs = reLns.search(text)
|
|
|
|
|
reLs = reLns.search(self.body)
|
|
|
|
|
if reLs:
|
|
|
|
|
reL = reLs
|
|
|
|
|
paramLine = text[reP.end():reLs.end()]
|
|
|
|
|
paramLine = self.body[reP.end():reLs.end()]
|
|
|
|
|
paramLine = paramLine.replace("\\"," ")
|
|
|
|
|
else:
|
|
|
|
|
reLn = re.compile("\n")
|
|
|
|
|
reL = reLn.search(text)
|
|
|
|
|
reL = reLn.search(self.body)
|
|
|
|
|
paramLine = textLine[reP.end():]
|
|
|
|
|
if reL:
|
|
|
|
|
self.body = text[reL.end():]
|
|
|
|
|
self.body = self.body[reL.end():]
|
|
|
|
|
else:
|
|
|
|
|
self.body = ""
|
|
|
|
|
paramList = re.split("\s+",paramLine)
|
|
|
|
@ -405,12 +412,14 @@ class fileHeader(_terms):
|
|
|
|
|
|
|
|
|
|
self.comment = self._getComment()
|
|
|
|
|
self.fileType = self._getType()
|
|
|
|
|
self.typeAppend = self._getAppend()
|
|
|
|
|
reExecRes = self.reExecStr.search(self.body)
|
|
|
|
|
if reExecRes:
|
|
|
|
|
self.execStr = self.body[reExecRes.start():reExecRes.end()]
|
|
|
|
|
self.body = self.body[reExecRes.end():]
|
|
|
|
|
if not incorrectParams:
|
|
|
|
|
typeAppend = self._getAppend()
|
|
|
|
|
if typeAppend:
|
|
|
|
|
self.typeAppend = typeAppend
|
|
|
|
|
else:
|
|
|
|
|
self.headerTerm = False
|
|
|
|
|
self.setError(_("incorrect header parameters - '%s'")\
|
|
|
|
|
%"append=%s"%self.params["append"])
|
|
|
|
|
if not incorrectParams and self.params:
|
|
|
|
|
incorrectParams = set(self.params.keys()) - set(self.allowParam)
|
|
|
|
|
if incorrectParams:
|
|
|
|
|
self.headerTerm = False
|
|
|
|
@ -419,19 +428,24 @@ class fileHeader(_terms):
|
|
|
|
|
|
|
|
|
|
def _getType(self):
|
|
|
|
|
"""Выдать тип файла"""
|
|
|
|
|
if self.params.has_key("format"):
|
|
|
|
|
if "format" in self.params:
|
|
|
|
|
return self.params["format"]
|
|
|
|
|
else:
|
|
|
|
|
return "raw"
|
|
|
|
|
|
|
|
|
|
def _getAppend(self):
|
|
|
|
|
"""Выдать тип добавления файла"""
|
|
|
|
|
if self.params.has_key("append") and self.params["append"] in\
|
|
|
|
|
self._fileAppend:
|
|
|
|
|
return self.params["append"]
|
|
|
|
|
if self.params.has_key("append"):
|
|
|
|
|
if self.params["append"] in self._fileAppend:
|
|
|
|
|
return self.params["append"]
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
if self.fileType != "raw" and self.fileType != "bin" and\
|
|
|
|
|
self.fileType != "":
|
|
|
|
|
if "format" in self.params and self.params["format"] == "patch":
|
|
|
|
|
self.params["append"] = "patch"
|
|
|
|
|
return "patch"
|
|
|
|
|
self.params["append"] = "join"
|
|
|
|
|
return "join"
|
|
|
|
|
self.params["append"] = "replace"
|
|
|
|
@ -532,7 +546,13 @@ class dirHeader(_terms):
|
|
|
|
|
incorrectParams = set([i])
|
|
|
|
|
elif len(par) == 2:
|
|
|
|
|
self.params[par[0]] = par[1]
|
|
|
|
|
self.typeAppend = self._getAppend()
|
|
|
|
|
typeAppend = self._getAppend()
|
|
|
|
|
if typeAppend:
|
|
|
|
|
self.typeAppend = typeAppend
|
|
|
|
|
else:
|
|
|
|
|
self.headerTerm = False
|
|
|
|
|
self.setError(_("incorrect header parameters - '%s'")\
|
|
|
|
|
%"append=%s"%self.params["append"])
|
|
|
|
|
if not flagErrorBody:
|
|
|
|
|
if not incorrectParams:
|
|
|
|
|
incorrectParams = set(self.params.keys()) - set(self.allowParam)
|
|
|
|
@ -543,9 +563,11 @@ class dirHeader(_terms):
|
|
|
|
|
|
|
|
|
|
def _getAppend(self):
|
|
|
|
|
"""Выдать тип добавления директории"""
|
|
|
|
|
if self.params.has_key("append") and self.params["append"] in\
|
|
|
|
|
self._fileAppend:
|
|
|
|
|
return self.params["append"]
|
|
|
|
|
if self.params.has_key("append"):
|
|
|
|
|
if self.params["append"] in self._fileAppend:
|
|
|
|
|
return self.params["append"]
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
return "join"
|
|
|
|
|
|
|
|
|
@ -3283,14 +3305,18 @@ re.M|re.S)
|
|
|
|
|
|
|
|
|
|
def getTemplateType(self):
|
|
|
|
|
"""выдать тип шаблона (text, bin)"""
|
|
|
|
|
isBin = self.typeFileObj.isBinary(self.nameFileTemplate)
|
|
|
|
|
return self.getFileType(self.nameFileTemplate)
|
|
|
|
|
|
|
|
|
|
def getFileType(self, fileName):
|
|
|
|
|
"""выдать тип файла (text, bin)"""
|
|
|
|
|
isBin = self.typeFileObj.isBinary(fileName)
|
|
|
|
|
typeTemplate = "bin"
|
|
|
|
|
if isBin is True:
|
|
|
|
|
typeTemplate = "bin"
|
|
|
|
|
elif isBin is False:
|
|
|
|
|
typeTemplate = "text"
|
|
|
|
|
else:
|
|
|
|
|
self.setError(_("ERROR") + ": getTemplateType()")
|
|
|
|
|
self.setError(_("ERROR") + ": getFileType()")
|
|
|
|
|
self.setError(isBin)
|
|
|
|
|
return False
|
|
|
|
|
return typeTemplate
|
|
|
|
@ -3567,10 +3593,9 @@ re.M|re.S)
|
|
|
|
|
self.cltObj.dictProcessedTemplates = self.dictProcessedTemplates
|
|
|
|
|
if self.cltFilter:
|
|
|
|
|
# Шаблоны + .clt которые будут применены
|
|
|
|
|
self.cltObj.filterApplyTemplates=\
|
|
|
|
|
self.cltObj.filterApplyTemplates +=\
|
|
|
|
|
map(lambda x: pathJoin('/', x.partition(self._baseDir)[2]),
|
|
|
|
|
self.dictProcessedTemplates.keys())
|
|
|
|
|
# Обрабатываем шаблоны clt
|
|
|
|
|
if not self.cltObj.applyTemplates():
|
|
|
|
|
return False
|
|
|
|
|
return (self.createdDirs, self.filesApply)
|
|
|
|
@ -4213,7 +4238,7 @@ re.M|re.S)
|
|
|
|
|
return ([], False)
|
|
|
|
|
if not objHeadNew.body.strip():
|
|
|
|
|
preReturn(pathProg)
|
|
|
|
|
return ([], False)
|
|
|
|
|
return (applyFiles, False)
|
|
|
|
|
else:
|
|
|
|
|
applyFiles = [pathOldFile]
|
|
|
|
|
if pathProg:
|
|
|
|
@ -4333,9 +4358,48 @@ re.M|re.S)
|
|
|
|
|
if objHeadNew.comment:
|
|
|
|
|
objHeadOld = fileHeader(nameFileConfig, self.textConfig,
|
|
|
|
|
objHeadNew.comment)
|
|
|
|
|
elif objHeadNew.fileType and\
|
|
|
|
|
objHeadNew.typeAppend in ("before", "after"):
|
|
|
|
|
configFileType = self.getFileType(nameFileConfig)
|
|
|
|
|
objHeadOld = fileHeader(nameFileConfig, self.textConfig,
|
|
|
|
|
fileType=configFileType)
|
|
|
|
|
# Строка вызова скрипта (#!/bin/bash ...)
|
|
|
|
|
execStr = ""
|
|
|
|
|
if objHeadNew.execStr:
|
|
|
|
|
execStr = objHeadNew.execStr
|
|
|
|
|
elif objHeadOld and objHeadOld.execStr:
|
|
|
|
|
execStr = objHeadOld.execStr
|
|
|
|
|
|
|
|
|
|
if objHeadNew.fileType:
|
|
|
|
|
formatTemplate = objHeadNew.fileType
|
|
|
|
|
typeAppendTemplate = objHeadNew.typeAppend
|
|
|
|
|
if formatTemplate == "patch":
|
|
|
|
|
if typeAppendTemplate != "patch":
|
|
|
|
|
self.setError(\
|
|
|
|
|
_("False option append=%(type)s in template %(file)s")\
|
|
|
|
|
%{"type":typeAppendTemplate,"file":nameFileTemplate})
|
|
|
|
|
return False
|
|
|
|
|
# создаем объект формата шаблона
|
|
|
|
|
objTempl = self.getFormatObj(formatTemplate, self.textTemplate)
|
|
|
|
|
if not objTempl:
|
|
|
|
|
self.setError(\
|
|
|
|
|
_("Incorrect header parmeter format=%s in template")\
|
|
|
|
|
%formatTemplate + " " + nameFileTemplate)
|
|
|
|
|
return False
|
|
|
|
|
if objHeadOld and objHeadOld.body:
|
|
|
|
|
self.textConfig = objHeadOld.body
|
|
|
|
|
# обработка конфигурационного файла
|
|
|
|
|
self.textTemplate = objTempl.processingFile(self.textConfig)
|
|
|
|
|
if objTempl.getError():
|
|
|
|
|
self.setError(_("False template") + ": " +\
|
|
|
|
|
nameFileTemplate)
|
|
|
|
|
return False
|
|
|
|
|
if execStr:
|
|
|
|
|
self.textConfig = execStr + title + self.textTemplate
|
|
|
|
|
else:
|
|
|
|
|
self.textConfig = title + self.textTemplate
|
|
|
|
|
self.saveConfFile()
|
|
|
|
|
return filesApply
|
|
|
|
|
# Создаем объект в случае параметра format в заголовке
|
|
|
|
|
if (typeAppendTemplate == "replace" or\
|
|
|
|
|
typeAppendTemplate == "before" or\
|
|
|
|
@ -4397,7 +4461,7 @@ re.M|re.S)
|
|
|
|
|
self.textConfig = title + self.textTemplate
|
|
|
|
|
self.saveConfFile()
|
|
|
|
|
return filesApply
|
|
|
|
|
# Впереди
|
|
|
|
|
# Вверху
|
|
|
|
|
elif typeAppendTemplate == "before":
|
|
|
|
|
if "xml_" in formatTemplate:
|
|
|
|
|
self.setError(\
|
|
|
|
@ -4410,16 +4474,14 @@ re.M|re.S)
|
|
|
|
|
tmpTemplate = self.textTemplate + self.textConfig
|
|
|
|
|
else:
|
|
|
|
|
tmpTemplate = self.textTemplate + "\n" + self.textConfig
|
|
|
|
|
if objHeadNew.execStr:
|
|
|
|
|
self.textConfig = objHeadNew.execStr + title + tmpTemplate
|
|
|
|
|
elif objHeadOld and objHeadOld.execStr:
|
|
|
|
|
self.textConfig = objHeadOld.execStr + title + tmpTemplate
|
|
|
|
|
if execStr:
|
|
|
|
|
self.textConfig = execStr + title + tmpTemplate
|
|
|
|
|
else:
|
|
|
|
|
self.textConfig = title + tmpTemplate
|
|
|
|
|
|
|
|
|
|
self.saveConfFile()
|
|
|
|
|
return filesApply
|
|
|
|
|
# Cзади
|
|
|
|
|
# Внизу
|
|
|
|
|
elif typeAppendTemplate == "after":
|
|
|
|
|
if "xml_" in formatTemplate:
|
|
|
|
|
self.setError(\
|
|
|
|
@ -4432,10 +4494,8 @@ re.M|re.S)
|
|
|
|
|
tmpTemplate = self.textConfig + self.textTemplate
|
|
|
|
|
else:
|
|
|
|
|
tmpTemplate = self.textConfig + "\n" + self.textTemplate
|
|
|
|
|
if objHeadNew.execStr:
|
|
|
|
|
self.textConfig = objHeadNew.execStr + title + tmpTemplate
|
|
|
|
|
elif objHeadOld and objHeadOld.execStr:
|
|
|
|
|
self.textConfig = objHeadOld.execStr + title + tmpTemplate
|
|
|
|
|
if execStr:
|
|
|
|
|
self.textConfig = execStr + title + tmpTemplate
|
|
|
|
|
else:
|
|
|
|
|
self.textConfig = title + tmpTemplate
|
|
|
|
|
self.saveConfFile()
|
|
|
|
@ -4476,14 +4536,6 @@ re.M|re.S)
|
|
|
|
|
if not self.textConfig or\
|
|
|
|
|
not reNoClean.search(self.textConfig):
|
|
|
|
|
self.textConfig = ""
|
|
|
|
|
#if objHeadNew.execStr:
|
|
|
|
|
#self.textConfig = objHeadNew.execStr + \
|
|
|
|
|
#title + objTemplNew.getConfig().encode("UTF-8")
|
|
|
|
|
#else:
|
|
|
|
|
#self.textConfig = title +\
|
|
|
|
|
#objTemplNew.getConfig().encode("UTF-8")
|
|
|
|
|
#self.saveConfFile()
|
|
|
|
|
#return True
|
|
|
|
|
|
|
|
|
|
objHeadOld = fileHeader(nameFileConfig, self.textConfig,
|
|
|
|
|
objTemplNew._comment)
|
|
|
|
@ -4518,12 +4570,9 @@ re.M|re.S)
|
|
|
|
|
data.insert(1,title)
|
|
|
|
|
self.textConfig = "\n".join(data)
|
|
|
|
|
else:
|
|
|
|
|
if objHeadNew.execStr:
|
|
|
|
|
self.textConfig = objHeadNew.execStr + title +\
|
|
|
|
|
objTemplOld.getConfig().encode("UTF-8")
|
|
|
|
|
elif objHeadOld.execStr:
|
|
|
|
|
self.textConfig = objHeadOld.execStr + title +\
|
|
|
|
|
objTemplOld.getConfig().encode("UTF-8")
|
|
|
|
|
if execStr:
|
|
|
|
|
self.textConfig = execStr + title +\
|
|
|
|
|
objTemplOld.getConfig().encode("UTF-8")
|
|
|
|
|
else:
|
|
|
|
|
self.textConfig = title +\
|
|
|
|
|
objTemplOld.getConfig().encode("UTF-8")
|
|
|
|
@ -4588,6 +4637,9 @@ class templateClt(scanDirectoryClt, template):
|
|
|
|
|
self.flagApplyTemplates = False
|
|
|
|
|
if self.objVar.Get("cl_name") in applyPackages:
|
|
|
|
|
self.flagApplyTemplates = True
|
|
|
|
|
# Базовая директория переноса шаблонов "/mnt/calculate" или "/" и.т.д
|
|
|
|
|
self._baseDir = pathJoin(self.objVar.Get("cl_chroot_path"),
|
|
|
|
|
self.objVar.Get("cl_root_path"))
|
|
|
|
|
|
|
|
|
|
def applyTemplate(self, path):
|
|
|
|
|
"""Применение отдельного .clt шаблона"""
|
|
|
|
@ -4616,6 +4668,7 @@ class templateClt(scanDirectoryClt, template):
|
|
|
|
|
else:
|
|
|
|
|
nameFileConfig = path
|
|
|
|
|
nameFileConfig = nameFileConfig[:-self.lenExtFileTemplate]
|
|
|
|
|
nameFileConfig = pathJoin(self._baseDir, nameFileConfig)
|
|
|
|
|
# файл в системе без условий
|
|
|
|
|
nameFileConfig = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
nameFileConfig.split("/")))
|
|
|
|
@ -4631,8 +4684,10 @@ class templateClt(scanDirectoryClt, template):
|
|
|
|
|
if filesApl:
|
|
|
|
|
self.filesApply += filesApl
|
|
|
|
|
# Настоящее имя конфигурационного файла
|
|
|
|
|
nameFileConfig = filesApl[0]
|
|
|
|
|
return nameFileConfig
|
|
|
|
|
nameFileConfig = filesApl[0]
|
|
|
|
|
return nameFileConfig
|
|
|
|
|
else:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def countsNumberTemplates(self, dirsTemplates=[]):
|
|
|
|
|
"""Считаем количество шаблонов"""
|
|
|
|
|