|
|
|
@ -3226,11 +3226,8 @@ class template(_file, _terms, xmlShare, templateFormat, _shareTemplate):
|
|
|
|
|
# Название файла шаблона директории
|
|
|
|
|
templDirNameFile = ".calculate_directory"
|
|
|
|
|
|
|
|
|
|
# Расширение файла шаблона
|
|
|
|
|
extFileTemplate = ".clt"
|
|
|
|
|
lenExtFileTemplate = len(extFileTemplate)
|
|
|
|
|
|
|
|
|
|
def __init__(self, objVar, servDir=False, dirsFilter=[], filesFilter=[]):
|
|
|
|
|
def __init__(self, objVar, servDir=False, dirsFilter=[], filesFilter=[],
|
|
|
|
|
cltObj=True):
|
|
|
|
|
# Необрабатываемые директории
|
|
|
|
|
self.dirsFilter = dirsFilter
|
|
|
|
|
# Необрабатываемые файлы
|
|
|
|
@ -3294,6 +3291,15 @@ re.M|re.S)
|
|
|
|
|
# Глобальный словарь обработанных шаблонов файлов
|
|
|
|
|
# {путь к конф. файлу:[имена шаблонов] ...}
|
|
|
|
|
self.dictProcessedTemplates = {}
|
|
|
|
|
if cltObj is True:
|
|
|
|
|
# Объект templateClt
|
|
|
|
|
self.cltObj = templateClt(self.objVar)
|
|
|
|
|
elif cltObj:
|
|
|
|
|
# Объект templateClt
|
|
|
|
|
self.cltObj = cltObj
|
|
|
|
|
else:
|
|
|
|
|
# Объект templateClt
|
|
|
|
|
self.cltObj = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Преобразование восьмеричного в целое (ввод строка, вывод число)
|
|
|
|
@ -3532,7 +3538,6 @@ re.M|re.S)
|
|
|
|
|
self.dictTemplates = {}
|
|
|
|
|
# Количество шаблонов
|
|
|
|
|
self.allTemplates = 0
|
|
|
|
|
|
|
|
|
|
# Установка по умолчанию аттрибутов для функциии шаблонов ini()
|
|
|
|
|
# Время доступа к конфигурационному файлу функции шаблона ini()
|
|
|
|
|
self.functObj.timeIni = -1
|
|
|
|
@ -3562,11 +3567,45 @@ re.M|re.S)
|
|
|
|
|
return (self.createdDirs, self.filesApply)
|
|
|
|
|
for dirTemplate in dirsTemplatesExists:
|
|
|
|
|
scanObj.scanningDirectory(dirTemplate)
|
|
|
|
|
# Считаем количество шаблонов clt
|
|
|
|
|
if self.cltObj:
|
|
|
|
|
# Считаем количество шаблонов clt
|
|
|
|
|
self.cltObj.countsNumberTemplates()
|
|
|
|
|
# не считать количество файлов в объекте self.cltObj
|
|
|
|
|
self.cltObj.checkNumberTemplate = False
|
|
|
|
|
# начальны номер clt шаблона
|
|
|
|
|
self.cltObj.numberProcessTempl = self.allTemplates
|
|
|
|
|
# метод показывающий номер clt шаблона
|
|
|
|
|
self.cltObj.numberProcessTemplates = self.numberProcessTemplates
|
|
|
|
|
# общее количество шаблонов
|
|
|
|
|
self.allTemplates += self.cltObj.allTemplates
|
|
|
|
|
self.cltObj.allTemplates = self.allTemplates
|
|
|
|
|
self.numberAllTemplates(self.allTemplates)
|
|
|
|
|
# Обрабатываем шаблоны
|
|
|
|
|
for dirTemplate in dirsTemplatesExists:
|
|
|
|
|
if self.scanningTemplates(dirTemplate) is False:
|
|
|
|
|
return False
|
|
|
|
|
if self.cltObj:
|
|
|
|
|
# Созданные директории
|
|
|
|
|
self.cltObj.createdDirs = self.createdDirs
|
|
|
|
|
# Примененные файлы
|
|
|
|
|
self.cltObj.filesApply = self.filesApply
|
|
|
|
|
# Словарь директорий с количеством файлов шаблонов
|
|
|
|
|
self.cltObj.dictTemplates = self.dictTemplates
|
|
|
|
|
# Количество шаблонов
|
|
|
|
|
self.cltObj.allTemplates = self.allTemplates
|
|
|
|
|
# Установка по умолчанию аттрибутов для функциии шаблонов ini()
|
|
|
|
|
# Время доступа к конфигурационному файлу функции шаблона ini()
|
|
|
|
|
self.cltObj.functObj = self.functObj
|
|
|
|
|
# Словарь примененных файлов шаблонов
|
|
|
|
|
self.cltObj.dictProcessedTemplates = self.dictProcessedTemplates
|
|
|
|
|
# Шаблоны + .clt которые будут применены
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -3648,8 +3687,7 @@ re.M|re.S)
|
|
|
|
|
return False
|
|
|
|
|
if filesApl:
|
|
|
|
|
self.filesApply += filesApl
|
|
|
|
|
pathTemplate, nameTemplate = os.path.split(nameFileConfig)
|
|
|
|
|
return {"path":pathTemplate, "name":nameTemplate}
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def processingDirectory(self, path, prefix, opt):
|
|
|
|
|
"""Обработка в случае директории если возвращаем None то пропуск дир."""
|
|
|
|
@ -3872,17 +3910,10 @@ re.M|re.S)
|
|
|
|
|
def __getApplyHeadTemplate(self, nameFileTemplate, nameFileConfig,
|
|
|
|
|
templateFileType, optFile):
|
|
|
|
|
"""Применяет заголовок к шаблону (права, владелец, и.т. д)"""
|
|
|
|
|
|
|
|
|
|
def function(text):
|
|
|
|
|
"""Функция обработки функций в заголовке"""
|
|
|
|
|
return self.applyFuncTemplate(text,nameFileTemplate)
|
|
|
|
|
|
|
|
|
|
def renameConfFileCLT(nameFileConfig):
|
|
|
|
|
"""Изменение название файла templ.conf.clt на templ.conf"""
|
|
|
|
|
if nameFileConfig.endswith(self.extFileTemplate):
|
|
|
|
|
return nameFileConfig[:-self.lenExtFileTemplate]
|
|
|
|
|
return nameFileConfig
|
|
|
|
|
|
|
|
|
|
def chownConfFile(nameFileConfig, uid, gid, nameFileTemplate,
|
|
|
|
|
checkExists=True):
|
|
|
|
|
"""Изменение владельца конфигурационного файла"""
|
|
|
|
@ -3976,7 +4007,6 @@ re.M|re.S)
|
|
|
|
|
pathOldFile = os.path.join(path,nameFile)
|
|
|
|
|
else:
|
|
|
|
|
pathOldFile = os.path.join(path,os.path.split(nameFileConfig)[1])
|
|
|
|
|
pathOldFile = renameConfFileCLT(pathOldFile)
|
|
|
|
|
applyFiles = [pathOldFile]
|
|
|
|
|
# Фильтрация шаблонов по названию файла
|
|
|
|
|
realPath = os.path.join("/",pathOldFile.partition(self._baseDir)[2])
|
|
|
|
@ -4251,7 +4281,7 @@ re.M|re.S)
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def joinTemplate(self,nameFileTemplate, nameFileConfig ,optFile):
|
|
|
|
|
def joinTemplate(self, nameFileTemplate, nameFileConfig, optFile={}):
|
|
|
|
|
"""Объединения шаблона и конф. файла
|
|
|
|
|
|
|
|
|
|
join(nameFileTemplate, nameFileConfig, ListOptTitle)
|
|
|
|
@ -4279,6 +4309,8 @@ re.M|re.S)
|
|
|
|
|
self.textTemplate = self.applyFuncTemplate(self.textTemplate,
|
|
|
|
|
nameFileTemplate)
|
|
|
|
|
flagCopyTemplate = False
|
|
|
|
|
if not optFile:
|
|
|
|
|
optFile = {"path":os.path.split(nameFileConfig)[0]}
|
|
|
|
|
filesApply, objHeadNew = self.__getApplyHeadTemplate(nameFileTemplate,
|
|
|
|
|
nameFileConfig,
|
|
|
|
|
templateFileType,
|
|
|
|
@ -4520,6 +4552,153 @@ re.M|re.S)
|
|
|
|
|
return False
|
|
|
|
|
return filesApply
|
|
|
|
|
|
|
|
|
|
class scanDirectoryClt:
|
|
|
|
|
"""Класс для cканирования директорий с файлами .clt"""
|
|
|
|
|
|
|
|
|
|
# Расширение файла шаблона
|
|
|
|
|
extFileTemplate = ".clt"
|
|
|
|
|
lenExtFileTemplate = len(extFileTemplate)
|
|
|
|
|
filterApplyTemplates = []
|
|
|
|
|
|
|
|
|
|
def processingFile(self, path, prefix):
|
|
|
|
|
"""Обработка в случае файла"""
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def scanningTemplates(self, scanDir, prefix=None, flagDir=False):
|
|
|
|
|
"""Сканирование и обработка шаблонов в директории scanDir"""
|
|
|
|
|
ret = True
|
|
|
|
|
if not prefix:
|
|
|
|
|
prefix = os.path.realpath(scanDir)
|
|
|
|
|
if flagDir or stat.S_ISDIR(os.lstat(scanDir)[stat.ST_MODE]):
|
|
|
|
|
for fileOrDir in sorted(os.listdir(scanDir)):
|
|
|
|
|
absPath = os.path.join(scanDir,fileOrDir)
|
|
|
|
|
stInfo = os.lstat(absPath)
|
|
|
|
|
statInfo = stInfo[stat.ST_MODE]
|
|
|
|
|
if fileOrDir.endswith(self.extFileTemplate) and\
|
|
|
|
|
stat.S_ISREG(statInfo):
|
|
|
|
|
if not self.filterApplyTemplates or\
|
|
|
|
|
absPath[:-self.lenExtFileTemplate] in\
|
|
|
|
|
self.filterApplyTemplates:
|
|
|
|
|
if not self.processingFile(absPath, prefix):
|
|
|
|
|
ret = False
|
|
|
|
|
break
|
|
|
|
|
elif stat.S_ISDIR(statInfo):
|
|
|
|
|
ret = self.scanningTemplates(absPath, prefix, True)
|
|
|
|
|
if ret is False:
|
|
|
|
|
break
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
class templateClt(scanDirectoryClt, template):
|
|
|
|
|
"""Класс для обработки шаблонов c расширением .clt"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, objVar):
|
|
|
|
|
self.checkNumberTemplate = True
|
|
|
|
|
template.__init__(self, objVar, cltObj=False)
|
|
|
|
|
|
|
|
|
|
def processingFile(self, path, prefix):
|
|
|
|
|
"""Обработка в случае шаблона файла"""
|
|
|
|
|
self.numberProcessTempl += 1
|
|
|
|
|
self.numberProcessTemplates(self.numberProcessTempl)
|
|
|
|
|
# Пропуск шаблонов директорий
|
|
|
|
|
if self.templDirNameFile == os.path.split(path)[1]:
|
|
|
|
|
return True
|
|
|
|
|
# Проверка на переменные в названии файла
|
|
|
|
|
if not self.getNeedTemplate(path):
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
if prefix and prefix[-1] == "/":
|
|
|
|
|
prefix = prefix[:-1]
|
|
|
|
|
if prefix:
|
|
|
|
|
nameFileConfig = path.partition(prefix)[2]
|
|
|
|
|
else:
|
|
|
|
|
nameFileConfig = path
|
|
|
|
|
nameFileConfig = nameFileConfig[:-self.lenExtFileTemplate]
|
|
|
|
|
# файл в системе без условий
|
|
|
|
|
nameFileConfig = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
nameFileConfig.split("/")))
|
|
|
|
|
# Записываем в переменную обрабатываемый файл
|
|
|
|
|
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.joinTemplate(path, nameFileConfig)
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
if filesApl:
|
|
|
|
|
self.filesApply += filesApl
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def countsNumberTemplates(self, dirsTemplates=[]):
|
|
|
|
|
"""Считаем количество шаблонов"""
|
|
|
|
|
def createDictTemplates(path, prefix, dictTemplates):
|
|
|
|
|
"""Создает словарь {"директория":"кол-во шаблонов" ...}
|
|
|
|
|
|
|
|
|
|
и считает общее количество шаблонов
|
|
|
|
|
"""
|
|
|
|
|
# Количество шаблонов
|
|
|
|
|
self.allTemplates += 1
|
|
|
|
|
dirTemplate = os.path.split(path)[0]
|
|
|
|
|
while(True):
|
|
|
|
|
if dirTemplate in dictTemplates.keys():
|
|
|
|
|
dictTemplates[dirTemplate] += 1
|
|
|
|
|
else:
|
|
|
|
|
dictTemplates[dirTemplate] = 1
|
|
|
|
|
if dirTemplate == prefix:
|
|
|
|
|
break
|
|
|
|
|
dirTemplate = os.path.split(dirTemplate)[0]
|
|
|
|
|
return dictTemplates
|
|
|
|
|
|
|
|
|
|
if not dirsTemplates:
|
|
|
|
|
dirsTemplates = self.objVar.Get("cl_template_clt_path")
|
|
|
|
|
dirsTemplates.sort()
|
|
|
|
|
scanObj = scanDirectoryClt()
|
|
|
|
|
scanObj.processingFile = lambda x,y: createDictTemplates(x, y,\
|
|
|
|
|
self.dictTemplates)
|
|
|
|
|
# Считаем количество шаблонов
|
|
|
|
|
for dirTemplate in dirsTemplates:
|
|
|
|
|
scanObj.scanningTemplates(dirTemplate, "/")
|
|
|
|
|
|
|
|
|
|
def applyTemplates(self):
|
|
|
|
|
"""Применяет шаблоны к конфигурационным файлам"""
|
|
|
|
|
|
|
|
|
|
if not self.objVar.defined("cl_template_clt_path"):
|
|
|
|
|
self.setError(_("not defined Var: ") + "cl_template_clt_path")
|
|
|
|
|
return False
|
|
|
|
|
dirsTemplates = self.objVar.Get("cl_template_clt_path")
|
|
|
|
|
dirsTemplates.sort()
|
|
|
|
|
if self.checkNumberTemplate:
|
|
|
|
|
# Созданные директории
|
|
|
|
|
self.createdDirs = []
|
|
|
|
|
# Примененные файлы
|
|
|
|
|
self.filesApply = []
|
|
|
|
|
# Номер применяемого шаблона
|
|
|
|
|
self.numberProcessTempl = 0
|
|
|
|
|
# Словарь директорий с количеством файлов шаблонов
|
|
|
|
|
self.dictTemplates = {}
|
|
|
|
|
# Количество шаблонов
|
|
|
|
|
self.allTemplates = 0
|
|
|
|
|
# Установка по умолчанию аттрибутов для функциии шаблонов ini()
|
|
|
|
|
# Время доступа к конфигурационному файлу функции шаблона ini()
|
|
|
|
|
self.functObj.timeIni = -1
|
|
|
|
|
# Первоначальный словарь переменных для ini()
|
|
|
|
|
self.functObj.prevDictIni = {}
|
|
|
|
|
# Текущий словарь переменных для ini()
|
|
|
|
|
self.functObj.currDictIni = {}
|
|
|
|
|
# Словарь времен модификации env файлов для ini()
|
|
|
|
|
self.functObj.timeConfigsIni = {}
|
|
|
|
|
# Считаем количество шаблонов
|
|
|
|
|
self.countsNumberTemplates(dirsTemplates=dirsTemplates)
|
|
|
|
|
self.numberAllTemplates(self.allTemplates)
|
|
|
|
|
# Обрабатываем шаблоны
|
|
|
|
|
for dirTemplate in dirsTemplates:
|
|
|
|
|
if self.scanningTemplates(dirTemplate, "/") is False:
|
|
|
|
|
return False
|
|
|
|
|
return (self.createdDirs, self.filesApply)
|
|
|
|
|
|
|
|
|
|
class iniParser(_error, templateFormat):
|
|
|
|
|
"""Класс для работы с ini файлами
|
|
|
|
|
|
|
|
|
|