From 5c5f1c7a98f745d2c2b51819ca88c89443a00106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=83=D0=BA=D0=B8=D0=BD=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Fri, 28 May 2010 16:45:29 +0400 Subject: [PATCH] rename function template info()to server() --- pym/cl_datavars.py | 36 ++++++++++++++++++++++++++++++++---- pym/cl_template.py | 42 ++++++++++-------------------------------- pym/cl_vars.py | 4 ++++ 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/pym/cl_datavars.py b/pym/cl_datavars.py index 4f6a92c..c363599 100644 --- a/pym/cl_datavars.py +++ b/pym/cl_datavars.py @@ -100,6 +100,8 @@ class var: class DataVars(object): + """Класс хранения переменных шаблонов""" + class DataVarsError(Exception): """Класс ошибок""" pass @@ -469,6 +471,31 @@ storage of variables templates")%location valueVar = value return valueVar.encode("UTF-8") + def GetRemoteInfo(self, envFile): + """Получение информационных переменных + + из файла envFile""" + optionsInfo = {} + # получить объект настроенный на ini + config = iniParser(envFile) + # получаем все секции из конфигурационного файла + allsect = config.getAllSectionNames() + if allsect: + # Секция (название сервиса) + for section in allsect: + allvars = config.getAreaVars(section) + if allvars == False: + return False + # Опции сервиса + options = {} + for varName, value in allvars.items(): + varName = varName.encode("UTF-8") + value=cl_utils.convertStrListDict(value.encode("UTF-8")) + options[varName] = value + if options: + optionsInfo[section] = options + return optionsInfo + def flIniFile(self): '''Заместить значение переменных значениями из ини файлов @@ -547,6 +574,7 @@ storage of variables templates")%location return foundVar def getVars(self, type_names=None): + """Словарь переменных для печати""" ret = {} for section, moduleVar, fillobj in self._importList: dataVar=moduleVar.Data @@ -568,8 +596,8 @@ storage of variables templates")%location ret[nameVar] = getattr(self, nameVar) return ret - #распечатать список переменных с значениями def printVars(self,type_names=None): + """распечатать список переменных с значениями""" var=None var=self.getVars(type_names) mlen_name=0; @@ -587,9 +615,9 @@ storage of variables templates")%location plist.sort() br = cl_utils.fillstr("-",mlen_name) + " " +\ cl_utils.fillstr("-",mlen_mode) + " " + cl_utils.fillstr("-",10) - print "The list of variables:" - print "var name".center(mlen_name),\ - "Mode","Value" + print _("The list of variables:") + print _("var name").center(mlen_name),\ + _("Mode"),_("Value") print br for i in plist: p_val=var[i].value diff --git a/pym/cl_template.py b/pym/cl_template.py index 2945d1f..46a377f 100644 --- a/pym/cl_template.py +++ b/pym/cl_template.py @@ -2872,7 +2872,7 @@ class templateFunction(_error, _shareTemplate, _shareTermsFunction): textTemplateTmp[resS.end():] return textTemplateTmp - def funcInfo(self, funArgv, resS, localVars, textTemplateTmp): + def funcServer(self, funArgv, resS, localVars, textTemplateTmp): """Функция шаблона info(), выдает значение опций сервиса из /var/calculate/remote/calculate.env @@ -2887,40 +2887,18 @@ class templateFunction(_error, _shareTemplate, _shareTermsFunction): 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'") + # файл /var/calculate/remote/server.env + envFile = self.objVar.Get("cl_env_server_path") + # получаем словарь всех информационных переменных + optInfo = self.objVar.GetRemoteInfo(envFile) + if optInfo is False: 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 + if optInfo: + self.optionsInfo = optInfo replace = '' - if service in self.optionsInfo: - if option in self.optionsInfo[service]: - replace = self.optionsInfo[service][option] + if service in self.optionsInfo and option in self.optionsInfo[service]: + replace = self.optionsInfo[service][option] textTemplateTmp = textTemplateTmp[:resS.start()] + replace +\ textTemplateTmp[resS.end():] return textTemplateTmp diff --git a/pym/cl_vars.py b/pym/cl_vars.py index c457be3..4a00fb8 100644 --- a/pym/cl_vars.py +++ b/pym/cl_vars.py @@ -50,6 +50,10 @@ class Data: # Пути к ini файлам (из cl_env_data) cl_env_path = {} + # Путь к информационному файлу сервера + cl_env_server_path = {'official':True, + 'value':'/var/calculate/remote/server.env'} + # Пути к файлам шаблонов cl_template_path = {'value':["/usr/share/calculate-2.2/templates", "/var/calculate/templates",