fixed py3 related bugs

master
idziubenko 3 years ago
parent ebf1afe9cf
commit 50387fe5b0

@ -191,7 +191,7 @@ class iniParser(_error):
# объединяем объекты для получения результирующего текста
objIni.join(objIniAdd)
# получаем текст
txtConfig = objIni.getConfig().encode("UTF-8")
txtConfig = objIni.getConfig()
# записываем его в ini файл
if not self.writeIniFile(txtConfig):
return False
@ -222,9 +222,12 @@ class iniParser(_error):
# В файле есть данные
if not self.isEmptyFile(textIni):
try:
objIni = self.formatFactory.getClassObj(
"plasma")(textIni, self)
except Exception:
tmp = self.formatFactory.getClassObj(
"plasma")
# objIni = self.formatFactory.getClassObj(
# "plasma")(textIni, self)
objIni = tmp(textIni, self)
except Exception as e:
self.setError(_("Incorrect file format") + _(": ") + \
self.iniFile)
self.checkIni = False

@ -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:

@ -22,9 +22,8 @@ from copy import deepcopy
# def appendChild(*args, **kwargs):
# ET._Element.append(*args, **kwargs)
# def display(xml):
# print(str(ET.tostring(xml, pretty_print=True), encoding="UTF-8"))
# ET._Element.appendChild = appendChild
def display_xml(xml):
print(str(ET.tostring(xml, pretty_print=True), encoding="UTF-8"))
#backwards compat
@ -769,10 +768,6 @@ class xmlDoc(object):
newAreaAction = None
baseNodes = []
for oName in nodesNames:
# print("DEBUG in for oName")
# print(oName)
# display(oName)
# print(firstChild(oName))
newAreaAction = self.getActionArea(xmlNewArea)
oArea = oName.getparent().getparent()
oNameTxt = ""
@ -988,7 +983,7 @@ class xmlDoc(object):
else:
fieldName = False
xmlFieldNameNodes = xpath.Evaluate('child::name', node)
if xmlFieldNameNodes and firstChild(xmlFieldNameNodes[0]):
if xmlFieldNameNodes and firstChild(xmlFieldNameNodes[0]) is not None:
fieldName = firstChild(xmlFieldNameNodes[0]).text
if fieldName:
if fieldName in fieldsSeplist:

