From 8090b3b6896c16675624c47a6cb92ef950f9c56c Mon Sep 17 00:00:00 2001 From: asamoukin Date: Wed, 25 Feb 2009 14:41:49 +0000 Subject: [PATCH] git-svn-id: http://svn.calculate.ru/calculate2/calculate-lib/trunk@941 c91db197-33c1-4113-bf15-f8a5c547ca64 --- pym/cl_profile.py | 76 +++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/pym/cl_profile.py b/pym/cl_profile.py index 622a98e..4a1813f 100644 --- a/pym/cl_profile.py +++ b/pym/cl_profile.py @@ -143,6 +143,7 @@ class _terms(_error): self.setError("'%s'"%term + " " + _("incorrect")) self.setError(textError) return False + flagIntTypeVar = None if flagFunction: valVars = function("#-%s-#"%vals[0]) if valVars == "": @@ -151,6 +152,19 @@ class _terms(_error): self.setError("'%s'"%term + " " + _("incorrect")) self.setError(textError) return False + if "load" == searchFunct.group(1): + if re.search("\(\s*num\s*,",vals[0]): + if valVars: + try: + valVars = int(valVars) + except: + self.setError("'%s'"%term + " " + \ + _("incorrect")) + self.setError (textError) + return False + flagIntTypeVar = True + else: + flagIntTypeVar = False else: try: valVars = self.objVar.Get(vals[0]) @@ -160,7 +174,9 @@ class _terms(_error): exit(1) # Cравниваем номера версий if "_ver" in vals[0] or \ - (flagFunction and "pkg" == searchFunct.group(1)): + (flagFunction and "pkg" == searchFunct.group(1)) or\ + (flagFunction and "load" == searchFunct.group(1) and\ + re.search("\(\s*ver\s*,",vals[0])): verFile, verVar = self._convertVers(vals[1],valVars) exec("res=("+"'"+verVar+"'"+sepF+"'"+verFile+"'"+")") if res: @@ -168,11 +184,12 @@ class _terms(_error): else: listEqual.append("0") else: - flagIntTypeVar = True - try: - valVars = int(valVars) - except: - flagIntTypeVar = False + if flagIntTypeVar == None: + flagIntTypeVar = True + try: + valVars = int(valVars) + except: + flagIntTypeVar = False if flagIntTypeVar: if not vals[1].strip(): vals[1] = 0 @@ -2241,33 +2258,42 @@ class profile(_file, _terms,xmlShare): exit(1) return textProfileTmp - def funcLoad(resS,localVarsLoad,textProfileTmp): + def funcLoad(funTxt,resS,textProfileTmp): """если файл существует читает из файла локальную переменную если один параметр - выводит значение локальной переменной """ terms = funTxt[5:-1].replace(" ","").split(",") - # Название локальной переменной - nameLocVar = terms[0] - if not localVarsLoad.has_key(nameLocVar): - localVarsLoad[nameLocVar] = "" - if len(terms) == 2: - if terms[1].strip(): - fileName = terms[1].strip() - if fileName[1] != "/": - path = os.path.split(nameSystemFile)[0] - fileName=os.path.join(path,fileName) - if os.path.exists(fileName): - FD = open(fileName) - localVarsLoad[nameLocVar] = FD.read().strip() - FD.close - if not terms[0].strip() or\ + if not terms[0].strip() or\ (len(terms)==2 and not terms[1].strip()) or\ len(terms)>2: print _("error in profile %s")%nameProfile print _("error profile term %s")%str(funTxt) exit(1) - replace = localVarsLoad[nameLocVar] + if len(terms) == 2: + if not terms[0] in ["ver","num","char","key"]: + print _("error in profile %s")%nameProfile + print _("error profile term %s")%str(funTxt) + print _("first argument function is not 'ver' or 'num' or\ + 'char'") + exit(1) + if len(terms) == 1: + fileName = terms[0].strip() + if fileName[0] != "/": + path = os.path.split(nameSystemFile)[0] + fileName=os.path.join(path,fileName) + else: + fileName = terms[1].strip() + if fileName[1] != "/": + path = os.path.split(nameSystemFile)[0] + fileName=os.path.join(path,fileName) + replace = "" + if os.path.exists(fileName): + FD = open(fileName) + replace = FD.read().strip() + FD.close + if terms[0] in ["ver","num"]: + replace = "0" textProfileTmp = textProfileTmp[:resS.start()] + replace +\ textProfileTmp[resS.end():] return textProfileTmp @@ -2416,8 +2442,6 @@ class profile(_file, _terms,xmlShare): # Локальные переменные localVars = {} - # Локальные переменные для функции load - localVarsLoad = {} # Регулярное выражние для сложения sNum = re.compile("\-[^\-\+]+|[^\-\+]+") # Регулярное выражение для умножениея и деления @@ -2433,7 +2457,7 @@ class profile(_file, _terms,xmlShare): resS = self._reFunc.search(textProfileTmp) # Функция load elif funTxt[:5] == "load(": - textProfileTmp = funcLoad(resS,localVarsLoad,textProfileTmp) + textProfileTmp = funcLoad(funTxt,resS,textProfileTmp) resS = self._reFunc.search(textProfileTmp) elif funTxt[:4] == "pkg(": textProfileTmp = funcPkg(funTxt,resS,textProfileTmp)