fixes for datavars

master
idziubenko 3 years ago
parent b7d9ee35a5
commit 1391332af2

@ -294,30 +294,16 @@ 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" % 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:
@ -350,21 +336,12 @@ class Variable(VariableInterface):
"""
Get zipped values of variables specified by list 'argvVarNames'
"""
print("Im zipVars")
if "humanreadable" in kw:
hr = kw['humanreadable']
# return zip(*list(map(lambda x:self.Get(x, humanreadable=hr),
# argvVarNames)))
return list(zip(*map(lambda x:self.Get(x, humanreadable=hr),
argvVarNames)))
else:
print("beep")
print(argvVarNames)
tt = self.Get(argvVarNames[0])
print(tt)
raise Exception
tmp = list(map(self.Get, argvVarNames))
print(tmp)
return zip(*tmp)
return list(zip(*map(self.Get, argvVarNames)))
def _get_format_value(self):
return self._value_formatter.format(
@ -376,15 +353,9 @@ class Variable(VariableInterface):
Calculate value method
"""
if self.__class__.value_format:
val = self._get_format_value()
# print("DEBUG get - value_format")
# print(val)
return val
return self._get_format_value()
if self.__class__.value:
val = self.__class__.value
# print("DEBUG get - value")
# print(val)
return val
return self.__class__.value
else:
return [] if "list" in self.type else ""
@ -455,22 +426,18 @@ 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()
@ -481,15 +448,10 @@ class Variable(VariableInterface):
self.value = 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):
@ -508,7 +470,7 @@ class Variable(VariableInterface):
if isinstance(res, GeneratorType):
res = tuple(res)
if res and type(res[0]) in (tuple, list):
return zip(*res)
return list(zip(*res))
else:
return res, None
@ -1110,14 +1072,12 @@ class SimpleDataVars(object):
"""
Get zipped values of variables specified by list '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)))
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))
def select(self, *fields, **kw):
"""
@ -1184,7 +1144,6 @@ 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:
@ -1209,15 +1168,10 @@ 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:]
@ -1227,12 +1181,6 @@ 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:
@ -1496,15 +1444,15 @@ class DataVars(SimpleDataVars):
def Get(self, varname, humanreadable=HumanReadable.No):
"""Threading safety Get"""
if varname in ["install.os_lvm_data"]:
print("DEBUG datavars 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")
# if varname in ["install.os_lvm_data"]:
# print("DEBUG AFTER")
finally:
DataVars.l.release()
@ -1519,21 +1467,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))
# 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
# 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)
@ -1547,8 +1495,8 @@ 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")
# if varname in ["install.os_lvm_data"]:
# print("DEBUG in __GET")
section, varname = self.splitVarname(varname)
if (varname not in self.loadVariables or
@ -1565,8 +1513,8 @@ class DataVars(SimpleDataVars):
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 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,
@ -1585,8 +1533,6 @@ 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):

@ -86,9 +86,9 @@ from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3', sys.modules[__name__])
reSearch = lambda pattern, listar: map(lambda x: x.groups(),
reSearch = lambda pattern, listar: list(map(lambda x: x.groups(),
filter(None,
map(pattern.search, listar)))
map(pattern.search, listar))))
class FilesError(Exception):
@ -762,16 +762,16 @@ def listDirectory(directory, fullPath=False, onlyDir=False):
try:
if fullPath:
if onlyDir:
return filter(lambda x: path.isdir(x),
return list(filter(lambda x: path.isdir(x),
map(lambda x: path.join(directory, x),
os.listdir(directory)))
os.listdir(directory))))
else:
return map(lambda x: path.join(directory, x),
os.listdir(directory))
return list(map(lambda x: path.join(directory, x),
os.listdir(directory)))
else:
if onlyDir:
return filter(lambda x: path.isdir(path.join(directory, x)),
os.listdir(directory))
return list(filter(lambda x: path.isdir(path.join(directory, x)),
os.listdir(directory)))
else:
return os.listdir(directory)
except OSError:
@ -945,10 +945,9 @@ def getCmdLineParam(paramName):
"""
cmdLine = '/proc/cmdline'
paramName = "%s=" % paramName
params = \
map(lambda x: x.partition('=')[2],
filter(lambda x: x.startswith(paramName),
readFile(cmdLine).split(' ')))
params = list(map(lambda x: x.partition('=')[2],
filter(lambda x: x.startswith(paramName),
readFile(cmdLine).split(' '))))
if params:
return params[-1]
else:
@ -1122,10 +1121,10 @@ def getLoopFromPath(directory):
losetup = getProgPath('losetup')
p = process(losetup, '-a')
rePattern = re.compile(r'(^/dev/loop[^:]+)[^(]+\(([^)]+)\).*')
return map(lambda x: x[0],
return list(map(lambda x: x[0],
filter(lambda x: x[1].startswith(directory),
reSearch(rePattern,
p.readlines())))
p.readlines()))))
def getMdRaidDevices():
@ -1765,15 +1764,15 @@ def getRunCommands(not_chroot=False, chroot=None, uid=None, withpid=False,
if not os.access('/proc', os.R_OK):
return []
if withpid:
return filter(lambda x: x[1],
return list(filter(lambda x: x[1],
map(lambda x:(x,getCmd(x)),
filter(lambda x: x.isdigit(),
listDirectory('/proc'))))
listDirectory('/proc')))))
else:
return filter(None,
return list(filter(None,
map(getCmd,
filter(lambda x: x.isdigit(),
listDirectory('/proc'))))
listDirectory('/proc')))))
class XAttrError(Exception):
pass
@ -1788,11 +1787,11 @@ class xattr(object):
if p.success():
return p.read()
err = p.readerr()
raise XAttrError(err.partition(":")[2].strip())
raise XAttrError(err.partition(b":")[2].strip())
@classmethod
def set(cls, dn, attrname, value):
p = process(cls.setfattr, "-n", attrname, "-v", value, dn)
if not p.success():
err = p.readerr()
raise XAttrError(err.rpartition(":")[2].strip())
raise XAttrError(err.rpartition(b":")[2].strip())

