|
|
|
@ -0,0 +1,551 @@
|
|
|
|
|
diff --git calculate/lib/cl_template.py calculate/lib/cl_template.py
|
|
|
|
|
index 24ad307..55527cd 100644
|
|
|
|
|
--- calculate/lib/cl_template.py
|
|
|
|
|
+++ calculate/lib/cl_template.py
|
|
|
|
|
@@ -39,8 +39,9 @@ from utils.common import _error, _warning
|
|
|
|
|
from utils.text import _toUNICODE, convertStrListDict
|
|
|
|
|
from utils.portage import isPkgInstalled
|
|
|
|
|
from utils.content import PkgContents
|
|
|
|
|
-from utils.files import (getModeFile, removeDir, typeFile, scanDirectory,
|
|
|
|
|
- pathJoin,process,STDOUT)
|
|
|
|
|
+from utils.files import (getModeFile, listDirectory,removeDir, typeFile,
|
|
|
|
|
+ scanDirectory,
|
|
|
|
|
+ pathJoin,readFile,readLinesFile,process,STDOUT)
|
|
|
|
|
from datavars import DataVarsError
|
|
|
|
|
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
|
@@ -301,6 +302,8 @@ class _terms(_error, _shareTermsFunction):
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
valVars = self.objVar.Get(vals[0])
|
|
|
|
|
+ if not valVars:
|
|
|
|
|
+ valVars = ""
|
|
|
|
|
except DataVarsError, e:
|
|
|
|
|
raise TemplatesError("{header}\n{body}".format(
|
|
|
|
|
header=textError,body=str(e)))
|
|
|
|
|
@@ -502,7 +505,7 @@ class fileHeader(_terms):
|
|
|
|
|
headerTerm = True
|
|
|
|
|
|
|
|
|
|
def __init__(self, templateName, text, comment=False, fileType=False,
|
|
|
|
|
- objVar=False, function=False):
|
|
|
|
|
+ objVar=False, function=False, templateObj=None):
|
|
|
|
|
self.body = text
|
|
|
|
|
# Объект с переменными
|
|
|
|
|
self.objVar=objVar
|
|
|
|
|
@@ -564,6 +567,7 @@ class fileHeader(_terms):
|
|
|
|
|
self.body = self.body[reL.end():]
|
|
|
|
|
else:
|
|
|
|
|
self.body = ""
|
|
|
|
|
+ paramLine = templateObj.applyFuncTemplate(paramLine,templateName)
|
|
|
|
|
paramList = self.splitParLine(paramLine)
|
|
|
|
|
if paramList:
|
|
|
|
|
for i in paramList:
|
|
|
|
|
@@ -2181,6 +2185,10 @@ class _file(_error):
|
|
|
|
|
F_CONF = open (nameFileConfig, "r+")
|
|
|
|
|
except:
|
|
|
|
|
try:
|
|
|
|
|
+ if os.path.isdir(nameFileConfig):
|
|
|
|
|
+ self.setWarning(_("unable to open the directory as file:")
|
|
|
|
|
+ + nameFileConfig)
|
|
|
|
|
+ return False
|
|
|
|
|
F_CONF = open(nameFileConfig, "w+")
|
|
|
|
|
except:
|
|
|
|
|
self.setError(_("unable to open the file:")
|
|
|
|
|
@@ -2482,6 +2490,9 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
# директория установленных программ
|
|
|
|
|
basePkgDir = "/var/db/pkg"
|
|
|
|
|
|
|
|
|
|
+ # кэш для проверки наличия пакета в портежах
|
|
|
|
|
+ cachePortdir = {}
|
|
|
|
|
+
|
|
|
|
|
# стек глобальных переменных
|
|
|
|
|
stackGlobalVars = []
|
|
|
|
|
|
|
|
|
|
@@ -2498,6 +2509,11 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
# Текст функции шаблона
|
|
|
|
|
functText = ""
|
|
|
|
|
|
|
|
|
|
+ # regular for discard sort number and version
|
|
|
|
|
+ reData = re.compile(r"^(?:\d+-)?(.+?)(?:-(?:|always|\d+|\d(?:\d|\.|pre|_"
|
|
|
|
|
+ "|-always|alpha|beta|pre|rc|[a-z][^a-z])*[a-z]?)(?:"
|
|
|
|
|
+ "-r\d+)?)?$",re.S)
|
|
|
|
|
+
|
|
|
|
|
currentBelong = ""
|
|
|
|
|
|
|
|
|
|
def __init__(self, objVar):
|
|
|
|
|
@@ -2756,7 +2772,8 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
"""
|
|
|
|
|
for pkgname,category,ver,slot in pkgs:
|
|
|
|
|
fullname = "%s/%s"%(category,pkgname)
|
|
|
|
|
- if not fullname in self.installProg:
|
|
|
|
|
+ if not fullname in self.installProg or \
|
|
|
|
|
+ type(self.installProg[fullname]) != dict:
|
|
|
|
|
self.installProg[fullname] = self.installProg[pkgname] = {}
|
|
|
|
|
if force or not slot in self.installProg[fullname]:
|
|
|
|
|
self.installProg[fullname][slot] = ver
|
|
|
|
|
@@ -2803,6 +2820,18 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
"""Функция шаблона pkg(), выдает номер версии программы"""
|
|
|
|
|
# Название программы
|
|
|
|
|
nameProg = funArgv.replace(" ","")
|
|
|
|
|
+ if not nameProg:
|
|
|
|
|
+ fileName = os.path.split(self.nameTemplate)[1]
|
|
|
|
|
+ if fileName == '.calculate_directory':
|
|
|
|
|
+ parentDir = os.path.dirname(self.nameTemplate)
|
|
|
|
|
+ parentDir, pkgName = os.path.split(parentDir)
|
|
|
|
|
+ else:
|
|
|
|
|
+ parentDir, pkgName = os.path.split(self.nameTemplate)
|
|
|
|
|
+ category = os.path.split(parentDir)[1]
|
|
|
|
|
+ # reg for discard version and sort number
|
|
|
|
|
+ pkgName = self.reData.search(pkgName).group(1)
|
|
|
|
|
+ category = self.reData.search(category).group(1)
|
|
|
|
|
+ nameProg = "%s/%s"%(category,pkgName)
|
|
|
|
|
# Замена функции в тексте шаблона
|
|
|
|
|
replace = ""
|
|
|
|
|
if "/" in nameProg:
|
|
|
|
|
@@ -2810,6 +2839,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
nameProg, spl, slot = nameProg.partition(":")
|
|
|
|
|
if not category in self.installCategory:
|
|
|
|
|
self.getInstallPkgGentoo(category=category)
|
|
|
|
|
+ self.installCategory.append(category)
|
|
|
|
|
replace = self.pkg(nameProg, slot=slot or None)
|
|
|
|
|
else:
|
|
|
|
|
if not self.flagAllPkgScan:
|
|
|
|
|
@@ -2875,7 +2905,11 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
" is neither 'upper' or 'lower' or"
|
|
|
|
|
" 'capitalize'"))
|
|
|
|
|
try:
|
|
|
|
|
- strValue = str(self.objVar.Get(terms[1]))
|
|
|
|
|
+ strValue = self.objVar.Get(terms[1])
|
|
|
|
|
+ if not strValue:
|
|
|
|
|
+ strValue = ""
|
|
|
|
|
+ else:
|
|
|
|
|
+ strValue = str(strValue)
|
|
|
|
|
except:
|
|
|
|
|
raise TemplatesError(
|
|
|
|
|
_("error in template %s")%self.nameTemplate + "\n" +
|
|
|
|
|
@@ -2894,6 +2928,31 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
textTemplateTmp[resS.end():]
|
|
|
|
|
return textTemplateTmp
|
|
|
|
|
|
|
|
|
|
+ def funcIn(self, funArgv, resS, localVars, textTemplateTmp, nameTemp):
|
|
|
|
|
+ """
|
|
|
|
|
+ Function in for check value in variable
|
|
|
|
|
+ """
|
|
|
|
|
+ terms = funArgv.replace(" ","").split(",")
|
|
|
|
|
+ # Название локальной переменной
|
|
|
|
|
+ nameLocVar = terms[0]
|
|
|
|
|
+ flagFoundVar = False
|
|
|
|
|
+ try:
|
|
|
|
|
+ value = self.objVar.Get(nameLocVar)
|
|
|
|
|
+ flagFoundVar = True
|
|
|
|
|
+ except:
|
|
|
|
|
+ pass
|
|
|
|
|
+ if flagFoundVar:
|
|
|
|
|
+ if value in terms[1:]:
|
|
|
|
|
+ replace = "1"
|
|
|
|
|
+ else:
|
|
|
|
|
+ replace = ""
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.raiseErrTemplate(_("error: variable %s does not exist")\
|
|
|
|
|
+ %str(nameLocVar))
|
|
|
|
|
+ textTemplateTmp = textTemplateTmp[:resS.start()] + replace +\
|
|
|
|
|
+ textTemplateTmp[resS.end():]
|
|
|
|
|
+ return textTemplateTmp
|
|
|
|
|
+
|
|
|
|
|
def funcPush(self, funArgv, resS, localVars, textTemplateTmp, nameTemp):
|
|
|
|
|
"""локальная функция записывает значение переменной
|
|
|
|
|
|
|
|
|
|
@@ -3215,12 +3274,63 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
return textTemplateTmp
|
|
|
|
|
|
|
|
|
|
def funcBelong(self, funArgv, resS, localVars, textTemplateTmp, nameTemp):
|
|
|
|
|
- #self.setWarning(
|
|
|
|
|
- # _("Function '{funcname}' used by {template} is depricated"
|
|
|
|
|
- # " and will be removed at the future").format(
|
|
|
|
|
- # funcname="belong",template=nameTemp))
|
|
|
|
|
- return self.funcMerge(funArgv, resS, localVars,
|
|
|
|
|
- textTemplateTmp, nameTemp)
|
|
|
|
|
+ self.setWarning(
|
|
|
|
|
+ _("Function '{funcname}' used by {template} is depricated"
|
|
|
|
|
+ " and will be removed at the future").format(
|
|
|
|
|
+ funcname="belong",template=nameTemp))
|
|
|
|
|
+ replace = ""
|
|
|
|
|
+ return textTemplateTmp[:resS.start()] + replace +\
|
|
|
|
|
+ textTemplateTmp[resS.end():]
|
|
|
|
|
+
|
|
|
|
|
+ def checkCorrectPkgName(self,package):
|
|
|
|
|
+ """
|
|
|
|
|
+ Check pkg name (in /var/db/pkg,/usr/portage,/var/lib/layman/calculate
|
|
|
|
|
+ and other overlays)
|
|
|
|
|
+ """
|
|
|
|
|
+ category,spl,pkgname = package.partition('/')
|
|
|
|
|
+ pkgname, spl, slot = pkgname.partition(":")
|
|
|
|
|
+ # check installed package in system
|
|
|
|
|
+ if not category in self.installCategory:
|
|
|
|
|
+ self.getInstallPkgGentoo(category=category)
|
|
|
|
|
+ self.installCategory.append(category)
|
|
|
|
|
+ if self.pkg("%s/%s"%(category,pkgname), slot=slot or None):
|
|
|
|
|
+ return True
|
|
|
|
|
+ # check package in portage and calculate,overlay
|
|
|
|
|
+ def queuePortdir():
|
|
|
|
|
+ yield "/usr/portage"
|
|
|
|
|
+ calculate = "/var/lib/layman/calculate"
|
|
|
|
|
+ yield calculate
|
|
|
|
|
+ for portdir in filter(lambda x:x!=calculate,
|
|
|
|
|
+ self.objVar.Get('cl_portdir_overlay')):
|
|
|
|
|
+ yield portdir
|
|
|
|
|
+
|
|
|
|
|
+ for portdir in queuePortdir():
|
|
|
|
|
+ if not portdir in self.cachePortdir:
|
|
|
|
|
+ lPortdir = len(portdir)+1
|
|
|
|
|
+ self.cachePortdir[portdir] = \
|
|
|
|
|
+ list(set(
|
|
|
|
|
+ map(lambda x:x[lPortdir:].rpartition('/')[0],
|
|
|
|
|
+ glob.glob("%s/*/*/*.ebuild"%portdir))))
|
|
|
|
|
+ if package in self.cachePortdir[portdir]:
|
|
|
|
|
+ return True
|
|
|
|
|
+ else:
|
|
|
|
|
+ if portdir == "/usr/portage" and \
|
|
|
|
|
+ len(self.cachePortdir[portdir]) < 30:
|
|
|
|
|
+ #raise TemplatesError(_("Ebuild files are not found in portage"))
|
|
|
|
|
+ return True
|
|
|
|
|
+ if not "portage/update" in self.cachePortdir:
|
|
|
|
|
+ updateFiles = sorted(listDirectory('/usr/portage/profiles/updates'),
|
|
|
|
|
+ key=lambda x:tuple(reversed(x.split('Q-'))),reverse=True)
|
|
|
|
|
+ if updateFiles:
|
|
|
|
|
+ self.cachePortdir["portage/update"] = \
|
|
|
|
|
+ map(lambda x:x.split(' ')[1],
|
|
|
|
|
+ filter(lambda x:x.startswith('move '),
|
|
|
|
|
+ readLinesFile(os.path.join('/usr/portage/profiles/updates',
|
|
|
|
|
+ updateFiles[0]))))
|
|
|
|
|
+ if package in self.cachePortdir:
|
|
|
|
|
+ self.printWARNING(_("Package {frompkg} was renamed").format(frompkg=package))
|
|
|
|
|
+ return True
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
|
|
def funcMerge(self, funArgv, resS, localVars, textTemplateTmp, nameTemp):
|
|
|
|
|
"""
|
|
|
|
|
@@ -3234,11 +3344,27 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
|
|
|
|
|
self.raiseErrTemplate()
|
|
|
|
|
funcPkg = terms[0]
|
|
|
|
|
if not funcPkg:
|
|
|
|
|
- funcPkg = os.path.split(self.nameTemplate)[1]
|
|
|
|
|
- if funcPkg == '.calculate_directory':
|
|
|
|
|
- funcPkg = os.path.split(os.path.dirname(self.nameTemplate))[1]
|
|
|
|
|
- if not funcPkg:
|
|
|
|
|
- self.raiseErrTemplate(_("incorrect template path"))
|
|
|
|
|
+ fileName = os.path.split(self.nameTemplate)[1]
|
|
|
|
|
+ if fileName == '.calculate_directory':
|
|
|
|
|
+ parentDir = os.path.dirname(self.nameTemplate)
|
|
|
|
|
+ parentDir, pkgName = os.path.split(parentDir)
|
|
|
|
|
+ else:
|
|
|
|
|
+ parentDir, pkgName = os.path.split(self.nameTemplate)
|
|
|
|
|
+ category = os.path.split(parentDir)[1]
|
|
|
|
|
+ # reg for discard version and sort number
|
|
|
|
|
+ pkgName = self.reData.search(pkgName).group(1)
|
|
|
|
|
+ category = self.reData.search(category).group(1)
|
|
|
|
|
+ funcPkg = "%s/%s"%(category,pkgName)
|
|
|
|
|
+ try:
|
|
|
|
|
+ if not self.checkCorrectPkgName(funcPkg):
|
|
|
|
|
+ self.printWARNING(
|
|
|
|
|
+ _("Package {pkgName} specified in the merge() into "
|
|
|
|
|
+ "{templName} template is not found").format(
|
|
|
|
|
+ pkgName=funcPkg,templName=self.nameTemplate))
|
|
|
|
|
+ return textTemplateTmp[:resS.start()] + \
|
|
|
|
|
+ textTemplateTmp[resS.end():]
|
|
|
|
|
+ except TemplatesError as e:
|
|
|
|
|
+ self.printWARNING(str(e))
|
|
|
|
|
self.currentBelong = funcPkg
|
|
|
|
|
pkg = self.objVar.Get("cl_merge_pkg")
|
|
|
|
|
replace = ""
|
|
|
|
|
@@ -3601,6 +3727,9 @@ re.M|re.S)
|
|
|
|
|
self.allTemplates = 0
|
|
|
|
|
# Объект функций шаблона
|
|
|
|
|
self.functObj = templateFunction(self.objVar)
|
|
|
|
|
+ self.functObj.printSUCCESS = self.printSUCCESS
|
|
|
|
|
+ self.functObj.printWARNING = self.printWARNING
|
|
|
|
|
+ self.functObj.printERROR = self.printERROR
|
|
|
|
|
# Метод применения функций к шаблонам
|
|
|
|
|
self.applyFuncTemplate = self.functObj.applyFuncTemplate
|
|
|
|
|
# Объект для определения типа файла шаблона
|
|
|
|
|
@@ -3658,7 +3787,8 @@ re.M|re.S)
|
|
|
|
|
|
|
|
|
|
def executeTemplate(self, code, execPath):
|
|
|
|
|
"""Execute template"""
|
|
|
|
|
- p = process(execPath,lang=self.objVar.Get('os_locale_locale'))
|
|
|
|
|
+ p = process(execPath,lang=self.objVar.Get('os_locale_locale'),
|
|
|
|
|
+ envdict=os.environ)
|
|
|
|
|
if "/bin/bash" in code.partition('\n')[0]:
|
|
|
|
|
p.write("""function translate() {
|
|
|
|
|
gettext -d cl_template "$*"
|
|
|
|
|
@@ -3771,7 +3901,11 @@ gettext -d cl_template "$*"
|
|
|
|
|
varName = mark[self._deltVarStart:-self._deltVarEnd]
|
|
|
|
|
varValue = ""
|
|
|
|
|
try:
|
|
|
|
|
- varValue = str(self.objVar.Get(varName))
|
|
|
|
|
+ varValue = self.objVar.Get(varName)
|
|
|
|
|
+ if not varValue:
|
|
|
|
|
+ varValue = ""
|
|
|
|
|
+ else:
|
|
|
|
|
+ varValue = str(varValue)
|
|
|
|
|
except DataVarsError, e:
|
|
|
|
|
raise TemplatesError(_("error in template %s")%nameTemplate
|
|
|
|
|
+ "\n" + str(e))
|
|
|
|
|
@@ -4131,9 +4265,8 @@ gettext -d cl_template "$*"
|
|
|
|
|
for pkg in self.objVar.Get('cl_merge_pkg'):
|
|
|
|
|
category = isPkgInstalled(pkg)
|
|
|
|
|
if category:
|
|
|
|
|
- category = category[0].rpartition('/')[2]
|
|
|
|
|
pkgContents = PkgContents("{CATEGORY}/{PF}".format(
|
|
|
|
|
- **isPkgInstalled("%s/%s"%(category,pkg))[0]))
|
|
|
|
|
+ **category[0]))
|
|
|
|
|
for filename in pkgContents.content.keys():
|
|
|
|
|
if not filename in self.cltObj.filterApplyTemplates:
|
|
|
|
|
self.cltObj.filterApplyTemplates[filename] = []
|
|
|
|
|
@@ -4281,6 +4414,11 @@ gettext -d cl_template "$*"
|
|
|
|
|
self.getApplyHeadDir(newDir, dirInfoFile, opt)
|
|
|
|
|
if createdDirs:
|
|
|
|
|
self.createdDirs += createdDirs
|
|
|
|
|
+ if os.path.isfile(pathDir):
|
|
|
|
|
+ self.setWarning(_("{dirpath} is file").format(dirpath=pathDir))
|
|
|
|
|
+ self.setWarning(_("templates in {tempath} is skipped"
|
|
|
|
|
+ ).format(tempath=path))
|
|
|
|
|
+ return None
|
|
|
|
|
if objHeadDir:
|
|
|
|
|
return pathDir, objHeadDir
|
|
|
|
|
else:
|
|
|
|
|
@@ -4392,11 +4530,11 @@ gettext -d cl_template "$*"
|
|
|
|
|
# add packeges for reconfigure
|
|
|
|
|
if "merge" in objHead.params:
|
|
|
|
|
mergePkgs = objHead.params['merge'].split(',')
|
|
|
|
|
- reRight = re.compile(r'^(\w+-\w+/)?[\w+-]+$')
|
|
|
|
|
- for wrongPkg in (x for x in mergePkgs if not reRight.match(x)):
|
|
|
|
|
- self.setError(_("Wrong value '%s' for 'merge' in the template")%
|
|
|
|
|
+ for wrongPkg in (x for x in mergePkgs \
|
|
|
|
|
+ if not self.functObj.checkCorrectPkgName(x)):
|
|
|
|
|
+ self.printWARNING(
|
|
|
|
|
+ _("Wrong package '%s' for 'merge' in the template")%
|
|
|
|
|
wrongPkg + ": " + nameFileTemplate)
|
|
|
|
|
- return ([], False)
|
|
|
|
|
for pkg in mergePkgs:
|
|
|
|
|
if not pkg in self.objVar.Get('cl_merge_pkg_new') and \
|
|
|
|
|
not pkg in self.objVar.Get('cl_merge_pkg_pass'):
|
|
|
|
|
@@ -4668,7 +4806,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
self.closeTemplFile()
|
|
|
|
|
objHeadNew = fileHeader(nameFileTemplate, self.textTemplate, False,
|
|
|
|
|
templateFileType ,objVar=self.objVar,
|
|
|
|
|
- function=function)
|
|
|
|
|
+ function=function,templateObj=self)
|
|
|
|
|
# файл шаблона не будет применен
|
|
|
|
|
if not objHeadNew.headerTerm:
|
|
|
|
|
if objHeadNew.getError():
|
|
|
|
|
@@ -4679,11 +4817,11 @@ gettext -d cl_template "$*"
|
|
|
|
|
# add packeges for reconfigure
|
|
|
|
|
if "merge" in objHeadNew.params:
|
|
|
|
|
mergePkgs = objHeadNew.params['merge'].split(',')
|
|
|
|
|
- reRight = re.compile(r'^(\w+-\w+/)?[\w+-]+$')
|
|
|
|
|
- for wrongPkg in (x for x in mergePkgs if not reRight.match(x)):
|
|
|
|
|
- self.setError(_("Wrong value '%s' for 'merge' in the template")%
|
|
|
|
|
+ for wrongPkg in (x for x in mergePkgs \
|
|
|
|
|
+ if not self.functObj.checkCorrectPkgName(x)):
|
|
|
|
|
+ self.printWARNING(
|
|
|
|
|
+ _("Wrong package '%s' for 'merge' in the template")%
|
|
|
|
|
wrongPkg + ": " + nameFileTemplate)
|
|
|
|
|
- return ([], False)
|
|
|
|
|
for pkg in mergePkgs:
|
|
|
|
|
if not pkg in self.objVar.Get('cl_merge_pkg_new') and \
|
|
|
|
|
not pkg in self.objVar.Get('cl_merge_pkg_pass'):
|
|
|
|
|
@@ -5052,7 +5190,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
|
|
|
|
|
def fileIsUtf(self, fileName):
|
|
|
|
|
"""Проверяет файл на кодировку UTF-8"""
|
|
|
|
|
- if os.path.exists(fileName):
|
|
|
|
|
+ if os.path.isfile(fileName):
|
|
|
|
|
FD = open(os.path.abspath(fileName))
|
|
|
|
|
newTemplate = FD.read()
|
|
|
|
|
FD.close()
|
|
|
|
|
@@ -5060,7 +5198,8 @@ gettext -d cl_template "$*"
|
|
|
|
|
newTemplate.decode("UTF-8")
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
- return True
|
|
|
|
|
+ return True
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
|
|
def joinTemplate(self, nameFileTemplate, nameFileConfig, optFile={}):
|
|
|
|
|
"""Объединения шаблона и конф. файла
|
|
|
|
|
@@ -5092,15 +5231,9 @@ gettext -d cl_template "$*"
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
if templateFileType != "bin":
|
|
|
|
|
- # Вычисляем условные блоки
|
|
|
|
|
- self.textTemplate = self.applyTermsTemplate(self.textTemplate,
|
|
|
|
|
- nameFileTemplate)
|
|
|
|
|
# Заменяем переменные на их значения
|
|
|
|
|
self.textTemplate = self.applyVarsTemplate(self.textTemplate,
|
|
|
|
|
nameFileTemplate)
|
|
|
|
|
- # Вычисляем функции
|
|
|
|
|
- self.textTemplate = self.applyFuncTemplate(self.textTemplate,
|
|
|
|
|
- nameFileTemplate)
|
|
|
|
|
flagCopyTemplate = False
|
|
|
|
|
if not optFile:
|
|
|
|
|
optFile = {"path":os.path.split(nameFileConfig)[0]}
|
|
|
|
|
@@ -5110,6 +5243,13 @@ gettext -d cl_template "$*"
|
|
|
|
|
optFile)
|
|
|
|
|
if not objHeadNew:
|
|
|
|
|
return filesApply
|
|
|
|
|
+ if templateFileType != "bin":
|
|
|
|
|
+ # Вычисляем условные блоки
|
|
|
|
|
+ objHeadNew.body = self.applyTermsTemplate(objHeadNew.body,
|
|
|
|
|
+ nameFileTemplate)
|
|
|
|
|
+ # Вычисляем функции
|
|
|
|
|
+ objHeadNew.body = self.applyFuncTemplate(objHeadNew.body,
|
|
|
|
|
+ nameFileTemplate)
|
|
|
|
|
# Настоящее имя конфигурационного файла
|
|
|
|
|
nameFileConfig = filesApply[0]
|
|
|
|
|
# Флаг - кодировка с бинарными примесями у файла шаблона включаем при
|
|
|
|
|
diff --git calculate/lib/datavars.py calculate/lib/datavars.py
|
|
|
|
|
index 02b1d4a..1791281 100644
|
|
|
|
|
--- calculate/lib/datavars.py
|
|
|
|
|
+++ calculate/lib/datavars.py
|
|
|
|
|
@@ -33,9 +33,9 @@ from types import StringTypes
|
|
|
|
|
|
|
|
|
|
def addStdConfig(fileLst,prefix='/'):
|
|
|
|
|
stdPath = path.join(prefix,
|
|
|
|
|
- "/var/lib/layman/calculate/profiles/calculate.env")
|
|
|
|
|
+ "var/lib/layman/calculate/profiles/calculate.env")
|
|
|
|
|
if not stdPath in map(os.path.abspath,fileLst):
|
|
|
|
|
- return fileLst + [stdPath]
|
|
|
|
|
+ return [stdPath] + fileLst
|
|
|
|
|
return fileLst
|
|
|
|
|
|
|
|
|
|
def itemgetter(*args,**kwargs):
|
|
|
|
|
@@ -757,9 +757,10 @@ class SimpleDataVars:
|
|
|
|
|
searchProfile(iniFile,'calculate.env'),prefix=self.systemRoot),""))
|
|
|
|
|
else:
|
|
|
|
|
config = cl_template.iniParser(iniFile)
|
|
|
|
|
+ importVars = config.getAreaVars("main")
|
|
|
|
|
for varname in self.allVars.keys():
|
|
|
|
|
if not varname in self.cache:
|
|
|
|
|
- val = self.unserialize("string",config.getVar('main',varname))
|
|
|
|
|
+ val = self.unserialize("string",importVars.get(varname,''))
|
|
|
|
|
if val:
|
|
|
|
|
self.cache[varname] = val.encode('utf-8')
|
|
|
|
|
|
|
|
|
|
diff --git calculate/lib/format/world.py calculate/lib/format/world.py
|
|
|
|
|
index 69bfc4f..7d93488 100644
|
|
|
|
|
--- calculate/lib/format/world.py
|
|
|
|
|
+++ calculate/lib/format/world.py
|
|
|
|
|
@@ -22,7 +22,7 @@ class world(objShare):
|
|
|
|
|
"""Класс для обработки конфигурационного файла типа procmail
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
- _comment = ""
|
|
|
|
|
+ _comment = "#"
|
|
|
|
|
configName = "world"
|
|
|
|
|
configVersion = "0.1"
|
|
|
|
|
sepFields = "\n"
|
|
|
|
|
@@ -66,15 +66,15 @@ class world(objShare):
|
|
|
|
|
for k in txtLines:
|
|
|
|
|
textLine = k + endtxtLines[z]
|
|
|
|
|
z += 1
|
|
|
|
|
- #findComment = self.reComment.search(textLine)
|
|
|
|
|
+ findComment = self.reComment.search(textLine)
|
|
|
|
|
if not textLine.strip():
|
|
|
|
|
field.br = textLine
|
|
|
|
|
fields.append(field)
|
|
|
|
|
field = fieldData()
|
|
|
|
|
- #elif findComment:
|
|
|
|
|
- # field.comment = textLine
|
|
|
|
|
- # fields.append(field)
|
|
|
|
|
- # field = fieldData()
|
|
|
|
|
+ elif findComment:
|
|
|
|
|
+ field.comment = textLine
|
|
|
|
|
+ fields.append(field)
|
|
|
|
|
+ field = fieldData()
|
|
|
|
|
else:
|
|
|
|
|
pars = textLine.strip()
|
|
|
|
|
field.name = pars
|
|
|
|
|
diff --git calculate/lib/variables/env.py calculate/lib/variables/env.py
|
|
|
|
|
index 44da0c3..8da1f30 100644
|
|
|
|
|
--- calculate/lib/variables/env.py
|
|
|
|
|
+++ calculate/lib/variables/env.py
|
|
|
|
|
@@ -252,3 +252,62 @@ class VariableClEbuildPhase(ReadonlyVariable):
|
|
|
|
|
"""
|
|
|
|
|
def get(self):
|
|
|
|
|
return os.environ.get("EBUILD_PHASE","")
|
|
|
|
|
+
|
|
|
|
|
+class VariableClEmergeInfo(ReadonlyVariable):
|
|
|
|
|
+ """
|
|
|
|
|
+ Emerge --info cache
|
|
|
|
|
+ """
|
|
|
|
|
+ type = "list"
|
|
|
|
|
+
|
|
|
|
|
+ def get(self):
|
|
|
|
|
+ return filter(lambda x:x.startswith('PORTDIR_OVERLAY=') or \
|
|
|
|
|
+ x.startswith('PORTDIR='),
|
|
|
|
|
+ process("emerge","--info",envdict=os.environ).read().split('\n'))
|
|
|
|
|
+
|
|
|
|
|
+class VariableClPortdirOverlay(ReadonlyVariable):
|
|
|
|
|
+ """
|
|
|
|
|
+ Overlays path
|
|
|
|
|
+ """
|
|
|
|
|
+ type = "list"
|
|
|
|
|
+
|
|
|
|
|
+ def get(self):
|
|
|
|
|
+ emergeInfo = self.Get('cl_emerge_info')
|
|
|
|
|
+ for line in filter(lambda x:x.startswith("PORTDIR_OVERLAY="),
|
|
|
|
|
+ emergeInfo):
|
|
|
|
|
+ return filter(None,
|
|
|
|
|
+ line.partition("=")[2].strip('\n"\'').split(' '))
|
|
|
|
|
+ return []
|
|
|
|
|
+
|
|
|
|
|
+class VariableClTemplatesLocate(Variable):
|
|
|
|
|
+ """
|
|
|
|
|
+ Location templates
|
|
|
|
|
+ """
|
|
|
|
|
+ type = "choice-list"
|
|
|
|
|
+ #value = ['overlay','local','remote','clt']
|
|
|
|
|
+ element = "selecttable"
|
|
|
|
|
+ opt = ["-l","--locate"]
|
|
|
|
|
+ metavalue = "TEMPLATES"
|
|
|
|
|
+ untrusted = True
|
|
|
|
|
+
|
|
|
|
|
+ descriptionMap = {'overlay':_('Overlay templates'),
|
|
|
|
|
+ 'local':_('Local templates'),
|
|
|
|
|
+ 'remote':_('Remote templates'),
|
|
|
|
|
+ 'clt':_('clt templates')}
|
|
|
|
|
+
|
|
|
|
|
+ def init(self):
|
|
|
|
|
+ self.label = _("Location templates")
|
|
|
|
|
+ self.help = _("select location for templates %s") \
|
|
|
|
|
+ %",".join(self.get())
|
|
|
|
|
+
|
|
|
|
|
+ def get(self):
|
|
|
|
|
+ vals = \
|
|
|
|
|
+ self.Get('cl_template_location')[:len(self.Get('cl_template_path'))]
|
|
|
|
|
+ if self.Get('cl_action') == 'desktop':
|
|
|
|
|
+ return vals
|
|
|
|
|
+ else:
|
|
|
|
|
+ return vals + ['clt']
|
|
|
|
|
+
|
|
|
|
|
+ def choice(self):
|
|
|
|
|
+ return map(lambda x:(x,self.descriptionMap.get(x,x)),
|
|
|
|
|
+ self.get())
|
|
|
|
|
+
|
|
|
|
|
diff --git calculate/lib/variables/linux.py calculate/lib/variables/linux.py
|
|
|
|
|
index be3bbb2..e3e6bdd 100644
|
|
|
|
|
--- calculate/lib/variables/linux.py
|
|
|
|
|
+++ calculate/lib/variables/linux.py
|
|
|
|
|
@@ -240,8 +240,9 @@ class LinuxDataVars(SimpleDataVars):
|
|
|
|
|
VariableOsLinuxBuild(systemRoot=systemRoot))
|
|
|
|
|
makeprofile = path.join(systemRoot,'etc/make.profile')
|
|
|
|
|
if os.path.exists(makeprofile):
|
|
|
|
|
- inifile = path.join('/etc',os.readlink('/etc/make.profile'))
|
|
|
|
|
- self.flIniFileFrom(makeprofile)
|
|
|
|
|
+ inifile = path.join(systemRoot,'etc',
|
|
|
|
|
+ os.readlink(path.join(systemRoot,'etc/make.profile')))
|
|
|
|
|
+ self.flIniFileFrom(inifile)
|
|
|
|
|
inifile = "etc/calculate/calculate.env"
|
|
|
|
|
self.flIniFileFrom(path.join(systemRoot,inifile))
|
|
|
|
|
iniFile = "etc/calculate/calculate3.env"
|