Bugfix and added belong()- template function, cl_belong_pkg - template variable

develop
Самоукин Алексей 14 years ago
parent e8aef179d1
commit 83b326d2e6

@ -175,7 +175,7 @@ class DataVars(object):
dataVar = getattr(moduleVar.Data, nameVar)
except AttributeError, e:
pass
if dataVar:
if not dataVar is False:
break
if dataVar == False:
err1 = _("Not found variable %s")%nameVar

@ -46,7 +46,7 @@ class _shareTermsFunction:
_reFunctionArgvInSquareBrackets = "a-zA-Z0-9_\-\+\,\*\/\.\'\"~\\\\ "
_reFunctionArgvText = "[%s]"%_reFunctionArgvInSquareBrackets
# регулярное выражение для поиска функции в шаблоне
_reFunctionText = "([a-zA-Z0-9\_\-]+)\(%s+\)" %_reFunctionArgvText
_reFunctionText = "([a-zA-Z0-9\_\-]+)\((%s+|)\)" %_reFunctionArgvText
class _terms(_error, _shareTermsFunction):
@ -2922,6 +2922,34 @@ class templateFunction(_error, _shareTemplate, _shareTermsFunction):
textTemplateTmp[resS.end():]
return textTemplateTmp
def funcBelong(self, funArgv, resS, localVars, textTemplateTmp):
"""Функция шаблона belongs().
В случае установки переменной os_belongs_pkg=имя пакета, и совпадения
имени пакета в переменной и имени пакета в функции выдает "1" иначе ""
Если переменная os_belongs_pkg пуста выдает "1"
"""
terms = funArgv.replace(" ","").split(",")
if len(terms) != 1:
self.printErrTemplate()
cl_overriding.exit(1)
funcPkg = terms[0]
if not funcPkg:
funcPkg = os.path.split(os.path.dirname(self.nameTemplate))[1]
if not funcPkg:
print _("incorrect template path")
self.printErrTemplate()
cl_overriding.exit(1)
pkg = self.objVar.Get("cl_belong_pkg")
replace = ""
if pkg:
if pkg == funcPkg:
replace = "1"
else:
replace = "1"
textTemplateTmp = textTemplateTmp[:resS.start()] + replace +\
textTemplateTmp[resS.end():]
return textTemplateTmp
def printErrTemplate(self):
"""Печать ошибки при обработке функций шаблона"""
print _("error in template %s")%self.nameTemplate
@ -3035,7 +3063,7 @@ class template(_file, _terms, xmlShare, templateFormat, _shareTemplate):
self.varEnd),re.M)
# Условия
self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\
(?P<func>\(%s+\))?\
(?P<func>\((%s+|)\))?\
(?P<lTerm>[\>\<\=\!\&\|]+\
[\>\<\=\!\|\&\(\)%s]*)#\
\n*(?P<body>.+?)\n*#(?P=rTerm)#(?P<end>[ ,\t]*\n?)"\
@ -4589,4 +4617,4 @@ class iniParser(_error, templateFormat):
nSect = objIni.docObj.getNameArea(xmlNode)
if nSect:
namesSection.append(nSect)
return namesSection
return namesSection

@ -140,6 +140,10 @@ class Data:
# install / uninstall - установка и удаление программы
cl_pass_action = {}
# Состояние программы
# Указываем дополнительно к cl_pass_action в случае необходимости
cl_pass_state = {}
# Jabber ID пользователя
ur_jid = {'mode':"r", 'official':True}
@ -150,4 +154,10 @@ class Data:
# ip или имя домена (под управлением calculate-server)
cl_remote_host = {'mode':'r', 'official':True}
# Переменная работающая совместно с функцией шаблонов belong(имя_пакета)
# Если переменная будет определена то будут использованы шаблоны
# у которых параметр имя пакета функции шаблонов belong(имя_пакета)
# совпадает с значением этой переменной
# (имя_пакета == значение cl_belong_pkg)
cl_belong_pkg = {'mode':'r', 'official':True}

Loading…
Cancel
Save