@ -280,12 +280,6 @@ def getMaster(iface):
def getIp(iface):
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
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)
@ -294,8 +288,6 @@ 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):
@ -323,7 +315,7 @@ def getMask(iface):
Get mask for interface
"""
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, SIOCGIFNETMASK, ifreq)
except IOError:
@ -344,7 +336,7 @@ def getMac(iface):
Get mac for interface
"""
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifreq = struct.pack('16sH14s', iface, socket.AF_UNIX, '\x00' * 14)
ifreq = struct.pack('16sH14s', iface.encode("UTF-8"), socket.AF_UNIX, b'\x00' * 14)
try:
res = fcntl.ioctl(sockfd, SIOCGIFHWADDR, ifreq)
except IOError:

@ -138,12 +138,7 @@ class MountHelper(object):
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

@ -94,11 +94,11 @@ def getPkgUses(fullpkg, version=None, prefix="/"):
_pkgCategory = '{0}/{1}'.format(VDB_PATH, category)
pkgCategory = path.join(prefix, _pkgCategory)
if version is None:
packages = filter(lambda x: x['PN'] == pkg,
packages = list(filter(lambda x: x['PN'] == pkg,
map(reVerSplitToPV,
filter(lambda x: x,
map(lambda x: reVerSplit.search(x),
listDirectory(pkgCategory)))))
listDirectory(pkgCategory))))))
if not packages:
return None
usePath = path.join(pkgCategory, packages[-1]['PF'], "USE")
@ -108,12 +108,12 @@ def getPkgUses(fullpkg, version=None, prefix="/"):
iusePath = path.join(pkgCategory, "%s-%s" % (pkg, version), "IUSE")
iuse = readFile(iusePath).strip().split()
use = readFile(usePath).strip().split()
return (map(lambda x: x[1:] if x.startswith("+") else x,
return (list(map(lambda x: x[1:] if x.startswith("+") else x,
filter(lambda x: x,
use)),
map(lambda x: x[1:] if x.startswith("+") else x,
use))),
list(map(lambda x: x[1:] if x.startswith("+") else x,
filter(lambda x: x,
iuse)))
iuse))))
def isPkgInstalled(pkg, prefix='/', sortByVersion=False):
@ -135,10 +135,10 @@ def isPkgInstalled(pkg, prefix='/', sortByVersion=False):
else:
return res
else:
return filter(lambda x: filter(lambda y: y['PN'] == pkg,
return list(filter(lambda x: filter(lambda y: y['PN'] == pkg,
map(reVerSplitToPV,
listDirectory(x))),
listDirectory(pkgDir, fullPath=True))
listDirectory(pkgDir, fullPath=True)))
def getPkgSlot(pkg, prefix='/'):
@ -251,7 +251,7 @@ class RepositorySubstituting(object):
# TODO: проверка выхода за chroot
emerge_config = self.dv.Get('cl_emerge_config')
if emerge_config and emerge_config.repositories:
repos = {x.name.encode('utf-8'): x.location.encode('utf-8')
repos = {x.name: x.location
for x in emerge_config.repositories}
r = re.compile(r"|".join(r"^%s:" % x for x in repos.keys()))
self._substitution = (
@ -491,9 +491,9 @@ class Layman(object):
def is_new_layman(self):
layman_pkg_info = isPkgInstalled(self.layman_package,
prefix=self.prefix.encode('utf-8'))
prefix=self.prefix)
portage_pkg_info = isPkgInstalled(self.portage_package,
prefix=self.prefix.encode('utf-8'))
prefix=self.prefix)
if layman_pkg_info and portage_pkg_info:
layman_ver = layman_pkg_info[0].get('PV')
portage_ver = portage_pkg_info[0].get('PV')
@ -1238,10 +1238,10 @@ class PackageList(object):
def _packages(self):
if self.result is None:
self.result = filter(lambda x: x['PN'],
self.result = list(filter(lambda x: x['PN'],
map(lambda x: (x if isinstance(x, Mapping)
else EmergePackage(x)),
self._raw_list))
self._raw_list)))
return self.result
def __getitem__(self, item):
@ -1288,10 +1288,10 @@ class Manifest:
"""
Получить список файлов из Manifest
"""
return map(lambda x: x.group(1),
return list(map(lambda x: x.group(1),
filter(None,
map(self.re_dist.search,
readLinesFile(self._manifest))))
readLinesFile(self._manifest)))))
class Ebuild:

