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

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

@ -132,7 +132,7 @@ class _terms(_error):
flagError = True
if function:
reFunction = re.compile(\
"([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\)")
"([a-zA-Z0-9\_\-]+)\([a-zA-Z0-9_\-\+\,\*\/\.\'\"~]+\)")
searchFunct = reFunction.search(vals[0])
if searchFunct:
flagError = False
@ -2326,13 +2326,13 @@ class profile(_file, _terms, xmlShare, processingTemplates):
varStart = "#-"
varEnd = "-#"
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)
self._deltVarStart = len(varStart)
self._deltVarEnd = len(varEnd)
# Условия
self._reTermBloc = re.compile("#\?(?P<rTerm>[a-zA-Z0-9\-_]+)\
(?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.\'\"]+\))?\
(?P<func>\([a-zA-Z0-9_\-\+\,\*\/\.\'\"~]+\))?\
(?P<lTerm>[\>\<\=\!\&\|]+\
[a-zA-Z0-9\>\<\=\!\|\&\-\+\*\/_\.\,\(\)]*)#\
\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] != "/":
path = os.path.split(nameSystemFile)[0]
fileName=os.path.join(path,fileName)
# Если домашняя директория
if fileName[0] == "~":
# Получаем информацию о пользователе
uid, gid, homeDir = getDataUser()
# Получаем директорию пользователя
fileName = os.path.join(homeDir, fileName.partition("/")[2],
"")[:-1]
else:
fileName = terms[1].strip()
if fileName[1] != "/":
path = os.path.split(nameSystemFile)[0]
fileName=os.path.join(path,fileName)
# Если домашняя директория
if fileName[0] == "~":
# Получаем информацию о пользователе
uid, gid, homeDir = getDataUser()
# Получаем директорию пользователя
fileName = os.path.join(homeDir, fileName.partition("/")[2],
"")[:-1]
replace = ""
if os.path.exists(fileName):
FD = open(fileName)
@ -2870,6 +2884,27 @@ class profile(_file, _terms, xmlShare, processingTemplates):
isLoadVarsIni = False
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,
textProfileTmp):
"""локальная функция записывает и считывает значение переменной
@ -2878,25 +2913,8 @@ class profile(_file, _terms, xmlShare, processingTemplates):
"""
# ~/.calculate
if not homeDir:
homeDir = ""
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
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)
# Получаем информацию о пользователе
uid, gid, homeDir = getDataUser()
pathConfig = os.path.join(homeDir, ".calculate")
fileConfig = os.path.join(pathConfig,"ini.env")
# Создаем директорию

Loading…
Cancel
Save