@ -706,7 +706,7 @@ class TableVariable(Variable):
def get(self, hr=HumanReadable.No):
"""Get table data"""
for varname, value in (x for x in ((y, self.Get(y)) for y in self.source) if type(x[1]) != list):
for varname, value in (x for x in ((y, self.Get(y)) for y in self.source) if not isinstance(x[1], list)):
raise VariableError(
_("Source variable %s does not contain a list") % varname)
return [list(x) for x in zip_longest(*[self.Get(x, humanreadable=hr)
@ -743,11 +743,9 @@ class TableVariable(Variable):
if not any(value):
value = [[]] * len(writeCols)
else:
value = zip(*map(itemgetter(*map(itemgetter(0),
writeCols), alwaysTuple=True),
value))
for colInfo, values in \
zip(writeCols, value):
value = list(zip(*map(itemgetter(*map(itemgetter(0),
writeCols), alwaysTuple=True),value)))
for colInfo, values in zip(writeCols, value):
try:
self.parent.Check(colInfo[1], values)
except VariableError as e:
@ -829,16 +827,17 @@ class TableVariable(Variable):
error = []
if self.__isIndexWritable():
if not force and any(value):
self.parent.Check(self.source[0], zip(*value)[0])
self.parent.Check(self.source[0], list(zip(*value))[0])
oldvalue = newval
try:
self.parent.Set(self.source[0], oldvalue.keys())
#py3 keys() now returns its own type instead of a list
self.parent.Set(self.source[0], list(oldvalue.keys()))
except VariableError as e:
error.append(e)
# update entry by index field
else:
oldvalue.update(newval)
oldvalValues = zip(*oldvalue.values())
oldvalValues = list(zip(*oldvalue.values()))
for col, vals in zip((x[1] for x in writeCols),
oldvalValues):
try:
@ -1433,15 +1432,10 @@ class DataVars(SimpleDataVars):
def Get(self, varname, humanreadable=HumanReadable.No):
"""Threading safety Get"""
# if varname in ["install.os_lvm_data"]:
# print("DEBUG datavars Get")
DataVars.l.acquire()
try:
var = self.__Get(varname, humanreadable)
# if varname in ["install.os_lvm_data"]:
# print("DEBUG AFTER")
finally:
DataVars.l.release()
@ -1667,6 +1661,8 @@ class DataVars(SimpleDataVars):
val = self.serialize(self.getInfo(varname).type,
val)
writeVal = convertStrListDict(val)
print("DEBUG WRITE")
print(writeVal)
if writeVal != config.getVar(header, varname):
if not config.setVar(header, {varname: writeVal}):
raise DataVarsError(
@ -1849,7 +1845,7 @@ class DataVars(SimpleDataVars):
for col, typecol in multiLists:
if col < len(val):
val[col] = [x.split(',')
if type(x) in (str) else x for x
if isinstance(x, str) else x for x
in val[col]]
val = list(zip_longest(*val, fillvalue=""))
return val
@ -1911,7 +1907,7 @@ class DataVars(SimpleDataVars):
return []
errors = []
if self.groups:
keys = self.mapVarGroup.keys()
keys = list(self.mapVarGroup.keys())
else:
keys = sorted((x for x in info._type_info.keys() if x.lower() == x))
varsByKeys = [self.getInfo(x) for x in keys]
@ -1976,7 +1972,7 @@ class DataVars(SimpleDataVars):
if choicedata[1] is None:
choicedata = [choicedata[0],
choicedata[0]]
choicedata = zip(*choicedata)
choicedata = list(zip(*choicedata))
if varObj.type == "choice":
vals = [val]
else:
@ -1997,7 +1993,7 @@ class DataVars(SimpleDataVars):
# assemble all variable errors
messages = e if type(e) == list \
else [e]
mess = "\n".join((str(x) for x in self.plainList(*messages)))
mess = "\n".join((str(x) for x in messages))
mapError = {PasswordError: 'pwderror',
CommonVariableError: 'commonerror'}
for k, v in mapError.items():

@ -79,7 +79,7 @@ class backgrounds(TemplateFormat):
data = readFile(source)
else:
data = ""
return hashlib.md5(data+"\n".join(resolutions)).hexdigest()
return hashlib.md5(data+"\n".join(resolutions).encode("UTF-8")).hexdigest()
def setStretch(self, stretch):
self.stretch = stretch

@ -15,7 +15,7 @@
# limitations under the License.
import re
from generic import objShare
from .generic import objShare
from calculate.lib.cl_template import blocText
from calculate.lib.cl_xml import xmlDoc

@ -15,7 +15,7 @@
# limitations under the License.
import re
from calculate.lib.format.samba import samba
from .samba import samba
class compiz(samba):

@ -15,7 +15,7 @@
# limitations under the License.
import re
from calculate.lib.format.bind import bind
from .bind import bind
class dhcp(bind):

@ -15,9 +15,8 @@
# limitations under the License.
import re
import types
import copy
from calculate.lib.cl_xml import xpath, xmlDoc, firstChild
from calculate.lib.cl_xml import xpath, xmlDoc, firstChild, insertBefore
from copy import deepcopy
from calculate.lib.cl_template import blocText
from calculate.lib.format.samba import samba
@ -102,10 +101,10 @@ class xmlDocPlasma(xmlDoc):
for areaNode in areaNodes:
self.setActionArea(areaNode, "append")
parentNode = areaNode.getparent()
parentNode.insertBefore(deepcopy(self.sepAreas), areaNode)
insertBefore(parentNode, deepcopy(self.sepAreas), areaNode)
baseNode.append(xmlNewArea)
# Добавляем разделитель областей
baseNode.insertBefore(deepcopy(self.sepAreas), xmlNewArea)
insertBefore(baseNode, deepcopy(self.sepAreas), xmlNewArea)
nodesNames = xpath.Evaluate('child::area/caption/name', baseNode)
nodesNewArea = xpath.Evaluate('child::caption/name', xmlNewArea)
@ -227,7 +226,7 @@ class plasma(samba):
if not listPath:
return ret
flagList = False
if type(areaF) == types.ListType:
if isinstance(areaF, list):
fields = areaF
flagList = True
else:
@ -572,19 +571,19 @@ class plasma(samba):
continue
if flagFoundArea and node.tag == "field":
if self.docObj.getTypeField(node) == "var":
xmlArea.insertBefore(node, firstChildArea)
insertBefore(xmlArea, node, firstChildArea)
if it < lenChild:
node_type = self.docObj.getTypeField(
childNodes[it])
if node_type == "br":
xmlArea.insertBefore(childNodes[it],
insertBefore(xmlArea, childNodes[it],
firstChildArea)
# Добавление перевода строк в если его нет между полями
if (self.docObj.getTypeField(node) == "var" and
node.getprevious() and
not (self.docObj.getTypeField(
node.getprevious()) in ("br", "comment"))):
xmlArea.insertBefore(self.docObj.createField(
insertBefore(xmlArea, self.docObj.createField(
"br", [], "", [], False, False), node)
# Добавляем BR если его нет первым полем
@ -594,7 +593,7 @@ class plasma(samba):
self.docObj.getTypeField(
xmlFields[0]) == "comment")):
if xmlFields:
xmlArea.insertBefore(self.docObj.createField("br",
insertBefore(xmlArea, self.docObj.createField("br",
[], "", [],
False, False),
xmlFields[0])
@ -606,7 +605,7 @@ class plasma(samba):
node.getprevious() and
not (self.docObj.getTypeField(
node.getprevious()) in ("br", "comment"))):
xmlArea.insertBefore(self.docObj.createField("br",
insertBefore(xmlArea, self.docObj.createField("br",
[], "", [],
False,
False),
@ -623,7 +622,7 @@ class plasma(samba):
self.docObj.getTypeField(
xmlArea.getprevious()) == "comment")):
parentNode = xmlArea.getparent()
parentNode.insertBefore(self.docObj.createField(
insertBefore(parentNode, self.docObj.createField(
"br", [], "", [], False, False), xmlArea)
# Если есть предыдущее поле, и поле предыдущеее предыдущему
# не равно BR или комментарий то добавляем BR
@ -635,7 +634,7 @@ class plasma(samba):
self.docObj.getTypeField(
prPrSibling) == "comment")):
parentNode = xmlArea.getparent()
parentNode.insertBefore(self.docObj.createField(
insertBefore(parentNode, self.docObj.createField(
"br", [], "", [], False, False), xmlArea)
# Если после есть BR а за ним ничего нет, удаляем BR
if (xmlArea.getnext() and

@ -15,8 +15,8 @@
# limitations under the License.
import re
from calculate.lib.cl_xml import xpath, xmlDoc
from generic import objShare
from calculate.lib.cl_xml import xpath, xmlDoc, insertBefore
from .generic import objShare
class procmail(objShare):
"""Класс для обработки конфигурационного файла типа procmail
@ -45,7 +45,7 @@ class procmail(objShare):
node.getprevious() is not None and
(self.docObj.getTypeField(node.getprevious()) not in
("br", "comment"))):
self.docObj.body.insertBefore(self.docObj.createField(
insertBefore(self.docObj.body, self.docObj.createField(
"br", [], "", [], False, False), node)
def setDataField(self, txtLines, endtxtLines):

@ -16,9 +16,9 @@
import re
from calculate.lib.cl_xml import xpath
from generic import objShare
from .generic import objShare
from calculate.lib.cl_template import blocText
from calculate.lib.cl_xml import xmlDoc
from calculate.lib.cl_xml import xmlDoc, insertBefore
class samba(objShare):
@ -67,7 +67,7 @@ class samba(objShare):
if xmlArea.getnext() is not None:
parentNode = xmlArea.getparent()
nextNode = xmlArea.getnext()
parentNode.insertBefore(self.docObj.createField(
insertBefore(parentNode, self.docObj.createField(
"br", [], "", [], False, False), nextNode)
# Добавление переводов строк между полями
if xmlFields:
@ -77,7 +77,7 @@ class samba(objShare):
node.getprevious() is not None and
not (self.docObj.getTypeField(
node.getprevious()) in ("br", "comment"))):
xmlArea.insertBefore(self.docObj.createField(
insertBefore(xmlArea, self.docObj.createField(
"br", [], "", [], False, False), node)
# Удаление лишних переводов строк

@ -330,8 +330,8 @@ class BinhostError(Exception):
class BinhostSignError(BinhostError):
pass
class Binhosts(BinhostsBase):
__metaclass__ = SingletonParam
class Binhosts(BinhostsBase, metaclass=SingletonParam):
pass
class PackagesIndex(MutableMapping):
def __init__(self, data):

@ -95,6 +95,16 @@ class ConsoleCodesConverter(BaseConverter):
self.end = end
def tryParse(self, code):
print("DEBUG tryparse")
print(self.begin)
print(code)
print(self.end)
try:
code = int(code)
except Exception as e:
print(e)
return False
print("after", code)
return self.begin <= code <= self.end
def parse(self, code, codes):
@ -107,14 +117,14 @@ class ConsoleCodesConverter(BaseConverter):
def __init__(self, output=BaseOutput(), escSymb="\033"):
super(ConsoleCodesConverter, self).__init__(output)
self.escSymb = escSymb
self.escBlock = (r"{esc}(?:\[(\d*(?:;\d+)*)(m)|"
r"\]\d+;.*?\x07|"
r"\([B0UK]|"
r"\[\d*[A-D])".format(esc=escSymb))
self.otherSymb = r"(?:\r*\n|\t)"
self.escBlock = ("{esc}(?:\[(\d*(?:;\d+)*)(m)|"
"\]\d+;.*?\x07|"
"\([B0UK]|"
"\[\d*[A-D])".format(esc=escSymb))
self.otherSymb = "(?:\r*\n|\t)"
self.reEscBlock = re.compile(self.escBlock)
self.reParse = re.compile(
r"(?:{0}|({1}))?(.*?)(?=$|{0}|{1})".format(self.escBlock,
"(?:{0}|({1}))?(.*?)(?=$|{0}|{1})".format(self.escBlock,
self.otherSymb),
re.DOTALL)
resetBoldHalfbright = lambda: (
@ -168,17 +178,27 @@ class ConsoleCodesConverter(BaseConverter):
"""
Запустить преобразование текста
"""
print("DEBUG transform")
print(s)
def generator():
for ctrl, m, other, txt, _s, _m in self.reParse.findall(s):
print("DEBUG generator")
print(ctrl)
print(m)
print(other)
print(txt)
print(_s)
print(_m)
if m:
codes = SavableIterator(ctrl.split(';'))
for code in codes:
code = int(code or '0')
res = self.evaluteGram(code, codes)
if res:
yield res
elif other:
print(other)
res = self.evaluteGram(other)
if res:
yield res

@ -24,8 +24,7 @@ import termios
from calculate.lib.utils.tools import Singleton, ignore
class Terminal(object):
__metaclass__ = Singleton
class Terminal(metaclass=Singleton):
WRONG = -1

@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from xml.etree import ElementTree as ET
# from xml.etree import ElementTree as ET
from lxml import etree as ET
from .palette import (TextState, BaseColorMapping,
ConsoleCodeMapping, LightColorMapping, ConsoleColor256,
ConsoleCodesInfo, SpanPalette, XmlFormat)
@ -528,7 +529,7 @@ class XmlOutput(SaveAttrOutput):
escaper = XmlFormat.escaper
def __init__(self, state=None):
super(XmlOutput, self).__init__(state=state)
super().__init__(state=state)
self.clear_state = TextState()
def getXML(self, curstate, text):
@ -561,7 +562,10 @@ class XmlOutput(SaveAttrOutput):
if curstate.bold:
tail = ET.SubElement(tail, Tags.BOLD)
tail.text = text
return root[0]
print("DEBUG xml output")
print (ET.tostring(root))
# return root[0]
return root
def xmlToString(self, xml):
"""

@ -24,7 +24,6 @@ from calculate.lib.utils.dracut import Dracut
from calculate.lib.utils.system import SystemPath
import sys
import getpass
# from types import StringType
import string
import glob
import pwd

@ -125,7 +125,7 @@ class PkgContents(ContentsFormat):
filename = self.reCfg.sub("/", filename)
self.content[filename] = {'type': 'obj',
'md5': hashlib.md5(
readFile(newfilename)).hexdigest(),
readFile(newfilename).encode("UTF-8")).hexdigest(),
'mtime': str(
int(os.stat(newfilename).st_mtime))}
@ -202,7 +202,7 @@ def checkReserved(fileName, contentFile):
# if file is not exists
if not path.exists(fileName):
return True
contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
contentMD5 = hashlib.md5(readFile(fileName).encode("UTF-8")).hexdigest().strip()
configMD5 = obj[0][MD5].strip()
# if content was not changed
if contentMD5 == configMD5:
@ -239,7 +239,7 @@ def checkContents(pkg, fileName, prefix='/', reservedFile=None):
return True
else:
return False
contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
contentMD5 = hashlib.md5(readFile(fileName).encode("UTF-8")).hexdigest().strip()
configMD5 = obj[0][MD5].strip()
# if content was not changed
if contentMD5 == configMD5:
@ -305,7 +305,7 @@ class FileOwners(object):
fn_info = self.file_owners[fn][0]
if not path.islink(fn):
if path.isfile(fn):
system_md5 = hashlib.md5(readFile(fn)).hexdigest().strip()
system_md5 = hashlib.md5(readFile(fn).encode("UTF-8")).hexdigest().strip()
if system_md5 != fn_info.get('md5', ''):
yield fn
else:

@ -298,20 +298,11 @@ class Udev(object):
"""Get device info by syspath of name"""
if name is not None:
cache = self.name_cache
# print("DEBUGG (name)")
# print(name)
value = devfs.realpath(name)
# print(value)
name = value
else:
# print("DEBUGG (cache)")
cache = self.path_cache
# print(cache)
# print(path)
value = sysfs.realpath(path)
# print(value)
path = value
if value not in cache:
@ -326,7 +317,6 @@ class Udev(object):
self.path_cache[devname] = data
return data
else:
# print "fromCache",keyCache
return cache[value]
def get_block_devices(self):

@ -151,10 +151,6 @@ class MountHelper(object):
return self.isReadonly(eq=dn)
def exists(self, dn):
# print("DEBUG exists")
# print(dn)
# print(self.isExists(eq=dn))
# print(self.isExists(what=self.NAME, eq=dn))
return self.isExists(eq=dn) or self.isExists(what=self.NAME, eq=dn)
def isExists(self, what=DIR, eq=None, noteq=None):
@ -166,9 +162,8 @@ class MountHelper(object):
return bool([x for x in self.cache if filterfunc(x)])
class FStab(MountHelper):
class FStab(MountHelper, metaclass=SingletonParam):
"""Data reader for fstab"""
__metaclass__ = SingletonParam
data_file = '/etc/fstab'

@ -31,15 +31,13 @@ def round_disk_size(size):
class VolumesError(Exception):
pass
class VolumesBuilder(object):
class VolumesBuilder(metaclass=ABCMeta):
__metaclass__ = ABCMeta
class DeviceType(object):
class DeviceType():
Device = 0
RAID = 1
class VolumeType(object):
class VolumeType():
Generic = 0
Raid = 2
Fat32 = 3
@ -51,7 +49,7 @@ class VolumesBuilder(object):
Lvm = 9
Extended = 10
class Purpose(object):
class Purpose():
Undefined = 100
EfiBoot = 101
BiosBoot = 102
@ -104,8 +102,7 @@ class VolumesBuilder(object):
pass
class DosDisk(object):
__metaclass__ = ABCMeta
class DosDisk(metaclass=ABCMeta):
@abstractmethod
def get_partition_name(self, num):
@ -136,8 +133,7 @@ class DosDisk(object):
pass
class GptDisk(object):
__metaclass__ = ABCMeta
class GptDisk(metaclass=ABCMeta):
@abstractmethod
def create_table(self):
@ -160,8 +156,7 @@ class GptDisk(object):
pass
class LvmDisk(object):
__metaclass__ = ABCMeta
class LvmDisk(metaclass=ABCMeta):
@abstractmethod
def create_lvm(self):
@ -408,8 +403,7 @@ class VirtualLvm(SizeableDisk, LvmDisk):
self.parent.disk_format.append(partition.format)
class Fdisk(SizeableDisk):
__metaclass__ = ABCMeta
class Fdisk(SizeableDisk, metaclass=ABCMeta):
def __init__(self, dev, disk_size):
super(Fdisk, self).__init__(disk_size)
@ -907,8 +901,7 @@ class VolumesSet(object):
self.builder.finish()
class BuilderFactory(object):
__metaclass__ = ABCMeta
class BuilderFactory(metaclass=ABCMeta):
@abstractmethod
def createDosBuilder(self, device, size):
@ -935,8 +928,7 @@ class DiskFactory(BuilderFactory):
extsize=extsize))
class DeviceInfo(object):
__metaclass__ = ABCMeta
class DeviceInfo(metaclass=ABCMeta):
@abstractmethod
def get_device_type(self, path=None, name=None):

@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import types
from calculate.lib import cl_overriding
import re
import sys
@ -264,8 +263,7 @@ class MultiReplace:
def __init__(self, repl_dict):
# string to string mapping; use a regular expression
keys = repl_dict.keys()
keys = list(keys)
keys = list(repl_dict.keys())
keys.sort(reverse=True) # lexical order
pattern = r"|".join([re.escape(key) for key in keys])
self.pattern = re.compile(pattern)
@ -288,7 +286,8 @@ def str2dict(s):
String format:
{'key1':'value1','key2':'val\'ue2'}
"""
value = r'(?:\\\\|\\\'|[^\'])'
# value = r'(?:\\\\|\\\'|[^\'])'
value = r'(?:\\|\'|[^\'])'
pair = r"""
\s*' # begin key
(%(v)s*)
@ -322,7 +321,8 @@ def str2list(s):
String format:
['value1','val\'ue2']
"""
value = r'(?:\\\\|\\\'|[^\'])'
value = r'(?:\\|\'|[^\'])'
# value = r'(?:\\\\|\\\'|[^\'])'
element = r"""
\s*' # begin value
(%(v)s*)

@ -559,11 +559,10 @@ def firstelement(i, fallback=''):
return x
return fallback
class GenericFs(object):
class GenericFs(metaclass=ABCMeta):
"""
Объект обобщения файловых систем
"""
__metaclass__ = ABCMeta
@abstractmethod
def exists(self, fn):

@ -477,7 +477,8 @@ class Locale(object):
default_lang = "en_US"
fields = list(langData[default_lang].keys())
#first list for casting, second one for list in list
fields = list(list(langData[default_lang].keys()))
aliases = {
'en_AU': 'en_US',

Loading…
Cancel
Save