@ -117,9 +117,9 @@ class VariableClTemplateCltPath(ReadonlyVariable):
else:
protect_paths = ["/etc", "/usr/share/X11/xkb", "var/lib/hsqldb",
"/usr/share/config"]
return filter(path.exists,
return list(filter(path.exists,
map(lambda x: pathJoin(chroot, x),
protect_paths))
protect_paths)))
class VariableClRootPath(Variable):
@ -377,7 +377,7 @@ class VariableClConfigProtectMask(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "CONFIG_PROTECT_MASK" in emerge_config:
return emerge_config['CONFIG_PROTECT_MASK'].encode('utf-8').split()
return emerge_config['CONFIG_PROTECT_MASK'].split()
display_env = process('/bin/bash', "-c", "source /etc/profile;env",
stdout=PIPE)
for line in display_env:
@ -398,7 +398,8 @@ class VariableClConfigProtect(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "CONFIG_PROTECT" in emerge_config:
return emerge_config['CONFIG_PROTECT'].encode('utf-8').split()
return emerge_config['CONFIG_PROTECT'].split()
# return emerge_config['CONFIG_PROTECT'].encode('utf-8').split()
display_env = process('/bin/bash', "-c", "source /etc/profile;env",
stdout=PIPE)
for line in display_env:
@ -466,7 +467,8 @@ class VariableClPkgdir(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "PKGDIR" in emerge_config:
return emerge_config['PKGDIR'].encode('utf-8')
# return emerge_config['PKGDIR'].encode('utf-8')
return emerge_config['PKGDIR']
else:
emerge_info = self.Get('cl_emerge_info')
for line in filter(lambda x: x.startswith("PKGDIR="),
@ -484,14 +486,15 @@ class VariableClFeatures(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "FEATURES" in emerge_config:
return filter(
None, emerge_config['FEATURES'].encode('utf-8').split())
return list(filter(
# None, emerge_config['FEATURES'].encode('utf-8').split()))
None, emerge_config['FEATURES'].split()))
else:
emerge_info = self.Get('cl_emerge_info')
for line in filter(lambda x: x.startswith("FEATURES="),
emerge_info):
return filter(
None, line.partition("=")[2].strip('\n"\'').split())
return list(filter(
None, line.partition("=")[2].strip('\n"\'').split()))
return ""
@ -503,7 +506,8 @@ class VariableClDistdir(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "DISTDIR" in emerge_config:
return emerge_config['DISTDIR'].encode('utf-8')
# return emerge_config['DISTDIR'].encode('utf-8')
return emerge_config['DISTDIR']
return "/var/calculate/remote/distfiles"
@ -540,8 +544,9 @@ class VariableClRepositoryData(ReadonlyTableVariable):
def get(self, hr=HumanReadable.No):
emerge_config = self.Get('cl_emerge_config')
if emerge_config and "PKGDIR" in emerge_config:
return [[repo.name.encode('UTF-8'), repo.location.encode('UTF-8')]
tmp = [[repo.name, repo.location]
for repo in emerge_config.repositories]
return tmp
else:
info = self.Get("cl_emerge_info")
if self.portage_ver_ge("2.2.18"):
@ -677,7 +682,7 @@ class VariableClEmergeConfig(ReadonlyVariable):
c = PortageConfigWrapper.getconfig_chroot(self.systemRoot)
c.__str__ = lambda self: "EmergeConfig"
return c
except Exception:
except Exception as e:
pass
return ""
@ -690,7 +695,8 @@ class VariableClEmergeDefaultOpts(ReadonlyVariable):
def get(self):
emerge_config = self.Get('cl_emerge_config')
if emerge_config:
return emerge_config['EMERGE_DEFAULT_OPTS'].encode('UTF-8')
# return emerge_config['EMERGE_DEFAULT_OPTS'].encode('UTF-8')
return emerge_config['EMERGE_DEFAULT_OPTS']
else:
emerge_info = self.Get('cl_emerge_info')
for line in filter(lambda x: x.startswith("EMERGE_DEFAULT_OPTS="),
@ -733,8 +739,8 @@ class VariableClTemplatesLocate(Variable):
return vals + ['clt']
def choice(self):
return map(lambda x: (x, self.descriptionMap.get(x, x)),
self.get())
return list(map(lambda x: (x, self.descriptionMap.get(x, x)),
self.get()))
class VariableClTemplatePathUse(ReadonlyVariable):

@ -75,8 +75,8 @@ class VariableHrCpuNum(ReadonlyVariable):
def get(self):
cpuinfo_file = "/proc/cpuinfo"
return str(len(filter(lambda x: x.startswith("processor"),
readLinesFile(cpuinfo_file))) or 1)
return str(len(list(filter(lambda x: x.startswith("processor"),
readLinesFile(cpuinfo_file)))) or 1)
class VariableHrCpuName(ReadonlyVariable):

@ -257,7 +257,7 @@ class VariableOsLinuxPkglist(Variable):
'os_linux_shortname',
raw=True,
fallback=''))
yield value.encode('utf-8')
yield value
def get(self):
make_profile = self.Get('cl_make_profile')

@ -493,8 +493,8 @@ class Locale(object):
return [x for x in self.langData.keys() if x not in skip]
def getLanguages(self):
return map(lambda x: self.langData[x]['language'],
self.langData.keys())
return list(map(lambda x: self.langData[x]['language'],
self.langData.keys()))
def isLangExists(self, lang):
return lang in self.langData.keys()
@ -765,7 +765,7 @@ class VariableOsLang(ReadonlyVariable, Locale):
return self.getLangs()
def humanReadable(self):
return map(lambda x: self.getName(x), self.Get())
return list(map(lambda x: self.getName(x), self.Get()))
class VariableOsKeyboardLayout(ReadonlyVariable, Locale):
"""
@ -777,4 +777,4 @@ class VariableOsKeyboardLayout(ReadonlyVariable, Locale):
return self.getKeyboardLayouts()
def humanReadable(self):
return map(lambda x: self.getLayoutname(x), self.Get())
return list(map(lambda x: self.getLayoutname(x), self.Get()))

@ -77,8 +77,6 @@ class VariableOsRootDev(ReadonlyVariable):
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
@ -114,8 +112,8 @@ class VariableOsMapperRootDev(ReadonlyVariable):
dev_links = device.udev.get_device_info(
name=rootdev).get("DEVLINKS", "")
if dev_links:
mapper_name = filter(lambda x: "/dev/mapper" in x,
dev_links.split())
mapper_name = list(filter(lambda x: "/dev/mapper" in x,
dev_links.split()))
if mapper_name:
return mapper_name[0]
return rootdev

@ -67,11 +67,11 @@ class LdapHelper(object):
user_obj = self.getLdapUserObject()
if ldapUser and isinstance(user_obj, ldapUser):
if user_obj.connectLdap():
return map(lambda x: x[0][1]['uid'][0],
return list(map(lambda x: x[0][1]['uid'][0],
user_obj.ldapObj.ldapSearch(
user_obj.getUsersDN(),
ldap.SCOPE_ONELEVEL, '(objectClass=*)',
['uid']))
['uid'])))
return []

Loading…
Cancel
Save