Add support '~' path in function template load()

master
Самоукин Алексей 14 years ago
parent c702dce70b
commit afa3498c51

@ -132,7 +132,7 @@ class _terms(_error):
flagError = True flagError = True
if function: if function:
reFunction = re.compile(\ reFunction = re.compile(\
"([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\)") "([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.\'\"~]+\)")
searchFunct = reFunction.search(vals[0]) searchFunct = reFunction.search(vals[0])
if searchFunct: if searchFunct:
flagError = False flagError = False
@ -2326,13 +2326,13 @@ class profile(_file, _terms, xmlShare, processingTemplates):
varStart = "#-" varStart = "#-"
varEnd = "-#" varEnd = "-#"
self._reVar = re.compile(("%s[a-zA-Z0-9_-]+%s")%(varStart,varEnd),re.M) self._reVar = re.compile(("%s[a-zA-Z0-9_-]+%s")%(varStart,varEnd),re.M)
self._reFunc = re.compile(("%s[a-zA-Z0-9_\-\+\(\)\, \*\/\.\'\"]+%s")\ self._reFunc = re.compile(("%s[a-zA-Z0-9_\-\+\(\)\, \*\/\.\'\"~]+%s")\
%(varStart,varEnd),re.M) %(varStart,varEnd),re.M)
self._deltVarStart = len(varStart) self._deltVarStart = len(varStart)
self._deltVarEnd = len(varEnd) self._deltVarEnd = len(varEnd)
# Условия # Условия
self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\ self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\
(?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\))?\ (?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.\'\"~]+\))?\
(?P<lTerm>[\>\<\=\!\&\|]+\ (?P<lTerm>[\>\<\=\!\&\|]+\
[a-zA-Z0-9\>\<\=\!\|\&\-\+\*\/_\.\,\(\)]*)#\ [a-zA-Z0-9\>\<\=\!\|\&\-\+\*\/_\.\,\(\)]*)#\
\n*(?P<body>.+?)\n*#(?P=rTerm)#(?P<end>[ ,\t]*\n?)",re.M|re.S) \n*(?P<body>.+?)\n*#(?P=rTerm)#(?P<end>[ ,\t]*\n?)",re.M|re.S)
@ -2608,11 +2608,25 @@ class profile(_file, _terms, xmlShare, processingTemplates):
if fileName[0] != "/": if fileName[0] != "/":
path = os.path.split(nameSystemFile)[0] path = os.path.split(nameSystemFile)[0]
fileName=os.path.join(path,fileName) fileName=os.path.join(path,fileName)
# Если домашняя директория
if fileName[0] == "~":
# Получаем информацию о пользователе
uid, gid, homeDir = getDataUser()
# Получаем директорию пользователя
fileName = os.path.join(homeDir, fileName.partition("/")[2],
"")[:-1]
else: else:
fileName = terms[1].strip() fileName = terms[1].strip()
if fileName[1] != "/": if fileName[1] != "/":
path = os.path.split(nameSystemFile)[0] path = os.path.split(nameSystemFile)[0]
fileName=os.path.join(path,fileName) fileName=os.path.join(path,fileName)
# Если домашняя директория
if fileName[0] == "~":
# Получаем информацию о пользователе
uid, gid, homeDir = getDataUser()
# Получаем директорию пользователя
fileName = os.path.join(homeDir, fileName.partition("/")[2],
"")[:-1]
replace = "" replace = ""
if os.path.exists(fileName): if os.path.exists(fileName):
FD = open(fileName) FD = open(fileName)
@ -2870,6 +2884,27 @@ class profile(_file, _terms, xmlShare, processingTemplates):
isLoadVarsIni = False isLoadVarsIni = False
return isLoadVarsIni return isLoadVarsIni
def getDataUser():
"""Получить информацию о пользователе"""
userName = self.objVar.Get("ur_login")
if not userName:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("template variable 'ur_login' is empty")
cl_base.exit(1)
import pwd
try:
pwdObj = pwd.getpwnam(userName)
uid = pwdObj.pw_uid
gid = pwdObj.pw_gid
homeDir = pwdObj.pw_dir
except:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("Can not found user %s")%str(userName)
cl_base.exit(1)
return uid, gid, homeDir
def funcIni(funTxt,resS,localVarsIni,isLoadVarsIni, uid, gid, homeDir, def funcIni(funTxt,resS,localVarsIni,isLoadVarsIni, uid, gid, homeDir,
textProfileTmp): textProfileTmp):
"""локальная функция записывает и считывает значение переменной """локальная функция записывает и считывает значение переменной
@ -2878,25 +2913,8 @@ class profile(_file, _terms, xmlShare, processingTemplates):
""" """
# ~/.calculate # ~/.calculate
if not homeDir: if not homeDir:
homeDir = "" # Получаем информацию о пользователе
userName = self.objVar.Get("ur_login") uid, gid, homeDir = getDataUser()
if not userName:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("template variable 'ur_login' is empty")
cl_base.exit(1)
import pwd
try:
pwdObj = pwd.getpwnam(userName)
uid = pwdObj.pw_uid
gid = pwdObj.pw_gid
homeDir = pwdObj.pw_dir
flagFoundUser = True
except:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("Can not found user %s")%str(userName)
cl_base.exit(1)
pathConfig = os.path.join(homeDir, ".calculate") pathConfig = os.path.join(homeDir, ".calculate")
fileConfig = os.path.join(pathConfig,"ini.env") fileConfig = os.path.join(pathConfig,"ini.env")
# Создаем директорию # Создаем директорию

Loading…
Cancel
Save