From dceee3d487e76158e888eb8ed2f55c1edba3441d 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: Wed, 24 Mar 2010 12:30:30 +0300 Subject: [PATCH] Add exists() function --- pym/cl_profile.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/pym/cl_profile.py b/pym/cl_profile.py index 5e65d44..acfea71 100644 --- a/pym/cl_profile.py +++ b/pym/cl_profile.py @@ -2635,6 +2635,32 @@ class profile(_file, _terms, xmlShare, processingTemplates): cl_base.exit(1) return textProfileTmp + + def funcExists(funTxt,resS,textProfileTmp): + """если файл существует читает из файла локальную переменную + + если один параметр - выводит значение локальной переменной + """ + terms = funTxt[7:-1].replace(" ","").split(",") + if len(terms) !=1: + print _("error in profile %s")%nameProfile + print _("error profile term %s")%str(funTxt) + cl_base.exit(1) + fileName = terms[0].strip() + if fileName[0] == "~": + # Получаем директорию пользователя + fileName = os.path.join(self.homeDir, + fileName.partition("/")[2],"")[:-1] + elif fileName[0] != "/": + path = os.path.split(nameSystemFile)[0] + fileName=os.path.join(path,fileName) + replace = "" + if os.path.exists(fileName): + replace = "1" + textProfileTmp = textProfileTmp[:resS.start()] + replace +\ + textProfileTmp[resS.end():] + return textProfileTmp + def funcLoad(funTxt,resS,textProfileTmp): """если файл существует читает из файла локальную переменную @@ -3023,31 +3049,34 @@ class profile(_file, _terms, xmlShare, processingTemplates): mark = textProfileTmp[resS.start():resS.end()] funTxt = mark[self._deltVarStart:-self._deltVarEnd] # Функция sum - if funTxt[:4] == "sum(": + if funTxt.startswith("sum("): textProfileTmp = funcSum(funTxt,resS,localVars,textProfileTmp) resS = self._reFunc.search(textProfileTmp) # Функция load - elif funTxt[:5] == "load(": + elif funTxt.startswith("load("): textProfileTmp = funcLoad(funTxt,resS,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:4] == "pkg(": + elif funTxt.startswith("pkg("): textProfileTmp = funcPkg(funTxt,resS,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:4] == "rnd(": + elif funTxt.startswith("rnd("): textProfileTmp = funcRnd(funTxt,resS,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:5] == "case(": + elif funTxt.startswith("case("): textProfileTmp = funcCase(funTxt,resS,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:4] == "pop(": + elif funTxt.startswith("pop("): textProfileTmp = funcPop(funTxt,resS,localVars,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:5] == "push(": + elif funTxt.startswith("push("): textProfileTmp = funcPush(funTxt,resS,localVars,textProfileTmp) resS = self._reFunc.search(textProfileTmp) - elif funTxt[:4] == "ini(": + elif funTxt.startswith("ini("): textProfileTmp = funcIni(funTxt, resS, textProfileTmp) resS = self._reFunc.search(textProfileTmp) + elif funTxt.startswith("exists("): + textProfileTmp = funcExists(funTxt, resS, textProfileTmp) + resS = self._reFunc.search(textProfileTmp) else: resS = False if self.timeIni!=-1: