|
|
|
@ -24,7 +24,6 @@ from calculate.lib.utils.portage import getInstalledAtom, RepositoryPath, \
|
|
|
|
|
from calculate.lib.cl_xml import xmlShare
|
|
|
|
|
from calculate.lib.utils.system import SystemPath, FUser, emerge_running
|
|
|
|
|
from functools import wraps
|
|
|
|
|
import types
|
|
|
|
|
import random
|
|
|
|
|
import string
|
|
|
|
|
import time
|
|
|
|
@ -345,7 +344,8 @@ class _shareTermsFunction(object):
|
|
|
|
|
# Символы допустимые в скобках функции шаблона
|
|
|
|
|
_reFunctionArgvInSquareBrackets = (
|
|
|
|
|
r"a-zA-Z0-9_:;%@<>=\!\|\{\}\^\$\?\(\)\[\]\-"
|
|
|
|
|
r"\n\+\,\*\/\.\'\"~\\\\ ")
|
|
|
|
|
r"\n\+\,\*\/\.\'\"~\\ ")
|
|
|
|
|
# r"\n\+\,\*\/\.\'\"~\\\\ ")
|
|
|
|
|
_reFunctionArgvText = r"[%s]" % _reFunctionArgvInSquareBrackets
|
|
|
|
|
# регулярное выражение для поиска функции в шаблоне
|
|
|
|
|
_reFunctionText = (r"([a-zA-Z0-9\_-]+)\(((?:#-|-#|%s)+|)\)" %
|
|
|
|
@ -1015,8 +1015,9 @@ class fileHeader(HParams, _terms):
|
|
|
|
|
textLines = self.body.splitlines()
|
|
|
|
|
if textLines:
|
|
|
|
|
textLine = textLines[0]
|
|
|
|
|
#py3 regex problems
|
|
|
|
|
rePar = re.compile(
|
|
|
|
|
r"\s*#\s*calculate\s+\\\\?|\s*#\s*calculate\\\\?$", re.I)
|
|
|
|
|
r"\s*#\s*calculate\s+\\?|\s*#\s*calculate\\?$", re.I)
|
|
|
|
|
reP = rePar.search(textLine)
|
|
|
|
|
if reP:
|
|
|
|
|
reLns = re.compile(r"\A([^\\\n]*\\\n)+[^\n]*\n*", re.M)
|
|
|
|
@ -1199,8 +1200,9 @@ class dirHeader(HParams, _terms):
|
|
|
|
|
flagErrorBody = False
|
|
|
|
|
if textLines:
|
|
|
|
|
textLine = textLines[0]
|
|
|
|
|
#py3 regex problems
|
|
|
|
|
rePar = re.compile(
|
|
|
|
|
r"\s*#\s*calculate\s+\\\\?|\s*#\s*calculate\\\\?$", re.I)
|
|
|
|
|
r"\s*#\s*calculate\s+\\?|\s*#\s*calculate\\?$", re.I)
|
|
|
|
|
reP = rePar.search(textLine)
|
|
|
|
|
if reP:
|
|
|
|
|
reLns = re.compile(r"\A([^\\\n]*\\\n)+[^\n]*\n*", re.M)
|
|
|
|
@ -1546,7 +1548,7 @@ class _file(_error):
|
|
|
|
|
try:
|
|
|
|
|
self.F_CONF.truncate(0)
|
|
|
|
|
self.F_CONF.seek(0)
|
|
|
|
|
self.F_CONF.write(str(self.textConfig, encoding="UTF-8"))
|
|
|
|
|
self.F_CONF.write(self.textConfig)
|
|
|
|
|
except IOError:
|
|
|
|
|
self.setError(_("unable to open the file:")
|
|
|
|
|
+ self.nameFileConfig)
|
|
|
|
@ -1854,7 +1856,7 @@ class TemplateFormat(_error):
|
|
|
|
|
return self.parent.objVar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FormatFactory(object):
|
|
|
|
|
class FormatFactory():
|
|
|
|
|
"""
|
|
|
|
|
Фабрика классов форматов шаблонов
|
|
|
|
|
"""
|
|
|
|
@ -1880,9 +1882,10 @@ class FormatFactory(object):
|
|
|
|
|
globals(), locals(),
|
|
|
|
|
[nameClassTemplate]),
|
|
|
|
|
nameClassTemplate)
|
|
|
|
|
except (ImportError, AttributeError):
|
|
|
|
|
except (ImportError, AttributeError) as e:
|
|
|
|
|
# Создаем объект из self.newObjProt с помощью
|
|
|
|
|
# метаклассов
|
|
|
|
|
|
|
|
|
|
if nameClassTemplate in self.newObjProt:
|
|
|
|
|
# Прототип класса
|
|
|
|
|
nameProt = self.newObjProt[nameClassTemplate]
|
|
|
|
@ -1895,7 +1898,7 @@ class FormatFactory(object):
|
|
|
|
|
globals(), locals(),
|
|
|
|
|
[nameProt]),
|
|
|
|
|
nameProt)
|
|
|
|
|
except (ImportError, AttributeError):
|
|
|
|
|
except (ImportError, AttributeError) as e:
|
|
|
|
|
return False
|
|
|
|
|
self.importFormats[nameProt] = classProt
|
|
|
|
|
classFormat = self.createNewClass(nameClassTemplate,
|
|
|
|
@ -2499,12 +2502,36 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
self.installProg[fullname][slot] = ver
|
|
|
|
|
return self.installProg
|
|
|
|
|
|
|
|
|
|
# os.path.walk is deprecated in py3
|
|
|
|
|
# def getInstallPkgGentoo(self, category=""):
|
|
|
|
|
# pkgs = []
|
|
|
|
|
# filterFunc = lambda x: "SLOT" == x
|
|
|
|
|
|
|
|
|
|
# def getFilesDir(pkgs, dirname, names):
|
|
|
|
|
# for nameFile in filter(filterFunc, names):
|
|
|
|
|
# absNameFile = os.path.join(dirname, nameFile)
|
|
|
|
|
# category, spl, pkgname = dirname.rpartition('/')
|
|
|
|
|
# dbpkg, spl, category = category.rpartition('/')
|
|
|
|
|
# slot = readFile(absNameFile).strip().partition('/')[0]
|
|
|
|
|
# pkgname, spl, rev = pkgname.rpartition("-")
|
|
|
|
|
# if rev.startswith('r'):
|
|
|
|
|
# pkgname, spl, ver = pkgname.rpartition("-")
|
|
|
|
|
# ver = "%s-%s" % (ver, rev)
|
|
|
|
|
# else:
|
|
|
|
|
# ver = rev
|
|
|
|
|
# pkgs.append((pkgname, category, ver, slot))
|
|
|
|
|
# return True
|
|
|
|
|
|
|
|
|
|
# os.path.walk(os.path.join(self.basePkgDir, category),
|
|
|
|
|
# getFilesDir, pkgs)
|
|
|
|
|
|
|
|
|
|
# return self.sharePkg(pkgs)
|
|
|
|
|
|
|
|
|
|
def getInstallPkgGentoo(self, category=""):
|
|
|
|
|
pkgs = []
|
|
|
|
|
filterFunc = lambda x: "SLOT" == x
|
|
|
|
|
|
|
|
|
|
def getFilesDir(pkgs, dirname, names):
|
|
|
|
|
for nameFile in filter(filterFunc, names):
|
|
|
|
|
for dirname, dirs, files in os.walk(os.path.join(self.basePkgDir, category)):
|
|
|
|
|
for nameFile in filter(filterFunc, files+dirs):
|
|
|
|
|
absNameFile = os.path.join(dirname, nameFile)
|
|
|
|
|
category, spl, pkgname = dirname.rpartition('/')
|
|
|
|
|
dbpkg, spl, category = category.rpartition('/')
|
|
|
|
@ -2516,15 +2543,12 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
else:
|
|
|
|
|
ver = rev
|
|
|
|
|
pkgs.append((pkgname, category, ver, slot))
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
os.path.walk(os.path.join(self.basePkgDir, category),
|
|
|
|
|
getFilesDir, pkgs)
|
|
|
|
|
return self.sharePkg(pkgs)
|
|
|
|
|
|
|
|
|
|
def pkg(self, nameProg, slot=None):
|
|
|
|
|
if len(self.installProg) > 0:
|
|
|
|
|
if type(self.installProg.values()[0]) != dict:
|
|
|
|
|
if type(list(self.installProg.values())[0]) != dict:
|
|
|
|
|
self.installProg.clear()
|
|
|
|
|
self.getInstallPkgGentoo()
|
|
|
|
|
if nameProg in self.installProg:
|
|
|
|
@ -2532,7 +2556,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
if slot:
|
|
|
|
|
return versions.get(slot, "")
|
|
|
|
|
if len(versions) == 1:
|
|
|
|
|
return versions.values()[0]
|
|
|
|
|
return list(versions.values())[0]
|
|
|
|
|
else:
|
|
|
|
|
return versions[max(versions.keys(), key=getTupleVersion)]
|
|
|
|
|
else:
|
|
|
|
@ -3137,7 +3161,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
nameLocVar = "main.%s" % nameLocVar
|
|
|
|
|
elif len(namesVar) > 2:
|
|
|
|
|
raise self.raiseErrTemplate()
|
|
|
|
|
replace = ""
|
|
|
|
|
replace = b""
|
|
|
|
|
# Получаем время модификации конфигурационного файла
|
|
|
|
|
curTime = self.getTimeFile(self.fileConfigIni)
|
|
|
|
|
if 1 <= len(terms) <= 3:
|
|
|
|
@ -3173,6 +3197,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
if terms[1]:
|
|
|
|
|
raise self.raiseErrTemplate()
|
|
|
|
|
if value:
|
|
|
|
|
#awww yesss, legacy stuff
|
|
|
|
|
if terms[2] in ('url', 'purl'):
|
|
|
|
|
replace = (value.encode("UTF-8").__repr__()[1:-1].replace(
|
|
|
|
|
'\\x', '%').replace(' ', '%20'))
|
|
|
|
@ -3182,6 +3207,13 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
|
|
|
|
|
replace = value.__repr__()[2:-1]
|
|
|
|
|
elif terms[2] == 'hexcode':
|
|
|
|
|
replace = value.__repr__()[2:-1].replace('\\u0','\\x')
|
|
|
|
|
|
|
|
|
|
replace = replace.decode("UTF-8")
|
|
|
|
|
print("DEBUG funcIni")
|
|
|
|
|
print(textTemplateTmp)
|
|
|
|
|
print(type(textTemplateTmp))
|
|
|
|
|
print(replace)
|
|
|
|
|
print(type(replace))
|
|
|
|
|
textTemplateTmp = textTemplateTmp[:resS.start()] + replace + \
|
|
|
|
|
textTemplateTmp[resS.end():]
|
|
|
|
|
return textTemplateTmp
|
|
|
|
@ -4025,7 +4057,8 @@ gettext -d cl_template "$*"
|
|
|
|
|
"""Преобразование восьмеричного в целое (ввод строка, вывод число)"""
|
|
|
|
|
if strOct:
|
|
|
|
|
try:
|
|
|
|
|
res = string.atoi(strOct, 8)
|
|
|
|
|
# res = string.atoi(strOct, 8)
|
|
|
|
|
res = int(strOct, 8)
|
|
|
|
|
except ValueError:
|
|
|
|
|
self.setError(_("Invalid oct value: ") + str(strOct))
|
|
|
|
|
return False
|
|
|
|
@ -4285,10 +4318,10 @@ gettext -d cl_template "$*"
|
|
|
|
|
if textLines:
|
|
|
|
|
textLine = textLines[0]
|
|
|
|
|
rePar = re.compile(
|
|
|
|
|
r"\s*#\s*calculate\s+\\\\?|\s*#\s*calculate\\\\?$", re.I)
|
|
|
|
|
r"\s*#\s*calculate\s+\\?|\s*#\s*calculate\\?$", re.I)
|
|
|
|
|
reP = rePar.search(textLine)
|
|
|
|
|
if reP:
|
|
|
|
|
reLns = re.compile(r"\A([^\\\n]*\\\n)+[^\n]*\n*", re.M)
|
|
|
|
|
reLns = re.compile(r"\A([^\n]*\n)+[^\n]*\n*", re.M)
|
|
|
|
|
reLs = reLns.search(text)
|
|
|
|
|
if reLs:
|
|
|
|
|
paramLine = text[reP.end():reLs.end()]
|
|
|
|
@ -4302,13 +4335,19 @@ gettext -d cl_template "$*"
|
|
|
|
|
skipDirs = []
|
|
|
|
|
skipTemplates = []
|
|
|
|
|
debug = False
|
|
|
|
|
print("DEBUG getTemplateDirs")
|
|
|
|
|
print("dirsTemplates: ", dirsTemplates)
|
|
|
|
|
for dirsTemplate in dirsTemplates:
|
|
|
|
|
filesAndDirs = [os.path.join(dirsTemplate, x) for x in listDirectory(dirsTemplate)]
|
|
|
|
|
print("filesAndDirs: ",filesAndDirs)
|
|
|
|
|
for dirFile in filesAndDirs:
|
|
|
|
|
print("dirFile: ", dirFile)
|
|
|
|
|
if os.path.isdir(dirFile):
|
|
|
|
|
flagDir = True
|
|
|
|
|
templatePath = os.path.join(dirFile, self.templDirNameFile)
|
|
|
|
|
print("templatePath: ", templatePath)
|
|
|
|
|
if not os.path.isfile(templatePath):
|
|
|
|
|
print("Not a file for some reason")
|
|
|
|
|
skipDirs.append(dirFile)
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
@ -4316,12 +4355,15 @@ gettext -d cl_template "$*"
|
|
|
|
|
templatePath = dirFile
|
|
|
|
|
if os.path.isfile(templatePath):
|
|
|
|
|
if self.getFileType(templatePath) == "bin":
|
|
|
|
|
print("is a bin file: ", templatePath)
|
|
|
|
|
skipTemplates.append(dirFile)
|
|
|
|
|
else:
|
|
|
|
|
with open(templatePath) as f:
|
|
|
|
|
textTemplate = f.read()
|
|
|
|
|
print("textTemplate: ", textTemplate)
|
|
|
|
|
if textTemplate:
|
|
|
|
|
headerLine = self.getHeaderText(textTemplate)
|
|
|
|
|
print("headerLine: ", headerLine)
|
|
|
|
|
if headerLine:
|
|
|
|
|
if not debug and \
|
|
|
|
|
not "cl_name==" in headerLine and \
|
|
|
|
@ -4644,7 +4686,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
prefix=chrootPath)
|
|
|
|
|
reverse_cfgs = {y[0][1]: x for x, y in cfgs.items()}
|
|
|
|
|
autoUpdateDict = {}
|
|
|
|
|
get_digest = lambda x: hashlib.md5(readFile(x)).hexdigest()
|
|
|
|
|
get_digest = lambda x: hashlib.md5(readFile(x).encode("UTF-8")).hexdigest()
|
|
|
|
|
for pkg in list(set(filter(None, list(self.changedFiles.getPkgs()) +
|
|
|
|
|
self.objVar.Get('cl_merge_pkg')))):
|
|
|
|
|
atom = list(sorted(getInstalledAtom(pkg, prefix=chrootPath)))
|
|
|
|
@ -4837,6 +4879,10 @@ gettext -d cl_template "$*"
|
|
|
|
|
# Записываем в переменную обрабатываемый файл
|
|
|
|
|
self.objVar.Set("cl_pass_file", os.path.basename(nameFileConfig))
|
|
|
|
|
self.headerParams = None
|
|
|
|
|
print("DEBUG processing File")
|
|
|
|
|
print("path: ",path)
|
|
|
|
|
print("nameFileConfig: ", nameFileConfig)
|
|
|
|
|
print("optFile: ", optFile)
|
|
|
|
|
filesApl = self.joinTemplate(path, nameFileConfig, optFile)
|
|
|
|
|
if self.headerParams:
|
|
|
|
|
if has_any(self.headerParams, HParams.ServiceControl):
|
|
|
|
@ -6074,7 +6120,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
if ListOptTitle:
|
|
|
|
|
title = self.getTitle(objHeadNew.comment, ListOptTitle,
|
|
|
|
|
configPath=nameFileConfig)
|
|
|
|
|
title = title.encode("UTF-8")
|
|
|
|
|
# title = title.encode("UTF-8")
|
|
|
|
|
|
|
|
|
|
objHeadOld = False
|
|
|
|
|
if objHeadNew.comment:
|
|
|
|
@ -6249,7 +6295,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
if 'postXML' in dir(objTemplNew):
|
|
|
|
|
objTemplNew.postXML()
|
|
|
|
|
# Получение текстового файла из XML документа
|
|
|
|
|
self.textTemplate = objTemplNew.getConfig().encode("UTF-8")
|
|
|
|
|
self.textTemplate = objTemplNew.getConfig()
|
|
|
|
|
# Если не UTF-8 производим преобразование
|
|
|
|
|
if objTxtCoder:
|
|
|
|
|
self.textTemplate = objTxtCoder.decode(self.textTemplate)
|
|
|
|
@ -6258,7 +6304,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
title = self.getTitle(objTemplNew._comment,
|
|
|
|
|
ListOptTitle,
|
|
|
|
|
configPath=nameFileConfig)
|
|
|
|
|
title = title.encode("UTF-8")
|
|
|
|
|
# title = title.encode("UTF-8")
|
|
|
|
|
# Замена
|
|
|
|
|
if typeAppendTemplate == HParams.AppendParams.Replace:
|
|
|
|
|
if "xml_" in formatTemplate:
|
|
|
|
@ -6379,7 +6425,7 @@ gettext -d cl_template "$*"
|
|
|
|
|
title = self.getTitle(objTemplNew._comment,
|
|
|
|
|
ListOptTitle,
|
|
|
|
|
configPath=nameFileConfig)
|
|
|
|
|
title = title.encode("UTF-8")
|
|
|
|
|
# title = title.encode("UTF-8")
|
|
|
|
|
|
|
|
|
|
# В случае пустого конфигурационного файла
|
|
|
|
|
reNoClean = re.compile(r"[^\s]", re.M)
|
|
|
|
@ -6425,12 +6471,12 @@ gettext -d cl_template "$*"
|
|
|
|
|
self.setError(_("Wrong template") + _(": ") + \
|
|
|
|
|
nameFileTemplate)
|
|
|
|
|
return None
|
|
|
|
|
data = objTemplOld.getConfig().encode("UTF-8").split("\n")
|
|
|
|
|
data = objTemplOld.getConfig().split("\n")
|
|
|
|
|
data.insert(1, title)
|
|
|
|
|
self.textConfig = "\n".join(data)
|
|
|
|
|
else:
|
|
|
|
|
self.textConfig = self.add_comment(
|
|
|
|
|
execStr, title, objTemplOld.getConfig().encode("UTF-8"))
|
|
|
|
|
execStr, title, objTemplOld.getConfig())
|
|
|
|
|
# Декодируем если кодировка не UTF-8
|
|
|
|
|
if objTxtCoder:
|
|
|
|
|
self.textTemplate = objTxtCoder.decode(self.textTemplate)
|
|
|
|
@ -6465,7 +6511,11 @@ gettext -d cl_template "$*"
|
|
|
|
|
:param body:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
if comment.startswith(b"<!--") and body.startswith(b'<?xml'):
|
|
|
|
|
print("DEBUG add comment")
|
|
|
|
|
print(execStr)
|
|
|
|
|
print(comment)
|
|
|
|
|
print(body)
|
|
|
|
|
if comment.startswith("<!--") and body.startswith('<?xml'):
|
|
|
|
|
header, body = body.partition("\n")[::2]
|
|
|
|
|
body = header + "\n" + comment + body
|
|
|
|
|
else:
|
|
|
|
|