py3 changes

master
idziubenko 3 years ago
parent 0bafdb3bac
commit b7d9ee35a5

@ -22,7 +22,7 @@ from calculate.lib.cl_xml import xpath
import time
import fcntl
from cl_xml import firstChild
from .cl_xml import firstChild
from copy import deepcopy
from .utils.common import _error
from .cl_template import FormatFactory, TemplatesError

@ -285,7 +285,7 @@ class _shareTemplate(object):
_deltVarEnd = len(varEnd)
objVar = None
_reVar = re.compile(
"%s(?:[a-z0-9_]+\.)?[a-zA-Z0-9_-]+%s" % (varStart, varEnd), re.M)
r"%s(?:[a-z0-9_]+\.)?[a-zA-Z0-9_-]+%s" % (varStart, varEnd), re.M)
def applyVarsTemplate(self, textTemplate, nameTemplate):
""" Заменяет переменные на их значения
@ -346,11 +346,11 @@ class _shareTermsFunction(object):
"""Общие аттрибуты для классов _terms и templateFunctions"""
# Символы допустимые в скобках функции шаблона
_reFunctionArgvInSquareBrackets = (
"a-zA-Z0-9_:;%@<>=\!\|\{\}\^\$\?\(\)\[\]\-"
"\n\+\,\*\/\.\'\"~\\\\ ")
_reFunctionArgvText = "[%s]" % _reFunctionArgvInSquareBrackets
r"a-zA-Z0-9_:;%@<>=\!\|\{\}\^\$\?\(\)\[\]\-"
r"\n\+\,\*\/\.\'\"~\\\\ ")
_reFunctionArgvText = r"[%s]" % _reFunctionArgvInSquareBrackets
# регулярное выражение для поиска функции в шаблоне
_reFunctionText = ("([a-zA-Z0-9\_-]+)\(((?:#-|-#|%s)+|)\)" %
_reFunctionText = (r"([a-zA-Z0-9\_-]+)\(((?:#-|-#|%s)+|)\)" %
_reFunctionArgvText)
@ -361,15 +361,15 @@ class _terms(_error, _shareTermsFunction, _shareTemplate):
# регулярное выражение для поиска функции в шаблоне
_reFunction = re.compile(_shareTermsFunction._reFunctionText)
# регулярное выражение для не версии
_re_not_Version = re.compile("[^0-9\.]")
_re_not_Version = re.compile(r"[^0-9\.]")
# регулярное выражение не номер
_re_not_Number = re.compile("[^0-9]")
_re_not_Number = re.compile(r"[^0-9]")
_suffixDict = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1}
_lenSuffixDict = len(_suffixDict)
# Регулярное выражение для названия переменной
_reRightName = re.compile("^(?:[a-z_\-]+\.)?(?:[a-zA-Z0-9_\-]+)$")
_reRightName = re.compile(r"^(?:[a-z_\-]+\.)?(?:[a-zA-Z0-9_\-]+)$")
# Регулярное выражение для сравниваемого значения
_reDenyValue = re.compile("[^0-9a-zA-Z_/\.,-]")
_reDenyValue = re.compile(r"[^0-9a-zA-Z_/\.,-]")
# латинские буквы в нижнем регистре
_letters = list(string.ascii_lowercase)
@ -620,7 +620,7 @@ class _terms(_error, _shareTermsFunction, _shareTemplate):
self.setError(textError)
return False
if "load" == searchFunct.group(1) and \
re.search("\(\s*num\s*,", vals[0]):
re.search(r"\(\s*num\s*,", vals[0]):
if valVars:
try:
valVars = int(valVars)
@ -694,7 +694,7 @@ class _terms(_error, _shareTermsFunction, _shareTemplate):
("pkg", "merge", "mergepkg")) or
(flagFunction and searchFunct.group(
1) == "load" and
re.search("\(\s*ver\s*,",
re.search(r"\(\s*ver\s*,",
vals[0]))):
# Проверка значения на версию (или интервал)
if (not self._isVersion(vals[1]) and
@ -819,7 +819,7 @@ class _terms(_error, _shareTermsFunction, _shareTemplate):
return not flagQ, filter(lambda x: not x in foundPar,
mass), foundPar
listPar = re.split("\s+", linePar)
listPar = re.split(r"\s+", linePar)
flagFoundQ = "'" in linePar
flagFoundQQ = '"' in linePar
if flagFoundQ and flagFoundQQ:
@ -965,7 +965,7 @@ class fileHeader(HParams, _terms):
# Символ комментария
comment = False
# Выражение для поиска строки интерпретатора
reExecStr = re.compile("^(#!/.+[^#]\s)", re.M)
reExecStr = re.compile(r"^(#!/.+[^#]\s)", re.M)
# условные операторы
terms = ('>', '<', '==', '!=', '>=', '<=', '<>', '=>')
# параметры без значения
@ -996,7 +996,7 @@ class fileHeader(HParams, _terms):
# В случае текста XML
if isinstance(comment, tuple) and len(comment) == 2:
reCalcHeader = \
re.compile("\s*%s\s+%s.+\s+(.+\n)+%s\s?" \
re.compile(r"\s*%s\s+%s.+\s+(.+\n)+%s\s?" \
% (comment[0], titleFirst, comment[1]),
re.M | re.I)
reS = reCalcHeader.search(self.body)
@ -1004,7 +1004,7 @@ class fileHeader(HParams, _terms):
self.body = self.body[:reS.start()] + self.body[reS.end():]
else:
reCalcHeader = re.compile(
"\s*%s\-+\s+%s\s+%s.+\s+(%s.+\s+)+%s\-+\s?" \
r"\s*%s\-+\s+%s\s+%s.+\s+(%s.+\s+)+%s\-+\s?" \
% (comment, comment, titleFirst, comment, comment),
re.M | re.I)
reS = reCalcHeader.search(self.body)
@ -1020,7 +1020,7 @@ class fileHeader(HParams, _terms):
if textLines:
textLine = textLines[0]
rePar = re.compile(
"\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)
@ -1030,7 +1030,7 @@ class fileHeader(HParams, _terms):
paramLine = self.body[reP.end():reLs.end()]
paramLine = paramLine.replace("\\", " ")
else:
reLn = re.compile("\n")
reLn = re.compile(r"\n")
reL = reLn.search(self.body)
paramLine = textLine[reP.end():]
if reL:
@ -1204,7 +1204,7 @@ class dirHeader(HParams, _terms):
if textLines:
textLine = textLines[0]
rePar = re.compile(
"\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)
@ -1214,7 +1214,7 @@ class dirHeader(HParams, _terms):
paramLine = text[reP.end():reLs.end()]
paramLine = paramLine.replace("\\", " ")
else:
reLn = re.compile("\n")
reLn = re.compile(r"\n")
reL = reLn.search(text)
paramLine = textLine[reP.end():]
if reL:
@ -1794,12 +1794,12 @@ class utfBin(object):
def decode(self, text):
"""Декодирует UTF-8 в смешанный формат"""
varStart = "__hex__\?"
varEnd = "\?__hex__"
varStart = r"__hex__\?"
varEnd = r"\?__hex__"
# -1 Это экранирование '?' которое тоже считается
deltVarStart = len(varStart) - 1
deltVarEnd = len(varEnd) - 1
reVar = re.compile("%s[a-f0-9]+%s" % (varStart, varEnd), re.M)
reVar = re.compile(r"%s[a-f0-9]+%s" % (varStart, varEnd), re.M)
resS = reVar.search(text)
textTemplateTmp = text
while resS:
@ -2010,10 +2010,10 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
templateFunction = {}
# Регулярное выражение для сложения
sNum = re.compile("\-[^\-\+]+|[^\-\+]+")
sNum = re.compile(r"\-[^\-\+]+|[^\-\+]+")
# Регулярное выражение для умножениея и деления
sMD = re.compile("[^\-\+\*/]+")
sMD = re.compile(r"[^\-\+\*/]+")
# директория установленных программ
_basePkgDir = "/var/db/pkg"
@ -2026,11 +2026,11 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
stackGlobalVars = []
# регулярное выражение для поиска версии
reFindVer = re.compile("(?<=-)(?:\d+)(?:(?:\.\d+)*)"
"(?:[a-z]?)(?:(?:_(?:pre|p|beta|alpha|rc)\d*)*)"
"(?:-r\d+)?$")
reFindVer = re.compile(r"(?<=-)(?:\d+)(?:(?:\.\d+)*)"
r"(?:[a-z]?)(?:(?:_(?:pre|p|beta|alpha|rc)\d*)*)"
r"(?:-r\d+)?$")
reEmptyLoad = re.compile("^\s*$|^\s*;|^\s*#")
reEmptyLoad = re.compile(r"^\s*$|^\s*;|^\s*#")
# Имя обрабатываемого шаблона
nameTemplate = ""
@ -2040,8 +2040,8 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
# 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)
r"|-always|alpha|beta|pre|rc|[a-z][^a-z])*[a-z]?)(?:"
r"-r\d+)?)?$", re.S)
currentAction = HParams.ActionType.Merge
@ -2093,11 +2093,11 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
self.namesTemplateFunction.append(nameFunction)
# Объект хранения переменных
self.objVar = objVar
self._reFunc = re.compile("%s%s%s"
self._reFunc = re.compile(r"%s%s%s"
% (self.varStart, self._reFunctionText,
self.varEnd), re.M)
self._rePrePattern = "%s.{%%d,}?%s" % (self.varStart, self.varEnd)
self._rePreFuncPattern = "%s.{%%d,}?\)%s" % (self.varStart, self.varEnd)
self._rePrePattern = r"%s.{%%d,}?%s" % (self.varStart, self.varEnd)
self._rePreFuncPattern = r"%s.{%%d,}?\)%s" % (self.varStart, self.varEnd)
# Аттрибуты для функции шаблона ini()
# Первоначальный словарь переменных для ini()
self.prevDictIni = {}
@ -2303,7 +2303,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
pattern = r" "
pattern = pattern.replace(r"\1", "{0}")
pattern = re.sub(r"(^|[^\\])\\n", "\\1\n", pattern)
pattern = re.sub(r"(^|[^\\])\\n", r"\\1\n", pattern)
pattern = pattern.replace(r"\n", "\n")
pattern = pattern.replace(r"\t", "\t")
@ -2612,7 +2612,7 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
Функция grep (...), выдает значение из файла по регулярному выражению
"""
fname, op, regpattern = funArgv.replace(" ", "").partition(",")
regpattern = regpattern.replace("(?\<", "(?<")
regpattern = regpattern.replace(r"(?\<", "(?<")
regpattern = self._replace_hex(regpattern)
if not fname or not regpattern:
raise self.raiseErrTemplate()
@ -3047,13 +3047,13 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction,
wpath = pathJoin(self._baseDir, wpath)
if os.path.isdir(wpath):
re_resol = re.compile("^(\d+)x(\d+)(-\d+(@\d+)?)?$")
re_resol = re.compile(r"^(\d+)x(\d+)(-\d+(@\d+)?)?$")
resol = re_resol.match(resol)
if not resol:
raise self.raiseErrTemplate(
_("the first parameter must be the resolution"))
re_resol = re.compile(".*?(\d+)x(\d+).*")
re_resol = re.compile(r".*?(\d+)x(\d+).*")
res = map(lambda x: (int(x.group(1)), int(x.group(2)), x.group()),
filter(None,
map(re_resol.search,
@ -3888,11 +3888,11 @@ class Template(_file, _terms, _warning, xmlShare, _shareTemplate):
self._titleBody = ""
# Условия
self._reTermBloc = re.compile(
"#\?(?P<rTerm>(?:[a-z0-9_]+\.)?[a-zA-Z0-9\-_]+)"
"(?P<func>\(((?:#-|-#|%s)+|)\))?"
"(?P<lTerm>[><=!&\|]+"
"(?:#-|-#|[><=!\|&\(\)%s])*)#"
"\n?(?P<body>.+?\n*?)\n?#(?P=rTerm)#(?P<end>[ ,\t]*\n?)"
r"#\?(?P<rTerm>(?:[a-z0-9_]+\.)?[a-zA-Z0-9\-_]+)"
r"(?P<func>\(((?:#-|-#|%s)+|)\))?"
r"(?P<lTerm>[><=!&\|]+"
r"(?:#-|-#|[><=!\|&\(\)%s])*)#"
r"\n?(?P<body>.+?\n*?)\n?#(?P=rTerm)#(?P<end>[ ,\t]*\n?)"
% (self._reFunctionArgvText, self._reFunctionArgvInSquareBrackets),
re.M | re.S)
# Объект с переменными
@ -4113,8 +4113,8 @@ gettext -d cl_template "$*"
return createDirs
reBlock = re.compile(
"#\?(?P<rTerm>(?:[a-z0-9_]+\.)?[a-zA-Z0-9\-_]+).*?#(?P=rTerm)#"
"(?:[ ,\t]*\n?)",
r"#\?(?P<rTerm>(?:[a-z0-9_]+\.)?[a-zA-Z0-9\-_]+).*?#(?P=rTerm)#"
r"(?:[ ,\t]*\n?)",
re.S | re.M)
def applyTermsTemplate(self, textTemplate, nameTemplate):
@ -4297,7 +4297,7 @@ gettext -d cl_template "$*"
if textLines:
textLine = textLines[0]
rePar = re.compile(
"\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)
@ -4911,7 +4911,7 @@ gettext -d cl_template "$*"
ver_nor = prev_ver.partition("-")[0]
# rc даже после уже существующего гарантирует, что версия будет
# считаться ниже
#reRc = re.compile("(.*rc)(\d+)(.*)")
#reRc = re.compile(r"(.*rc)(\d+)(.*)")
#rc_match = reRc.search(ver_nor)
#if rc_match:
# rc_num = max(0, int(rc_match.group(2)) - 1)
@ -6410,7 +6410,7 @@ gettext -d cl_template "$*"
title = title.encode("UTF-8")
# В случае пустого конфигурационного файла
reNoClean = re.compile("[^\s]", re.M)
reNoClean = re.compile(r"[^\s]", re.M)
if not self.textConfig or \
not reNoClean.search(self.textConfig):
self.textConfig = ""

@ -3,8 +3,8 @@
from io import open
import configparser
# from collections import OrderedDict as _default_dict
from configparser import ConfigParser, Error
# from .configparser_helpers import _ChainMap
__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
@ -23,10 +23,30 @@ import os
from contextlib import contextmanager
from calculate.lib.utils.tools import LockError, Locker
#compat
NoSectionError = configparser.NoSectionError
DuplicateOptionError = configparser.DuplicateOptionError
DuplicateSectionError = configparser.DuplicateSectionError
NoOptionError = configparser.NoOptionError
InterpolationError = configparser.InterpolationError
InterpolationDepthError = configparser.InterpolationDepthError
InterpolationSyntaxError = configparser.InterpolationSyntaxError
ParsingError = configparser.ParsingError
MissingSectionHeaderError = configparser.MissingSectionHeaderError
ConfigParser = configparser.ConfigParser
SafeConfigParser = configparser.SafeConfigParser
RawConfigParser = configparser.RawConfigParser
Error = configparser.Error
class ConfigParserCaseSens(ConfigParser):
u"""ConfigParser with case sensitivity keys"""
def optionxform(self, optionstr):
return optionstr
class ConfigParserLocked(ConfigParser):
def __init__(self, filename, chmod=0o600):
super(ConfigParserLocked, self).__init__(strict=False)
super().__init__(strict=False)
self.filename = filename
self.locker = Locker(fn=filename)
self.chmod = chmod

@ -25,7 +25,8 @@ from .utils.files import pathJoin
from .utils.portage import searchProfile, RepositorySubstituting, RepositoryPath
from os import path
import os
from collections import OrderedDict, Iterable
from collections import OrderedDict
from collections.abc import Iterable
from threading import RLock
from itertools import *
import operator
@ -258,7 +259,7 @@ class Variable(VariableInterface):
@classmethod
def getVariableName(cls):
return re.sub("(.)([A-Z])", "\\1_\\2", cls.__name__[8:]).lower()
return re.sub(r"(.)([A-Z])", "\\1_\\2", cls.__name__[8:]).lower()
def getCharType(self):
"""
@ -293,13 +294,30 @@ class Variable(VariableInterface):
"""Get value of other value"""
if not varname or varname == self.name:
return self._get()
print("DEBUG Get")
print(varname)
varObj = self.parent.getInfo(varname)
if varname in ["os_lvm_data"]:
print(varname)
print(self.section)
# print(f"{self.section}.{varname}")
print("%s.%s" % (self.section, varname))
print(not "." in varname)
varname = f"{self.section}.{varname}"
print(not "." in varname)
print(self.parent)
# varObj.modeGet = Variable.UNCOMPAT
if not "." in varname:
varname = "%s.%s" % (self.section, varname)
# varname = "%s.%s" % tuple([self.section, varname])
varname = f"{self.section}.{varname}"
res = self.parent.Get(varname, humanreadable)
if varname in ["install.os_lvm_data"]:
print("AFTER GET")
raise Exception
# build dependence for check and uncompatible
if varObj:
if self.modeGet == Variable.NONE:
@ -332,12 +350,21 @@ class Variable(VariableInterface):
"""
Get zipped values of variables specified by list 'argvVarNames'
"""
print("Im zipVars")
if "humanreadable" in kw:
hr = kw['humanreadable']
return zip(*map(lambda x:self.Get(x, humanreadable=hr),
argvVarNames))
# return zip(*list(map(lambda x:self.Get(x, humanreadable=hr),
# argvVarNames)))
else:
return zip(*map(self.Get, argvVarNames))
print("beep")
print(argvVarNames)
tt = self.Get(argvVarNames[0])
print(tt)
raise Exception
tmp = list(map(self.Get, argvVarNames))
print(tmp)
return zip(*tmp)
def _get_format_value(self):
return self._value_formatter.format(
@ -349,9 +376,15 @@ class Variable(VariableInterface):
Calculate value method
"""
if self.__class__.value_format:
return self._get_format_value()
val = self._get_format_value()
# print("DEBUG get - value_format")
# print(val)
return val
if self.__class__.value:
return self.__class__.value
val = self.__class__.value
# print("DEBUG get - value")
# print(val)
return val
else:
return [] if "list" in self.type else ""
@ -395,8 +428,9 @@ class Variable(VariableInterface):
self.bIniRead = True
try:
value = self.parent.iniCache[self.fullname]
value = self.parent.unserialize(self.type,
value.encode('utf-8'))
value = self.parent.unserialize(self.type, value)
# value = self.parent.unserialize(self.type,
# value.encode('utf-8'))
if self.mode == READONLY:
raise VariableError(
_("Attempting to rewrite readonly variable %s "
@ -421,18 +455,22 @@ class Variable(VariableInterface):
"""
# variable need refill
if self.invalid:
# print('was invalid')
# get net value
if self.fullname in self.parent.iniCache and self.iniread():
# print("return ", self.value)
return self.value
else:
oldModeGet = self.modeGet
try:
# print("trying to get")
self.modeGet = Variable.NONE
value = self.get()
self.untrusted = self.__class__.untrusted
finally:
self.modeGet = oldModeGet
# if value not equal previous value
# print("value from get: ", value)
if value != self.value:
# invalidate depended variables
self.invalidate()
@ -441,7 +479,18 @@ class Variable(VariableInterface):
if hasattr(self.value, "close"):
self.value.close()
self.value = value
return self.value
# return self.value
val = self.value
# print("DEBUGGG")
# print(val)
# print(type(val))
if isinstance(val, bytes):
val = str(val, encoding="UTF-8")
# print(val)
# print(type(val))
return val
def choice(self):
"""
@ -702,10 +751,10 @@ class TableVariable(Variable):
self.source)):
raise VariableError(
_("Source variable %s does not contain a list") % varname)
return map(list,
return list(map(list,
zip_longest(
*map(lambda x: self.Get(x, humanreadable=hr),
self.source), fillvalue='')) or [[]]
self.source), fillvalue=''))) or [[]]
def getHumanReadableAuto(self):
"""
@ -879,7 +928,7 @@ class FieldValue(VariableInterface):
sourceVar = self.Get(self.source_variable)
if isinstance(sourceVar, Iterable):
if any(sourceVar):
return zip(*sourceVar)[self.column]
return list(zip(*sourceVar))[self.column]
else:
return []
else:
@ -896,14 +945,14 @@ class SourceReadonlyVariable(ReadonlyVariable):
indexField = ""
def get(self):
return map(lambda x: x or "",
return list(map(lambda x: x or "",
map(self.getMap().get,
self.Get(self.indexField)))
self.Get(self.indexField))))
def humanReadable(self):
return map(lambda x: x or "",
return list(map(lambda x: x or "",
map(self.getMapHumanReadable().get,
self.Get(self.indexField)))
self.Get(self.indexField))))
def getMap(self):
return {}
@ -1012,7 +1061,8 @@ class SimpleDataVars(object):
if varname not in self.changed:
val = self.unserialize(
varobj.type or "string",
importVars[varobj.section].get(varname, '').encode('utf-8'))
#TODO bin or string?
importVars[varobj.section].get(varname, ''))
if val and val != [[]] or varname in importVars[varobj.section]:
self.cache[varname] = val
@ -1051,20 +1101,23 @@ class SimpleDataVars(object):
if "list" in varType:
return getList()(value)
if "table" in varType:
return map(getList(':'), value.split(','))
value = str(value, "UTF-8")
return list(map(getList(':'), value.split(',')))
if (isinstance(value, bytes)):
value = str(value, "UTF-8")
return fixEmpty(value).strip("'").strip('"')
def ZipVars(self, *argvVarNames, **kw):
"""
Get zipped values of variables specified by list 'argvVarNames'
"""
if "humanreadable" in kw:
hr = kw['humanreadable']
return zip(*map(lambda x:self.Get(x, humanreadable=hr),
argvVarNames))
else:
return zip(*map(self.Get, argvVarNames))
print("DEBUG ZIPVARS")
raise Exception
# if "humanreadable" in kw:
# hr = kw['humanreadable']
# return zip(*list(map(lambda x:self.Get(x, humanreadable=hr),
# argvVarNames)))
# else:
# return zip(*list(map(self.Get, argvVarNames)))
def select(self, *fields, **kw):
"""
@ -1131,6 +1184,7 @@ class SimpleDataVars(object):
_if=None,
sort=None, sortkey=None, limit=None, zipVars=None):
"""Select value from table variables"""
print("DEBUG SELECT")
if zipVars is None:
zipVars = self.ZipVars
if func or _if:
@ -1155,9 +1209,15 @@ class SimpleDataVars(object):
else:
filterFunc = lambda x: x
if not type(where) in (tuple, list):
where = [where]
woffset = len(where)
print("SELECT HALFWAY")
print(isinstance(selField, (tuple, list)))
if isinstance(selField, (tuple, list)):
count = len(selField) + woffset
mapFunc = lambda x: x[woffset:]
@ -1167,6 +1227,12 @@ class SimpleDataVars(object):
count = 1 + woffset
fields = where + [selField]
mapFunc = lambda x: x[woffset]
print("BEEP")
print(fields)
tmp = zipVars(*fields)
print(tmp)
raise Exception
res = list(filter(filterFunc,
zipVars(*fields)))
if sort:
@ -1202,7 +1268,7 @@ class DataVars(SimpleDataVars):
l = RLock()
def __init__(self):
super(DataVars, self).__init__()
super().__init__()
self.requestVariables = []
self.loadVariables = {}
self.allVars = {}
@ -1253,7 +1319,7 @@ class DataVars(SimpleDataVars):
try:
varModule = importlib.import_module(data)
except (ImportError, AttributeError) as e:
self.raiseModuleError(data, e)
self.raiseModuleError(data, e)
return False
# get all Variable classes from module
# variable of class VariableClAction will be named cl_action
@ -1429,11 +1495,19 @@ 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()
return var
def isFromIni(self, varname):
@ -1445,9 +1519,21 @@ class DataVars(SimpleDataVars):
return self.filledVars[varname] if varname in self.filledVars else ""
def splitVarname(self, varname):
if varname in ["install.os_lvm_data"]:
print("DEBUG in splitVarname")
print(varname)
print(type(varname))
res = self.reRightVar.search(varname)
if res:
if res.group(1):
if varname in ["install.os_lvm_data"]:
print("DEBUG2 in splitVarname")
print(res)
print(bool(res))
print(res.group(1))
print(bool(res.group(1)))
# raise Exception
return res.groups()
else:
return self.defaultModule, res.group(2)
@ -1461,7 +1547,10 @@ class DataVars(SimpleDataVars):
try:
# tm = time.time()
# load variable if it isn't loaded
if varname in ["install.os_lvm_data"]:
print("DEBUG in __GET")
section, varname = self.splitVarname(varname)
if (varname not in self.loadVariables or
section not in self.importedModules):
try:
@ -1471,12 +1560,13 @@ class DataVars(SimpleDataVars):
return ""
raise
varObj = self.loadVariables[varname]
# check section
if varObj.section not in (section, "main"):
self.raiseVariableNotFound(varname, parent=self,
section=section)
if varname in ["os_lvm_data"]:
print("DEBUG2 in __GET")
# if for this variable already use Get method
if varObj.invalid and varObj in self.requestVariables:
varnames = "-".join(map(lambda x: x.name,
@ -1495,6 +1585,8 @@ class DataVars(SimpleDataVars):
if not humanreadable:
if self.requestVariables:
self.requestVariables.pop()
if varname in ["os_lvm_data"]:
print("DEBUG3 in __GET")
return res
except BaseException:
while len(self.requestVariables):

@ -26,16 +26,16 @@ class apache(bind):
_comment = "#"
configName = "apache"
configVersion = "0.1"
__headerArea = "[^\<\> \t]+[ \t]+[^\<\> \t]+"
__openArea = "[ \t]*\<%s\>" % __headerArea
__closeArea = "[ \t]*\<\/[^\<\>]+\>"
sepFields = "\n"
__headerArea = r"[^\<\> \t]+[ \t]+[^\<\> \t]+"
__openArea = r"[ \t]*\<%s\>" % __headerArea
__closeArea = r"[ \t]*\<\/[^\<\>]+\>"
sepFields = r"\n"
reOpen = re.compile(__openArea)
reClose = re.compile(__closeArea)
reCloseArea = re.compile(__closeArea + "\s*\Z")
reComment = re.compile("[ \t]*%s" % _comment)
reCloseArea = re.compile(__closeArea + r"\s*\Z")
reComment = re.compile(r"[ \t]*%s" % _comment)
reSepFields = re.compile(sepFields)
reSeparator = re.compile("[ \t]+")
reSeparator = re.compile(r"[ \t]+")
reHeader = re.compile(__headerArea)
def prepare(self):

@ -154,7 +154,7 @@ class backgrounds(TemplateFormat):
if self.convert not in self.objVar.Get('cl_image_formats'):
self.setError(_("Wrong image format '%s'") % self.convert)
return False
reRule = re.compile("^(\d+)x(\d+)(?:-[0-9]+)?$")
reRule = re.compile(r"^(\d+)x(\d+)(?:-[0-9]+)?$")
if not rootPath:
rootPath = '/'
@ -165,7 +165,7 @@ class backgrounds(TemplateFormat):
prefix = ""
if prefix:
md5_fn = os.path.join(workdir, "%s.md5" %
re.sub("[-._]+$", "", prefix))
re.sub(r"[-._]+$", "", prefix))
else:
md5_fn = os.path.join(workdir, self.fallback_md5fn)
if not self.source:

@ -28,15 +28,15 @@ class bind(objShare):
configName = "bind"
configVersion = "0.1"
__openArea = "{"
__closeArea = "[ \t]*\}[ \t]*;[ \t]*"
sepFields = ";"
__closeArea = r"[ \t]*\}[ \t]*;[ \t]*"
sepFields = r";"
reOpen = re.compile(__openArea)
reClose = re.compile(__closeArea)
reCloseArea = re.compile(__closeArea + "\s*\Z")
reCloseArea = re.compile(__closeArea + r"\s*\Z")
reComment = re.compile(
"[ \t]+%s|^%s|(?<=;)%s" % (_comment, _comment, _comment))
r"[ \t]+%s|^%s|(?<=;)%s" % (_comment, _comment, _comment))
reSepFields = re.compile(sepFields)
reSeparator = re.compile("[ \t]+")
reSeparator = re.compile(r"[ \t]+")
def prepare(self):
self.blocTextObj = blocText()

@ -25,11 +25,11 @@ class compiz(samba):
_comment = "#"
configName = "compiz"
configVersion = "0.1"
reHeader = re.compile("^[\t ]*\[[^\[\]]+\].*\n", re.M)
reBody = re.compile(".+", re.M | re.S)
reComment = re.compile("\s*%s.*" % _comment)
reSeparator = re.compile("\s*=\s*")
sepFields = "\n"
reHeader = re.compile(r"^[\t ]*\[[^\[\]]+\].*\n", re.M)
reBody = re.compile(r".+", re.M | re.S)
reComment = re.compile(r"\s*%s.*" % _comment)
reSeparator = re.compile(r"\s*=\s*")
sepFields = r"\n"
reSepFields = re.compile(sepFields)
def join(self, compizObj):

@ -26,14 +26,14 @@ class dhcp(bind):
configName = "dhcp"
configVersion = "0.1"
__openArea = "{"
__closeArea = "[ \t]*\}[ \t]*"
__closeArea = r"[ \t]*\}[ \t]*"
sepFields = ";"
reOpen = re.compile(__openArea)
reClose = re.compile(__closeArea)
reCloseArea = re.compile(__closeArea + "\s*\Z")
reComment = re.compile("^[ \t]*%s" % _comment)
reCloseArea = re.compile(__closeArea + r"\s*\Z")
reComment = re.compile(r"^[ \t]*%s" % _comment)
reSepFields = re.compile(sepFields)
reSeparator = re.compile("[ \t]+")
reSeparator = re.compile(r"[ \t]+")
def setDataField(self, txtLines, endtxtLines):
"""Создаем список объектов с переменными"""

@ -22,7 +22,7 @@ from calculate.lib.cl_xml import xpath
from lxml import etree
from calculate.lib.format.xml_xfce import xml_xfce
from calculate.lib.cl_lang import setLocalTranslate
from collections import Iterable
from collections.abc import Iterable
from copy import deepcopy
_ = lambda x: x

@ -18,7 +18,7 @@ import sys
from calculate.lib.cl_xml import xpath
from calculate.lib.format.xml_gconf import xml_gconf
from calculate.lib.cl_lang import setLocalTranslate
from collections import Iterable
from collections.abc import Iterable
from copy import deepcopy
_ = lambda x: x

@ -20,7 +20,7 @@ from calculate.lib.cl_xml import xpath
from lxml import etree
from calculate.lib.cl_template import TemplateFormat
from calculate.lib.cl_lang import setLocalTranslate
from collections import Iterable
from collections.abc import Iterable
from copy import deepcopy
_ = lambda x: x
setLocalTranslate('cl_lib3', sys.modules[__name__])

@ -19,7 +19,7 @@ from calculate.lib.cl_xml import xpath
# import xml.dom.minidom
from lxml import etree
from calculate.lib.format.xml_xfce import xml_xfce
from collections import Iterable
from collections.abc import Iterable
from copy import deepcopy
from calculate.lib.cl_lang import setLocalTranslate

@ -24,7 +24,8 @@ from calculate.lib.configparser import ConfigParserCaseSens, Error as CPError
from calculate.lib.utils.tools import SingletonParam, Cachable
from calculate.lib.utils.gpg import GPGError
from .files import writeFile, xz
from collections import MutableMapping, OrderedDict
from collections import OrderedDict
from collections.abc import MutableMapping
from functools import total_ordering
from contextlib import contextmanager
import io
@ -147,7 +148,7 @@ class BinhostsBase(Cachable):
except BinhostSignError:
return False
re_revison = re.compile("\w+=(\w+)")
re_revison = re.compile(r"\w+=(\w+)")
def _get_timestamp(self, timestamp_file):
"""

@ -108,13 +108,13 @@ class ConsoleCodesConverter(BaseConverter):
super(ConsoleCodesConverter, self).__init__(output)
self.escSymb = escSymb
self.escBlock = (r"{esc}(?:\[(\d*(?:;\d+)*)(m)|"
"\]\d+;.*?\x07|"
"\([B0UK]|"
"\[\d*[A-D])".format(esc=escSymb))
self.otherSymb = "(?:\r*\n|\t)"
r"\]\d+;.*?\x07|"
r"\([B0UK]|"
r"\[\d*[A-D])".format(esc=escSymb))
self.otherSymb = r"(?:\r*\n|\t)"
self.reEscBlock = re.compile(self.escBlock)
self.reParse = re.compile(
"(?:{0}|({1}))?(.*?)(?=$|{0}|{1})".format(self.escBlock,
r"(?:{0}|({1}))?(.*?)(?=$|{0}|{1})".format(self.escBlock,
self.otherSymb),
re.DOTALL)
resetBoldHalfbright = lambda: (
@ -261,7 +261,7 @@ class XmlConverter(BaseConverter):
}
self.colorMap = {FontAttr.FOREGROUND.lower(): self.output.setForeground,
FontAttr.BACKGROUND.lower(): self.output.setBackground}
self.reMatch = re.compile("<(?:%s)" % "|".join(self.tagMap.keys()),
self.reMatch = re.compile(r"<(?:%s)" % "|".join(self.tagMap.keys()),
re.I)
self.parser = self.createParser()

@ -88,8 +88,8 @@ class _warning(object):
def genpassword(passlen=9, chars=string.ascii_letters + string.digits):
"""Return random charset specified lenght (passlen)"""
return ''.join(map(lambda x: choice(chars),
range(0, passlen)))
return ''.join(list(map(lambda x: choice(chars),
range(0, passlen))))
def getpathenv():
@ -126,12 +126,12 @@ def getTupleVersion(ver):
"rc": -1}
def toTuple(v):
return map(lambda x: suffix_value[x] if x in suffix_value else x,
return list(map(lambda x: suffix_value[x] if x in suffix_value else x,
map(lambda x: int(x) if x.isdigit() else x,
re.findall("r\d+$|\d+|[a-zA-Z+]+",
v.replace('-SNAPSHOT', ''))))
re.findall(r"r\d+$|\d+|[a-zA-Z+]+",
v.replace('-SNAPSHOT', '')))))
vers, revision = re.search("(^.*?)(-r\d+)?$", ver, re.S).groups()
vers, revision = re.search(r"(^.*?)(-r\d+)?$", ver, re.S).groups()
vers = toTuple(vers)
vers.extend([0] * (10 - len(vers)))
revision = toTuple(revision or "r0")
@ -142,9 +142,9 @@ def getInstalledVideo(prefix="/"):
"""Get installed video drivers"""
usrlib = SystemPath(prefix).usrlib
x11Drivers = "%s/xorg/modules/drivers" % usrlib
return map(lambda x: x[:-7],
return list(map(lambda x: x[:-7],
filter(lambda x: x.endswith('_drv.so'),
listDirectory(x11Drivers)))
listDirectory(x11Drivers))))
def getDistfilesVideo(prefix="/"):
@ -184,14 +184,14 @@ def getPasswdUsers(minId=1000, maxId=65000, prefix="/",
retList = []
fileName = path.join(prefix, datafile)
if os.access(fileName, os.R_OK):
reNumb = re.compile("^\d+$")
reNumb = re.compile(r"^\d+$")
lenData = 7
with open(fileName) as f:
userData = filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), f))
userData = filter(
userData = list(filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), f)))
userData = list(filter(
lambda x: reNumb.match(x[2]) and minId <= int(x[2]) <= maxId,
userData)
userData))
sortUsers = list(map(lambda x: x[0], userData))
sortUsers.sort()
retList = ["root"] + sortUsers
@ -203,8 +203,8 @@ def getSupportArch():
Is support processor x86_64 else only i686.
"""
if filter(lambda x: x.startswith('flags') and " lm " in x,
readLinesFile('/proc/cpuinfo')):
if list(filter(lambda x: x.startswith('flags') and " lm " in x,
readLinesFile('/proc/cpuinfo'))):
return ['i686', 'x86_64']
else:
return ['i686']
@ -290,7 +290,7 @@ def getValueFromConfig(config, name):
config config file name
name param name
"""
reMatch = re.compile("^%s\s*=\s*(.*?)\s*$" % name, re.I)
reMatch = re.compile(r"^%s\s*=\s*(.*?)\s*$" % name, re.I)
val = None
try:
if path.exists(config):
@ -312,20 +312,20 @@ def getVideoFromXorgLog(prefix="/", available_drivers=()):
# Try analize Xorg.{DISPLAY}.log
display = os.environ.get('DISPLAY', ':0')
if display and available_drivers:
reDriver = re.compile('|'.join(map(lambda x: "%s_drv.so" % x,
available_drivers)))
reDriver = re.compile('|'.join(list(map(lambda x: "%s_drv.so" % x,
available_drivers))))
display_number = re.search(r':(\d+)(\..*)?', display)
reDriverName = re.compile(r'([^/]+)_drv.so')
if display_number:
xorg_log_file = path.join(prefix, 'var/log/Xorg.%s.log' %
display_number.group(1))
if path.exists(xorg_log_file):
matchStrs = map(
matchStrs = list(map(
lambda x: x.group(1),
filter(lambda x: x, map(
reDriverName.search,
filter(lambda x: "drv" in x and reDriver.search(x),
readLinesFile(xorg_log_file)))))
readLinesFile(xorg_log_file))))))
if matchStrs:
reUnload = re.compile('UnloadModule: "(%s)"' %'|'.join(x
for x in matchStrs))
@ -365,10 +365,10 @@ def getVideoFromCmdLine():
def getVideoFromModules():
workedModules = map(lambda x: x[0],
workedModules = list(map(lambda x: x[0],
filter(lambda x: x[1].isdigit() and int(x[1]) > 0,
map(lambda x: x.split()[:3:2],
readLinesFile('/proc/modules'))))
readLinesFile('/proc/modules')))))
mapModules = {'nouveau': 'nouveau',
'radeon': 'radeon',
'i915': 'intel',
@ -429,7 +429,7 @@ def getCompositeFromXorgconf(prefix="/"):
if line.startswith('Section') and '"Extensions"' in line:
flagStartExtensions = True
if lineComposite:
listOpt = filter(lambda x: x.strip(), lineComposite.split('"'))
listOpt = list(filter(lambda x: x.strip(), lineComposite.split('"')))
if len(listOpt) == 3:
ret = listOpt[2].lower()
if ret in ("on", "true", "yes", "1"):
@ -469,10 +469,10 @@ def getUserGroups(userName, prefix="/"):
"""
Get user groups from /etc/groups
"""
return map(lambda x: x[0],
return list(map(lambda x: x[0],
filter(lambda x: len(x) > 1 and userName in x[1].split(','),
map(lambda x: x.split(':')[0::3],
readLinesFile(path.join(prefix, 'etc/group')))))
readLinesFile(path.join(prefix, 'etc/group'))))))
def getUserPrimaryGroup(userName, prefix="/"):
@ -494,9 +494,9 @@ def getGroups(prefix="/"):
"""
Get groups from etc/group
"""
return filter(None,
return list(filter(None,
map(lambda x: x.split(':')[0],
readLinesFile(path.join(prefix, 'etc/group'))))
readLinesFile(path.join(prefix, 'etc/group')))))
def getPagesInterval(count, offset, length):

@ -31,7 +31,7 @@ def getUUIDDict(revers=False, devs=()):
"""Get dict UUID -> dev"""
blkidProcess = files.process("/sbin/blkid", "-s", "UUID", "-c", "/dev/null",
*list(devs))
reSplit = re.compile('^([^:]+):.*UUID="([^"]+)"', re.S)
reSplit = re.compile(r'^([^:]+):.*UUID="([^"]+)"', re.S)
searched = (x.groups() for x in map(reSplit.search, blkidProcess) if x)
mapping = (("UUID=%s" % uuid, udev.get_devname(name=dev, fallback=dev))
for dev, uuid in searched)
@ -256,9 +256,9 @@ class UdevAdm(UdevAdmNull):
value = path
udev_output = files.process(self.udevadm_cmd, "info", "--query",
"property",
type_query, value).read().split(b"\n")
type_query, value).read().split("\n")
return dict(x.partition(b"=")[0::2] for x in udev_output if b"=" in x)
return dict(x.partition("=")[0::2] for x in udev_output if "=" in x)
def info_export(self):
return files.process(self.udevadm_cmd, "info", "-e").read().strip()
@ -300,11 +300,20 @@ 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:
@ -645,7 +654,7 @@ class DeviceFs(object):
self.fs = files.RealFs("/")
def pathjoin(self, *dns):
res = path.join(b"/", *(dn[1:] if dn.startswith(b"/") else dn
res = path.join("/", *(dn[1:] if dn.startswith("/") else dn
for dn in dns))
return res
@ -760,5 +769,5 @@ class Hwinfo(object):
"""
Получить допустимые разрешения фреймбуффера
"""
re_modes = re.compile("^\s+Mode 0x[0-9a-f]+:\s+(\d+x\d+)\s",re.M)
re_modes = re.compile(r"^\s+Mode 0x[0-9a-f]+:\s+(\d+x\d+)\s",re.M)
return tuple(sorted(unique(re_modes.findall(self.framebuffer()))))

@ -285,7 +285,10 @@ class process(StdoutableProcess):
else:
for line in self.readByLine():
pass
return self.cacheresult
# print("debug process read")
# print(self.cacheresult)
# print(type(self.cacheresult))
return self.cacheresult.decode(encoding="UTF-8")
except KeyboardInterrupt:
self.kill()
raise KeyboardInterrupt
@ -294,7 +297,7 @@ class process(StdoutableProcess):
def readlines(self):
"""Read lines"""
return self.read().decode(encoding="UTF-8").split('\n')
return self.read().split('\n')
def __iter__(self):
"""Get iterator"""
@ -1118,7 +1121,7 @@ def getLoopFromPath(directory):
"""
losetup = getProgPath('losetup')
p = process(losetup, '-a')
rePattern = re.compile('(^/dev/loop[^:]+)[^(]+\(([^)]+)\).*')
rePattern = re.compile(r'(^/dev/loop[^:]+)[^(]+\(([^)]+)\).*')
return map(lambda x: x[0],
filter(lambda x: x[1].startswith(directory),
reSearch(rePattern,
@ -1129,7 +1132,7 @@ def getMdRaidDevices():
"""
Получить словарь: какой mdraid какие использует устройства
"""
reMdInfo = re.compile('^(\w+)\s+:\s+active.*?raid\d+\s+(.*)')
reMdInfo = re.compile(r'^(\w+)\s+:\s+active.*?raid\d+\s+(.*)')
return dict(map(lambda x: (x[0], map(lambda x: x.partition('[')[0],
x[1].split())),
reSearch(reMdInfo, readLinesFile('/proc/mdstat'))))
@ -1141,7 +1144,7 @@ class PercentProgress(processProgress):
Args:
part: количество прогрессов в программе
delimeter: разделители строк по умолчанию \n и \r
delimeter: разделители строк по умолчанию \\n и \\r
cachefilter: фильтр вывода программы (регулярная строка)
startpart: используется для вывода процентов прогрессбар
с определенного места (0 по умолчанию)
@ -1150,7 +1153,7 @@ class PercentProgress(processProgress):
"""
def init(self, *args, **kwargs):
self.rePerc = re.compile("(\d+(?:\.\d+)?)%", re.S)
self.rePerc = re.compile(r"(\d+(?:\.\d+)?)%", re.S)
self.part = kwargs.get("part", 1)
if self.part < 1:
self.part = 1
@ -1158,11 +1161,12 @@ class PercentProgress(processProgress):
self.offset = 0 + kwargs.get("startpart", 0) * self.add_offset
self.is_end = kwargs.get("end", True)
self.stderr = STDOUT
self.delimeter = re.compile("[%s]" % kwargs.get("delimeter", "\n\r"))
self.cachedata = re.compile(kwargs.get("cachefilter",
"((?:\[31;01m\*|\[33;01m\*|"
"Bad Option|No space left|FATAL ERROR|SYNTAX:|mkisofs:|"
"error:|warning:|fatal:).*)"))
self.delimeter = re.compile(r"[%s]" % kwargs.get("delimeter", "\n\r"))
#TODO do something with this monster?
self.cachedata = re.compile(kwargs.get(r"cachefilter",
r"((?:\[31;01m\*|\[33;01m\*|"
r"Bad Option|No space left|FATAL ERROR|SYNTAX:|mkisofs:|"
r"error:|warning:|fatal:).*)"))
self.atty = kwargs.get("atty", False)
self.alldata = ""
@ -1205,7 +1209,7 @@ class PercentProgress(processProgress):
resSearch = self.cachedata.search(strdata)
if resSearch:
self._cachedata.append(
re.sub("\[31;01m\*|\[33;01m\*|\[.*?m",
re.sub(r"\[31;01m\*|\[33;01m\*|\[.*?m",
"", resSearch.group(1)))
if match:
percent = int(float(match.group(1)))

@ -20,12 +20,12 @@ class XorgConfig(object):
"""
Объект получения параметров из xorg.conf подобного файла
"""
section_pattern = '^Section "%s"\s*\n(.*?)^EndSection'
section_pattern = r'^Section "%s"\s*\n(.*?)^EndSection'
class Section(object):
value_pattern = '%s\s*"([^"]+)"'
value_pattern = r'%s\s*"([^"]+)"'
option_pattern = 'Option\s*"%s"\s*"([^"]+)"'
option_pattern = r'Option\s*"%s"\s*"([^"]+)"'
def __init__(self, sectionname, content):
self.sectionname = sectionname

@ -500,18 +500,18 @@ class Git(object):
:return: (тип, хост)
"""
net_protocols = {
'ssh': Git.GitProtocol.SSH,
'ssh+git': Git.GitProtocol.SSH,
'git+ssh': Git.GitProtocol.SSH,
'http': Git.GitProtocol.HTTP,
'https': Git.GitProtocol.HTTPS,
'ftp': Git.GitProtocol.FTP,
'ftps': Git.GitProtocol.FTPS,
'rsync': Git.GitProtocol.Rsync,
'git': Git.GitProtocol.Git}
r'ssh': Git.GitProtocol.SSH,
r'ssh+git': Git.GitProtocol.SSH,
r'git+ssh': Git.GitProtocol.SSH,
r'http': Git.GitProtocol.HTTP,
r'https': Git.GitProtocol.HTTPS,
r'ftp': Git.GitProtocol.FTP,
r'ftps': Git.GitProtocol.FTPS,
r'rsync': Git.GitProtocol.Rsync,
r'git': Git.GitProtocol.Git}
re_host = re.compile(
"(%s)://(?:[^@]+@)?([^:/]+)(:\d+)?" %
"|".join(x.replace("+", r"\+") for x in net_protocols.keys())
r"(%s)://(?:[^@]+@)?([^:/]+)(:\d+)?" %
r"|".join(x.replace("+", r"\+") for x in net_protocols.keys())
)
net_match = re_host.search(url)
if net_match:
@ -729,8 +729,8 @@ class Git(object):
'origin':'origin/master'}
"""
reStatus = re.compile(
"^## (\w+)\s*(\(no branch\))?(?:\.\.\.(\S+))?(?:\s+\[(ahead \d+)?"
"(?:, )?(behind \d+)?\])?\n?(.*|$)", re.S)
r"^## (\w+)\s*(\(no branch\))?(?:\.\.\.(\S+))?(?:\s+\[(ahead \d+)?"
r"(?:, )?(behind \d+)?\])?\n?(.*|$)", re.S)
match = reStatus.search(data)
if not match:
return {}

@ -55,28 +55,28 @@ IFF_MASTER = 0x400
IFF_SLAVE = 0x800
# ip digit from 0|1-255|254 (template)
IP_DIG = "[%s-9]|(?:1[0-9]|[1-9])[0-9]|2[0-4][0-9]|25[0-%s]"
IP_DIG = r"[%s-9]|(?:1[0-9]|[1-9])[0-9]|2[0-4][0-9]|25[0-%s]"
# ip net 0-32
IP_NET_SUFFIX = "[0-9]|[12][0-9]|3[012]"
IP_NET_SUFFIX = r"[0-9]|[12][0-9]|3[012]"
# ip digs 1-254,0-254,0-255
IP_DIGS = {'dig1_254': IP_DIG % (1, 4), 'dig0_254': IP_DIG % (0, 4),
'dig0_255': IP_DIG % (0, 5), }
IP_DIGS = {r'dig1_254': IP_DIG % (1, 4), r'dig0_254': IP_DIG % (0, 4),
r'dig0_255': IP_DIG % (0, 5), }
# ip addr 10.0.0.12
IP_ADDR = "(%(dig1_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)\.(%(dig1_254)s)" % \
IP_ADDR = r"(%(dig1_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)\.(%(dig1_254)s)" % \
IP_DIGS
IP_MASK = "(%(dig0_255)s)\.(%(dig0_255)s)\.(%(dig0_255)s)\.(%(dig0_255)s)" % \
IP_MASK = r"(%(dig0_255)s)\.(%(dig0_255)s)\.(%(dig0_255)s)\.(%(dig0_255)s)" % \
IP_DIGS
# ip addr for net 10.0.0.0
IP_NET = "(%(dig1_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)" % \
IP_NET = r"(%(dig1_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)\.(%(dig0_254)s)" % \
IP_DIGS
# ip and net 192.168.0.0/16
IP_ADDR_NET = "(%(ipaddr)s)/((%(ipnet)s))" % {'ipaddr': IP_NET,
IP_ADDR_NET = r"(%(ipaddr)s)/((%(ipnet)s))" % {'ipaddr': IP_NET,
'ipnet': IP_NET_SUFFIX}
reIp = re.compile("^{0}$".format(IP_ADDR))
reNetSuffix = re.compile("^{0}$".format(IP_NET_SUFFIX))
reNet = re.compile("^{0}$".format(IP_ADDR_NET))
reMask = re.compile("^{0}$".format(IP_MASK))
reIp = re.compile(r"^{0}$".format(IP_ADDR))
reNetSuffix = re.compile(r"^{0}$".format(IP_NET_SUFFIX))
reNet = re.compile(r"^{0}$".format(IP_ADDR_NET))
reMask = re.compile(r"^{0}$".format(IP_MASK))
def checkIp(ip):
@ -218,7 +218,7 @@ def isDhcpIp(interface="eth0"):
leaseIp = \
map(lambda x: x.group(1),
filter(None,
map(re.compile('^ip_address=(.*)$').search,
map(re.compile(r'^ip_address=(.*)$').search,
process(dhcpcd, '-U', interface))))
if not curIp or leaseIp and leaseIp[0] == curIp:
return True
@ -230,7 +230,7 @@ def getRouteTable(onlyIface=()):
ipProg = checkUtils('/sbin/ip')
routes = process(ipProg, "route")
if onlyIface:
filterRe = re.compile("|".join(map(lambda x: r"dev %s" % x, onlyIface)))
filterRe = re.compile(r"|".join(map(lambda x: r"dev %s" % x, onlyIface)))
routes = filter(filterRe.search, routes)
for line in routes:
network, op, line = line.partition(" ")
@ -280,7 +280,13 @@ def getMaster(iface):
def getIp(iface):
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00' * 14)
print("DEBUG getIp")
print(socket.AF_INET)
print(type(socket.AF_INET))
tmp = '\x00' * 14
print(tmp)
print(type(tmp))
ifreq = struct.pack('16sH14s', iface.encode("UTF-8"), socket.AF_INET, b'\x00' * 14)
try:
res = fcntl.ioctl(sockfd, SIOCGIFADDR, ifreq)
except IOError:
@ -288,11 +294,13 @@ def getIp(iface):
finally:
sockfd.close()
ip = struct.unpack('16sH2x4s8x', res)[2]
print(ip)
print(type(ip))
return socket.inet_ntoa(ip)
def checkFlag(iface, flag):
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00' * 14)
ifreq = struct.pack('16sH14s', iface.encode("UTF-8"), socket.AF_INET, b'\x00' * 14)
try:
res = fcntl.ioctl(sockfd, SIOCGIFFLAGS, ifreq)
except IOError:

@ -104,9 +104,9 @@ class MountHelper(object):
return ar[:6] + [""] * (6 - len(ar))
self.cache = \
map(lambda x: setlen(map(lambda y: y.strip(), x.split())),
list(map(lambda x: setlen(list(map(lambda y: y.strip(), x.split()))),
filter(lambda x: x.strip() and not x.lstrip().startswith("#"),
self._readdata().split('\n')))
self._readdata().split('\n'))))
for data in self.cache:
convertDev = lambda x: (os.path.realpath(x)
if x.startswith('/') else x)
@ -114,7 +114,7 @@ class MountHelper(object):
name=convertDev(self.dictUUID.get(data[0], data[0]))
).get('DEVNAME', data[0])
data[1] = data[1] if data[2] != "swap" else "swap"
self.rotateCache = zip(*self.cache)
self.rotateCache = list(zip(*self.cache))
def getBy(self, what=DIR, where=NAME, _in=None, eq=None,
contains=None, noteq=None, allentry=False):
@ -127,7 +127,7 @@ class MountHelper(object):
filterfunc = lambda x: contains in x[where]
else:
filterfunc = lambda x: x[where] != noteq
res = map(lambda x: x[what], filter(filterfunc, self.cache))
res = list(map(lambda x: x[what], filter(filterfunc, self.cache)))
if allentry:
return res
else:
@ -135,10 +135,15 @@ class MountHelper(object):
def getFields(self, *fields):
"""Get all data by specifie fields"""
return zip(*reduce(lambda x, y: x + [self.rotateCache[y]], fields, []))
return list(zip(*reduce(lambda x, y: x + [self.rotateCache[y]], fields, [])))
def isReadonly(self, what=DIR, eq=None):
print("DEBUG isReadonly")
print(type(self.cache))
print(eq)
print(self.cache)
for data in filter(lambda x: x[what] == eq, self.cache):
print(data)
opts = data[self.OPTS].split(',')
if "ro" in opts:
return True
@ -153,6 +158,10 @@ 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):
@ -161,7 +170,7 @@ class MountHelper(object):
filterfunc = lambda x: x[what] == eq
else:
filterfunc = lambda x: x[what] != noteq
return bool(filter(filterfunc, self.cache))
return bool(list(filter(filterfunc, self.cache)))
class FStab(MountHelper):
@ -194,7 +203,7 @@ class DiskSpace(object):
data = p.read().strip()
lines = data.split('\n')
if len(lines) >= 2:
cols = filter(None, lines[1].split())
cols = list(filter(None, lines[1].split()))
if len(cols) == 6:
return int(cols[3])
raise DiskSpaceError(_("Wrong df output:\n%s") % data)
@ -205,8 +214,8 @@ class DiskSpace(object):
def commonPath(*paths):
"""Return common path from list of paths"""
paths = map(lambda x: os.path.normpath(x).split('/'), paths)
res = map(lambda x: x[0],
filter(lambda x: filter(lambda y: x[0] == y, x[1:]), zip(*paths)))
res = list(map(lambda x: x[0],
filter(lambda x: filter(lambda y: x[0] == y, x[1:]), zip(*paths))))
return "/".join(res)

@ -35,7 +35,8 @@ from .files import (getProgPath, find, process, listDirectory, readFile,
removeDir, removeFileWithEmptyDirectory, FindFileType)
from .tools import SavableIterator, ignore
from .system import SystemPath
from collections import Mapping, defaultdict
from collections.abc import Mapping
from collections import defaultdict
from .common import getTupleVersion
from contextlib import closing
from functools import total_ordering
@ -54,7 +55,7 @@ setLocalTranslate('cl_lib3', sys.modules[__name__])
VDB_PATH = 'var/db/pkg'
reVerSplit = re.compile(r"^(?:.*/%s/)?(?:(\w+-\w+)/)?(.*?)-(([^-]+?)"
"(?:-(r\d+))?)(?:.(tbz2))?$" % VDB_PATH, re.S)
r"(?:-(r\d+))?)(?:.(tbz2))?$" % VDB_PATH, re.S)
class RepositoryPath(object):
Layman = '/var/lib/layman'
@ -67,7 +68,8 @@ class RepositoryPath(object):
def reVerSplitToPV(x):
"""Convert match from reVerSplit to PV hash"""
if type(x) in (str, unicode):
# if type(x) in (str, unicode):
if isinstance(x, str):
x = reVerSplit.search(x)
if x:
match = x.groups()
@ -234,7 +236,7 @@ class RepositorySubstituting(object):
занимает время, то объек извлекает данные из переменной только при
необходимости: в строке найдено repository:
"""
token = re.compile("^\w+:")
token = re.compile(r"^\w+:")
def __init__(self, dv, system_root=''):
self.dv = dv
@ -251,7 +253,7 @@ class RepositorySubstituting(object):
if emerge_config and emerge_config.repositories:
repos = {x.name.encode('utf-8'): x.location.encode('utf-8')
for x in emerge_config.repositories}
r = re.compile("|".join("^%s:" % x for x in repos.keys()))
r = re.compile(r"|".join(r"^%s:" % x for x in repos.keys()))
self._substitution = (
functools.partial(
r.sub, lambda *args: "%s%s/profiles/" % (
@ -295,7 +297,7 @@ class ReposConf(object):
def add_default(self, config):
if config["DEFAULT"].get("main-repo") is None:
config["DEFAULT"]["main-repo"] = "gentoo"
config["DEFAULT"]["main-repo"] = r"gentoo"
def add(self, rname, rurl, rpath):
if not self.conffile:
@ -335,7 +337,7 @@ class ReposConf(object):
config = ConfigParser(strict=False)
config.read(conffile, encoding="utf-8")
for rep in config.sections():
if rep != "gentoo":
if rep != r"gentoo":
location = config[rep]["location"]
if location:
yield rep, location
@ -453,7 +455,7 @@ class Layman(object):
if path.exists(self.makeconf):
content = readFile(self.makeconf)
if self.portdir_param in content:
new_content = re.sub('\A%s="([^\"]+)"' % self.portdir_param,
new_content = re.sub(r'\A%s="([^\"]+)"' % self.portdir_param,
fixContent, content, re.DOTALL)
if new_content == content:
return
@ -480,7 +482,7 @@ class Layman(object):
if path.exists(self.makeconf):
content = readFile(self.makeconf)
if self.portdir_param in content:
new_content = re.sub('\A%s="([^\"]+)"' % self.portdir_param,
new_content = re.sub(r'\A%s="([^\"]+)"' % self.portdir_param,
fixContent, content, re.DOTALL)
if new_content == content:
return
@ -561,7 +563,7 @@ class EmergePackage(Mapping):
со строкой, содержащей версию. Сравнение выполняется по категория/имя, затем
по версии
"""
default_repo = 'gentoo'
default_repo = r'gentoo'
prefix = r"(?:.*/%s/|=)?" % VDB_PATH
category = r"(?:(\w+(?:-\w+)?)/)?"
pn = "([^/:]*?)"
@ -695,7 +697,7 @@ class PackageInformation:
timeout=60).read()
except pexpect.TIMEOUT:
output = ""
re_cut = re.compile("^.*?(?=<\?xml version)", re.S)
re_cut = re.compile(r"^.*?(?=<\?xml version)", re.S)
with ignore(ET.ParseError):
xml = ET.fromstring(re_cut.sub('', output))
for pkg in self.query_packages:
@ -720,7 +722,7 @@ class UnmergePackage(EmergePackage):
"""
Информация об обновлении одного пакета
"""
re_pkg_info = re.compile("^\s(\S+)\n\s+selected:\s(\S+)", re.MULTILINE)
re_pkg_info = re.compile(r"^\s(\S+)\n\s+selected:\s(\S+)", re.MULTILINE)
def __init__(self, package):
super(UnmergePackage, self).__init__(package)
@ -756,10 +758,10 @@ class EmergeUpdateInfo(Mapping):
Информация об обновлении одного пакета
"""
install_info = "\[(binary|ebuild)([^\]]+)\]"
install_info = r"\[(binary|ebuild)([^\]]+)\]"
atom_info = r"\S+"
use_info = 'USE="[^"]+"'
prev_version = "\[(?:[^,\]]+, )*([^\]]+)\]"
use_info = r'USE="[^"]+"'
prev_version = r"\[(?:[^,\]]+, )*([^\]]+)\]"
pkg_size = r"[\d,]+ \w+"
attrs = ['binary', 'REPLACING_VERSIONS', 'SIZE', 'new', 'newslot',
@ -832,7 +834,7 @@ class EmergeRemoveInfo(EmergeUpdateInfo):
"""
Информация об удалении одного пакета (в списке обновляемых пакетов)
"""
install_info = "\[(uninstall)([^\]]+)\]"
install_info = r"\[(uninstall)([^\]]+)\]"
class Eix(object):
@ -1277,7 +1279,7 @@ class Manifest:
Объект используется для получения данных из Manifest
файлов портежей
"""
re_dist = re.compile("^DIST\s*(\S+)\s*")
re_dist = re.compile(r"^DIST\s*(\S+)\s*")
def __init__(self, manifest):
self._manifest = manifest
@ -1423,10 +1425,10 @@ class InstalledPackageInfo(object):
"""
Информация об установленном пакете (DEPEND) из /var/db/pkg
"""
depend_pattern = 'declare (?:-x )?({0})="([^"]+)"'
depend_pattern = r'declare (?:-x )?({0})="([^"]+)"'
re_depend = re.compile(depend_pattern.format(
"|".join(EbuildInfo.support_keys)), re.DOTALL)
re_multispace = re.compile("\s+", re.DOTALL)
r"|".join(EbuildInfo.support_keys)), re.DOTALL)
re_multispace = re.compile(r"\s+", re.DOTALL)
def __init__(self, atom, pkg_dir):
self.atom = atom
@ -1505,7 +1507,7 @@ def getlibpaths(prefix="/"):
return sorted(list(set([path.normpath(x) for x in rval if x])))
_re_req_arches = re.compile("(\w+:\s.*?)(?=\s\w+:|$)")
_re_req_arches = re.compile(r"(\w+:\s.*?)(?=\s\w+:|$)")
class LibraryProviders(Mapping):
@ -1535,7 +1537,7 @@ class LibraryProviders(Mapping):
if arch not in self.data:
self.data[arch] = defaultdict(list)
for library in list(set(
re.findall("^(?:sym|obj)\s+(?:%s)/(%s)\s+" % (
re.findall(r"^(?:sym|obj)\s+(?:%s)/(%s)\s+" % (
pattern_libpath, "|".join(
re.escape(x) for x in libraries.split())),
content, flags=re.M))):
@ -1824,5 +1826,5 @@ class PortageState(object):
for dn in self.paths:
fdn = pathJoin(self.prefix, dn)
for data in self.getpathdata(fdn):
m.update(data)
m.update(data.encode("UTF-8"))
return m.hexdigest()

@ -75,25 +75,25 @@ class SystemType(object):
@classmethod
def detect_container(cls):
if grepFile("/proc/cpuinfo", "UML"):
if grepFile(r"/proc/cpuinfo", r"UML"):
return cls.Uml
elif grepFile("/proc/self/status",
"(s_context|VxID):\s*[1-9]"):
elif grepFile(r"/proc/self/status",
r"(s_context|VxID):\s*[1-9]"):
return cls.VServer
elif (path.exists("/proc/vz/veinfo")
and not path.exists("/proc/vz/version")):
elif (path.exists(r"/proc/vz/veinfo")
and not path.exists(r"/proc/vz/version")):
return cls.OpenVZ
elif grepFile("/proc/self/status", "envID:\s*[1-9]"):
elif grepFile(r"/proc/self/status", r"envID:\s*[1-9]"):
return cls.OpenVZ #old test
elif grepFile("/proc/1/environ", "container=lxc"):
elif grepFile(r"/proc/1/environ", r"container=lxc"):
return cls.LXC
elif grepFile("/proc/1/environ", "container=rkt"):
elif grepFile(r"/proc/1/environ", r"container=rkt"):
return cls.Rkt
elif grepFile("/proc/1/environ", "container=systemd-nspawn"):
elif grepFile(r"/proc/1/environ", r"container=systemd-nspawn"):
return cls.SystemdNSpawn
elif path.exists("/.dockerenv"):
elif path.exists(r"/.dockerenv"):
return cls.Docker
elif grepFile("/proc/1/environ", "container=docker"):
elif grepFile(r"/proc/1/environ", r"container=docker"):
return cls.Docker
return cls.NotDetected

@ -333,7 +333,7 @@ def str2list(s):
'\s* # end value
""" % {"v": value}
reList = re.compile(element, re.X)
reMatchList = re.compile("""
reMatchList = re.compile(r"""
^\[ # begin dict
((%(v)s,)* # many elements with comma at end
%(v)s)? # element without comma
@ -352,7 +352,7 @@ def list2str(list):
Return string with escaped \ and '.
"""
replaceSlash = MultiReplace({'\\': '\\\\', '\'': '\\\''})
replaceSlash = MultiReplace({r'\\': r'\\\\', r'\'': r'\\\''})
return "[%s]" % ','.join(["'%s'" % replaceSlash(str(i))
for i in list])
@ -362,7 +362,7 @@ def dict2str(dict):
Return string with escaped \ and '.
"""
replaceSlash = MultiReplace({'\\': '\\\\', '\'': '\\\''})
replaceSlash = MultiReplace({r'\\': r'\\\\', r'\'': r'\\\''})
return '{%s}' % ','.join(["'%s':'%s'" % (str(k), replaceSlash(str(v))) \
for (k, v) in dict.items()])
@ -378,10 +378,10 @@ def convertStrListDict(val):
# else it is string
else:
# detect dictionary
if re.match("^{.*}$", val):
if re.match(r"^{.*}$", val):
return str2dict(val)
# detect list
elif re.match("^\[.*\]$", val):
elif re.match(r"^\[.*\]$", val):
return str2list(val)
# else is simple string
else:

@ -16,7 +16,8 @@
import os
from calculate.lib.utils.files import readFile
from collections import Mapping, deque
from collections import deque
from collections.abc import Mapping
from os import path
import json
from functools import wraps

@ -35,10 +35,10 @@ class EdidInfoError(Exception):
pass
class EdidInfo(object):
reBaseEDID = re.compile("\nBlock \d, Base EDID:.*?\nChecksum:",
reBaseEDID = re.compile(r"\nBlock \d, Base EDID:.*?\nChecksum:",
re.S)
reDTD = re.compile(r"DTD\s+\d+:\s*(\d+x\d+)\s+(?:[0-9.]+\s+Hz)"
"\s+(\d+:\d+)\s+[^(]+\((\d+) mm x (\d+) mm\)")
r"\s+(\d+:\d+)\s+[^(]+\((\d+) mm x (\d+) mm\)")
def __init__(self):
self.edid_decode = getProgPath('/usr/bin/edid-decode')

@ -39,7 +39,7 @@ class VariableOsX11Resolution(Variable):
except (FilesError, OSError):
return ""
lines = processXDpy.readlines()
reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels")
reRes = re.compile(r"dimensions:\s+(\d+)x(\d+)\s+pixels")
searchRes = False
for line in lines:
searchRes = reRes.search(line)
@ -63,34 +63,34 @@ class VariableOsX11Resolution(Variable):
with open(xlog, 'r') as f:
logdata = f.read()
for re_pat in (
"Output [\S]+ using initial mode (\d+)x(\d+)",
"Virtual screen size determined to be"
" ([0-9]+)\s*x\s*([0-9]+)",
'Setting mode "(\d+)x(\d+)[0-9@]"',
"Virtual size is (\d+)x(\d+)"):
r"Output [\S]+ using initial mode (\d+)x(\d+)",
r"Virtual screen size determined to be"
r" ([0-9]+)\s*x\s*([0-9]+)",
r'Setting mode "(\d+)x(\d+)[0-9@]"',
r"Virtual size is (\d+)x(\d+)"):
reXorgLogParser = re.compile(re_pat, re.S)
resXorgLogParser = reXorgLogParser.search(logdata)
if resXorgLogParser:
return "%sx%s" % filter(lambda x: x,
resXorgLogParser.groups())[:2]
tmp = list(filter(lambda x: x, resXorgLogParser.groups()))
return "%sx%s" % tuple(tmp[:2])
# get resolution from xorg.conf
xorgconf = "/etc/X11/xorg.conf"
reScreenSections = re.compile('Section "Screen"(.*?)EndSection',
reScreenSections = re.compile(r'Section "Screen"(.*?)EndSection',
re.S)
reModes = re.compile('Modes\s+"(\d+x\d+)')
reModes = re.compile(r'Modes\s+"(\d+x\d+)')
if os.access(xorgconf, os.R_OK):
sectionsScreen = filter(lambda x: "Modes" in x,
reScreenSections.findall(
readFile('/etc/X11/xorg.conf')))
modes = map(lambda x: x.groups()[0],
modes = list(map(lambda x: x.groups()[0],
filter(lambda x: x,
map(reModes.search, sectionsScreen)))
map(reModes.search, sectionsScreen))))
if modes:
return max(modes, key=lambda x: int(x.partition('x')[0]))
# get resolution from command line
reRightResolution = re.compile("^(\d+x\d+|auto)$", re.S)
reRightResolution = re.compile(r"^(\d+x\d+|auto)$", re.S)
kernelResolution = getValueFromCmdLine(
CmdlineParams.Calculate, CmdlineParams.Resolution)
if kernelResolution and reRightResolution.match(kernelResolution):
@ -207,9 +207,9 @@ class VariableClResolutions(Variable):
def get(self):
if self.Get('cl_chroot_status') == 'off':
try:
values = filter(None, list({
values = list(filter(None, list({
self.Get('install.os_install_fb_resolution'),
self.Get('install.os_install_x11_resolution')}))
self.Get('install.os_install_x11_resolution')})))
if values:
return values
except DataVarsError:

@ -521,7 +521,7 @@ class VariableClRepositoryData(ReadonlyTableVariable):
def parse_repository_block(self, i):
text = "\n".join(i)
re_block = re.compile("^(\w+)$\n\s+location: (.*)$", re.M)
re_block = re.compile(r"^(\w+)$\n\s+location: (.*)$", re.M)
return re_block.findall(text)
def from_portdir_vars(self, info):
@ -833,7 +833,7 @@ class VariableOsPython(ReadonlyVariable):
chroot_path = self.get_root()
if chroot_path == "/":
p = process("/usr/bin/emerge","--version")
m = re.search("python (\d\.\d)", p.read())
m = re.search(r"python (\d\.\d)", p.read())
if m:
return "python%s" % m.group(1)
pythons = readFileEx(pathJoin(chroot_path,

@ -82,7 +82,7 @@ class VariableHrCpuNum(ReadonlyVariable):
class VariableHrCpuName(ReadonlyVariable):
def get(self):
cpuinfo_file = "/proc/cpuinfo"
re_model_name = re.compile("^model name\s*:\s*(.*)$", re.M)
re_model_name = re.compile(r"^model name\s*:\s*(.*)$", re.M)
res = re_model_name.search(readFile(cpuinfo_file))
if res:
return res.group(1).strip()
@ -97,7 +97,7 @@ class VariableHrVirtual(ReadonlyVariable):
virt_sys_dict = {'VirtualBox': 'virtualbox',
'VMware': 'vmware',
'Qumranet': 'qemu'}
re_virt_info = re.compile("|".join(virt_sys_dict.keys()))
re_virt_info = re.compile(r"|".join(virt_sys_dict.keys()))
devices = lspci(re_virt_info.search)
for device in devices.values():
name_res = re_virt_info.search(device['name'])

@ -81,10 +81,10 @@ class Linux(VariableInterface):
if path.exists(inifile):
with open(inifile) as f:
data = f.readlins()
short_name_list = filter(
short_name_list = list(filter(
None, map(lambda x: (len(x.split("=")) == 2 and
x.split("=")[0] == "calculate" and
x.split("=")[1].strip()), data))
x.split("=")[1].strip()), data)))
if short_name_list:
return short_name_list[0]
@ -126,27 +126,27 @@ class Linux(VariableInterface):
(len(x.split("=")) == 2 and
x.split("=")[0] == "linuxver" and
x.split("=")[1].strip()), data))
if ver_list:
re_ver = re.compile("^(\d+\.)*\d$", re.S)
re_res = filter(re_ver.search, ver_list)
if not ver_list.isEmpty():
re_ver = re.compile(r"^(\d+\.)*\d$", re.S)
re_res = list(filter(re_ver.search, ver_list))
if re_res:
return re_res[0]
def getVersionFromGentooFiles(self, systemroot):
"""Get version from gentoo files"""
gentoo_file = path.join(systemroot, "etc/gentoo-release")
re_ver = re.compile("^(\d+\.)*\d+$", re.S)
re_ver = re.compile(r"^(\d+\.)*\d+$", re.S)
if path.exists(gentoo_file):
gentoo_link = self.Get('cl_make_profile')
if path.islink(gentoo_link):
vers = filter(re_ver.search,
os.readlink(gentoo_link).split('/'))
vers = list(filter(re_ver.search,
os.readlink(gentoo_link).split('/')))
if vers:
return vers[-1]
def getVersionFromUname(self):
"""Get version from uname"""
re_ver = re.search("^(\d+\.)*\d", platform.release(), re.S)
re_ver = re.search(r"^(\d+\.)*\d", platform.release(), re.S)
if re_ver:
return re_ver.group()

@ -61,26 +61,28 @@ class VariableOsRootDev(ReadonlyVariable):
def get(self):
"""Root filesystem device"""
record = readFile('/proc/cmdline').strip()
re_resRealRoot = re.search('(?:^|\s)real_root=(\S+)(\s|$)', record)
re_resFakeRoot = re.search('(?:^|\s)root=(\S+)(\s|$)', record)
re_resRealRoot = re.search(r'(?:^|\s)real_root=(\S+)(\s|$)', record)
re_resFakeRoot = re.search(r'(?:^|\s)root=(\S+)(\s|$)', record)
# param real_root priority that root
re_res = re_resRealRoot or re_resFakeRoot
if re_res:
rootparam = re_res.group(1)
# check root for /dev/sd view
if re.match("^/dev/[a-z]+.*$", rootparam):
if re.match(r"^/dev/[a-z]+.*$", rootparam):
return device.udev.get_device_info(
name=rootparam.strip()).get('DEVNAME', rootparam)
# check root set by uuid
if re.match("^UUID=.*$", rootparam):
if re.match(r"^UUID=.*$", rootparam):
uuid = rootparam[5:].strip("\"'")
blkid_process = process('/sbin/blkid', '-c', '/dev/null', '-U',
uuid)
if blkid_process.success():
print("DEBUG var OsRootDev")
print(blkid_process.read())
return device.udev.get_device_info(
name=blkid_process.read().strip()).get('DEVNAME', '')
# check root set by label
if re.match("^LABEL=.*$", rootparam):
if re.match(r"^LABEL=.*$", rootparam):
uuid = rootparam[6:].strip("\"'")
blkid_process = process('/sbin/blkid', '-c', '/dev/null', '-L',
uuid)

@ -125,7 +125,7 @@ class VariableUrGroup(ReadonlyVariable):
def get(self):
gid = self.Get('ur_gid')
try:
return grp.getgrgid(gid).gr_name
return grp.getgrgid(str(gid)).gr_name
except (KeyError, TypeError):
return ""

Loading…
Cancel
Save