Add template function info()

develop
Самоукин Алексей 14 years ago
parent 33581df37c
commit 31738e4fa4

@ -32,7 +32,7 @@ from cl_ldap import ldapFun
import cl_overriding
from cl_utils import _error, _toUNICODE, getModeFile, removeDir, typeFile,\
scanDirectory
scanDirectory, convertStrListDict
import cl_lang
tr = cl_lang.lang()
@ -2293,6 +2293,8 @@ class templateFunction(_error, _shareTemplate, _shareTermsFunction):
self.timeConfigsIni = {}
# Словарь хранения переменых полученных функцией env() из env файлов
self.valuesVarEnv = {}
# Словарь хранения опций для функции info()
self.optionsInfo = {}
def equalTerm(self, term, localVars):
"""Метод для вычисления выражения"""
@ -2870,6 +2872,59 @@ class templateFunction(_error, _shareTemplate, _shareTermsFunction):
textTemplateTmp[resS.end():]
return textTemplateTmp
def funcInfo(self, funArgv, resS, localVars, textTemplateTmp):
"""Функция шаблона info(), выдает значение опций сервиса
из /var/calculate/remote/calculate.env
"""
terms = funArgv.replace(" ","").split(",")
if len(terms) != 2:
self.printErrTemplate()
cl_overriding.exit(1)
service = terms[0].strip()
option = terms[1].strip()
if not service or not option:
self.printErrTemplate()
cl_overriding.exit(1)
if not self.optionsInfo:
valueEnvData = self.objVar.Get("cl_env_data")
envData = {}
envData.update(valueEnvData)
if not "remote" in envData:
print _("Can not found env path 'remote' in template variable \
'cl_env_data'")
self.printErrTemplate()
cl_overriding.exit(1)
# файл /var/calculate/remote/calculate.env
envFile = envData["remote"]
# получить объект настроенный на ini
config = iniParser(envFile)
# получаем все секции из конфигурационного файла
allsect = config.getAllSectionNames()
if allsect:
# Секция (название сервиса)
for section in allsect:
allvars = config.getAreaVars(section)
if allvars == False:
self.printErrTemplate()
cl_overriding.exit(1)
# Опции сервиса
options = {}
for varName, value in allvars.items():
varName = varName.encode("UTF-8")
if varName.endswith("%s_info" %section):
value = convertStrListDict(value.encode("UTF-8"))
options = value
if options:
self.optionsInfo[section] = options
replace = ''
if service in self.optionsInfo:
if option in self.optionsInfo[service]:
replace = self.optionsInfo[service][option]
textTemplateTmp = textTemplateTmp[:resS.start()] + replace +\
textTemplateTmp[resS.end():]
return textTemplateTmp
def printErrTemplate(self):
"""Печать ошибки при обработке функций шаблона"""
print _("error in template %s")%self.nameTemplate

@ -40,9 +40,9 @@ class Data:
# Алиасы и пути к ini файлам
cl_env_data = {'official':True,
'value':[('default', '/etc/calculate/calculate.env'),
('local', '/var/calculate/calculate.env'),
('remote', '/var/calculate/remote/calculate.env')]}
'value':[('default', '/etc/calculate/calculate2.env'),
('local', '/var/calculate/calculate2.env'),
('remote', '/var/calculate/remote/calculate2.env')]}
# Алиасы путей к ini файлам (из cl_env_data)
cl_env_location = {'official':True}

Loading…
Cancel
Save