Add exists() function

master
Самоукин Алексей 14 years ago
parent 0859c1a179
commit dceee3d487

@ -2635,6 +2635,32 @@ class profile(_file, _terms, xmlShare, processingTemplates):
cl_base.exit(1) cl_base.exit(1)
return textProfileTmp 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): def funcLoad(funTxt,resS,textProfileTmp):
"""если файл существует читает из файла локальную переменную """если файл существует читает из файла локальную переменную
@ -3023,31 +3049,34 @@ class profile(_file, _terms, xmlShare, processingTemplates):
mark = textProfileTmp[resS.start():resS.end()] mark = textProfileTmp[resS.start():resS.end()]
funTxt = mark[self._deltVarStart:-self._deltVarEnd] funTxt = mark[self._deltVarStart:-self._deltVarEnd]
# Функция sum # Функция sum
if funTxt[:4] == "sum(": if funTxt.startswith("sum("):
textProfileTmp = funcSum(funTxt,resS,localVars,textProfileTmp) textProfileTmp = funcSum(funTxt,resS,localVars,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
# Функция load # Функция load
elif funTxt[:5] == "load(": elif funTxt.startswith("load("):
textProfileTmp = funcLoad(funTxt,resS,textProfileTmp) textProfileTmp = funcLoad(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:4] == "pkg(": elif funTxt.startswith("pkg("):
textProfileTmp = funcPkg(funTxt,resS,textProfileTmp) textProfileTmp = funcPkg(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:4] == "rnd(": elif funTxt.startswith("rnd("):
textProfileTmp = funcRnd(funTxt,resS,textProfileTmp) textProfileTmp = funcRnd(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:5] == "case(": elif funTxt.startswith("case("):
textProfileTmp = funcCase(funTxt,resS,textProfileTmp) textProfileTmp = funcCase(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:4] == "pop(": elif funTxt.startswith("pop("):
textProfileTmp = funcPop(funTxt,resS,localVars,textProfileTmp) textProfileTmp = funcPop(funTxt,resS,localVars,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:5] == "push(": elif funTxt.startswith("push("):
textProfileTmp = funcPush(funTxt,resS,localVars,textProfileTmp) textProfileTmp = funcPush(funTxt,resS,localVars,textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt[:4] == "ini(": elif funTxt.startswith("ini("):
textProfileTmp = funcIni(funTxt, resS, textProfileTmp) textProfileTmp = funcIni(funTxt, resS, textProfileTmp)
resS = self._reFunc.search(textProfileTmp) resS = self._reFunc.search(textProfileTmp)
elif funTxt.startswith("exists("):
textProfileTmp = funcExists(funTxt, resS, textProfileTmp)
resS = self._reFunc.search(textProfileTmp)
else: else:
resS = False resS = False
if self.timeIni!=-1: if self.timeIni!=-1:

Loading…
Cancel
Save