Merge branch 'py3_forced'

master
idziubenko 3 years ago
commit b23b15293a

6
.gitignore vendored

@ -0,0 +1,6 @@
revert_changes_to_vmachine
push_to_vmachine*
.vscode
*.pyc
*.pyo
*.bak

@ -52,7 +52,7 @@ from functools import reduce
setLocalTranslate('cl_install3', sys.modules[__name__])
class DefaultMountPath(object):
class DefaultMountPath():
"""
Пути по умолчанию для монтирования образов
"""
@ -119,7 +119,7 @@ def progressCopyFile(source, dest):
bufsize = (100 - (size % 100) + size) / 100
with open(source, 'rb') as infile:
with open(dest, 'w') as outfile:
for i in xrange(1, 101):
for i in range(1, 101):
outfile.write(infile.read(bufsize))
yield i
@ -129,12 +129,12 @@ class DistributiveError(Exception):
pass
class Distributive(object):
class Distributive():
"""
Distributive object. Parent object for all distributive.
"""
class Type(object):
class Type():
Directory = "dir"
Partition = "part"
SquashFS = "squash"
@ -374,10 +374,10 @@ class Distributive(object):
joinFrom = partial(path.join, fromdir)
params = [cpCmd, "-x"] + \
(["--no-preserve=mode,ownership"] if noperm else ["-a"]) + \
map(joinFrom,
ifilterfalse(byfile or operator.not_,
listDirectory(fromdir))) + \
[todir]
[joinFrom(x) for x
in filterfalse(byfile or operator.not_,
listDirectory(fromdir))] + \
[todir]
cpProcess = cpProcessProgress(*params,
maxfiles=filesnum, stderr=STDOUT)
for perc in cpProcess.progress():
@ -386,8 +386,7 @@ class Distributive(object):
errmes = cpProcess.read()
# copy by one file
if byfile:
percFiles = filter(byfile,
listDirectory(fromdir))
percFiles = [x for x in listDirectory(fromdir) if byfile(x)]
if len(percFiles) > 1:
maxPercOnFile = 100 / len(percFiles)
recountPerc = \
@ -431,7 +430,7 @@ class Distributive(object):
def rndString(self):
"""Get random string with len 8 char"""
return "".join([choice(string.ascii_letters + string.digits)
for i in xrange(0, 8)])
for i in range(0, 8)])
def _getSquashNum(self, reMatch):
if reMatch.groups()[1] and reMatch.groups()[1].isdigit():
@ -441,9 +440,7 @@ class Distributive(object):
def _getLastLive(self, directory):
"""Get last live squashfs image from directory"""
squashfiles = filter(lambda x: x,
map(self.reLive.search,
listDirectory(directory)))
squashfiles = [x for x in map(self.reLive.search, listDirectory(directory)) if x]
if squashfiles:
return max(squashfiles, key=self._getSquashNum).group()
return None
@ -456,8 +453,7 @@ class Distributive(object):
raise DistributiveError(
_("Failed to mount to the directory: %s\n")
% directory + _("Directory already mounted"))
mountopts_list = filter(lambda x: x,
mountopts.split(" "))
mountopts_list = [x for x in mountopts.split(" ") if x]
mountProcess = process('/bin/mount', file, directory, *mountopts_list,
stderr=STDOUT)
if mountProcess.success():
@ -668,7 +664,7 @@ class DirectoryDistributive(Distributive):
:return:
"""
if not self.system_mounted:
for obj in filter(lambda x: x['name'] not in skip, self.data):
for obj in (x for x in self.data if x['name'] not in skip):
target_path = path.join(self.directory, obj['target'])
if obj['type'] == 'bind':
if not path.exists(target_path):
@ -770,7 +766,7 @@ class DirectoryDistributive(Distributive):
return ld
class DataPartition(object):
class DataPartition():
"""Data partition"""
dev = None
mountPoint = None
@ -790,10 +786,8 @@ class MultiPartitions:
"""Add partition in data partition list"""
dictDataPart = reduce(lambda x, y: \
x.update({y: getattr(DataPartition, y)}) or x,
filter(lambda x: not x.startswith('_'),
DataPartition.__dict__), {})
updateAttrData = filter(lambda x: x[1] is not None,
dictDataPart.items())
[x for x in DataPartition.__dict__ if not x.startswith('_')], {})
updateAttrData = (x for x in dictDataPart.items() if x[1] is not None)
defaultAttr = []
for attrName, attrValue in updateAttrData:
if not attrName in argv.keys():
@ -804,14 +798,13 @@ class MultiPartitions:
if notFoundAttr:
raise DistributiveError(_("The following attributes "
"are not specified: (%s)") \
% ", ".join(
map(lambda x: "DataPartition.%s" % x, notFoundAttr)))
% ", ".join(("DataPartition.%s" % x for x in notFoundAttr)))
unnecessaryAttr = (set(dictDataPart.keys()) ^ set(argv.keys())) - \
set(dictDataPart.keys())
if unnecessaryAttr:
raise DistributiveError(_("Failed to use attributes (%s) ") \
% ", ".join(
map(lambda x: "DataPartition.%s" % x, unnecessaryAttr)))
("DataPartition.%s" % x for x in unnecessaryAttr)))
else:
partObj = DataPartition()
for attr, value in argv.items():
@ -822,27 +815,27 @@ class MultiPartitions:
def getSystemId(self):
"""Get systemID for change [None,82,...]"""
return map(lambda x: x.systemId, self.listPartitions)
return [x.systemId for x in self.listPartitions]
def getPartitionTable(self):
"""Get systemID for change [dos,gpt,...]"""
return map(lambda x: x.partitionTable, self.listPartitions)
return [x.partitionTable for x in self.listPartitions]
def getIsFormat(self):
"""Get list is format [True,...]"""
return map(lambda x: x.isFormat, self.listPartitions)
return [x.isFormat for x in self.listPartitions]
def getFileSystems(self):
"""Get list filesystems ["reiserfs",...]"""
return map(lambda x: x.fileSystem, self.listPartitions)
return [x.fileSystem for x in self.listPartitions]
def getPartitions(self):
"""Get list partition ["/dev/sda",...]"""
return map(lambda x: x.dev, self.listPartitions)
return [x.dev for x in self.listPartitions]
def getMountPoints(self):
"""Get list mount point ["/boot",...]"""
return map(lambda x: x.mountPoint, self.listPartitions)
return [x.mountPoint for x in self.listPartitions]
class FormatProcess(process):
@ -855,7 +848,7 @@ class FormatProcess(process):
self._label = label
self.purpose = purpose
self.compression = compression
super(FormatProcess, self).__init__(*self.format_command())
super().__init__(*self.format_command())
def format_command(self):
cmd = getProgPath(self.format_util)
@ -1084,8 +1077,7 @@ class PartitionDistributive(Distributive):
def postinstallMountBind(self):
"""Mount bind mount point and create mount dirs"""
if self.multipartition and self.DirectoryObject:
mulipartDataBind = filter(lambda x: x[2] == "bind",
self.getMultipartData())
mulipartDataBind = [x for x in self.getMultipartData() if x[2] == "bind"]
dirObj = self.DirectoryObject
mdirectory = dirObj.directory
for srcDir, destDir, fileSystem, isFormat, partTable \
@ -1129,8 +1121,7 @@ class PartitionDistributive(Distributive):
mapOpts.get(self.fileSystem,""))
dirObj = DirectoryDistributive(mdirectory, parent=self)
if self.multipartition:
mulipartDataNotBind = filter(lambda x: x[2] != "bind",
self.getMultipartData())
mulipartDataNotBind = (x for x in self.getMultipartData() if x[2] != "bind")
for dev, mountPoint, fileSystem, isFormat, partTable \
in sorted(mulipartDataNotBind, key=lambda x: x[1]):
realMountPoint = None
@ -1166,10 +1157,8 @@ class PartitionDistributive(Distributive):
self.multipartition.getMountPoints() + \
["/"])
# get partition which need format
formatPartitions = map(lambda x: (x[FS], x[DEV], x[NEWID], x[MP]),
filter(
lambda x: x[NEEDFORMAT] and x[FS] != "bind",
dataPartitions))
formatPartitions = [(x[FS], x[DEV], x[NEWID], x[MP]) for x
in dataPartitions if x[NEEDFORMAT] and x[FS] != "bind"]
# if has separate /boot partition
bootmp = ["/boot", "/"]
purpose_map = {"/boot": "boot",
@ -1194,9 +1183,8 @@ class PartitionDistributive(Distributive):
self.formatPartition(dev, format=fileSystem,
purpose=purpose_map.get(mp, None))
# change system id for partitions
changeidPartitions = map(lambda x: (x[NEWID], x[DEV], x[PARTTABLE]),
filter(lambda x: x[NEWID],
dataPartitions))
changeidPartitions = [(x[NEWID], x[DEV], x[PARTTABLE]) for x
in dataPartitions if x[NEWID]]
for systemid, dev, partTable in changeidPartitions:
self.changeSystemID(dev, systemid, partTable)
return True
@ -1213,8 +1201,7 @@ class PartitionDistributive(Distributive):
raise DistributiveError(
_("The specified format of '%s' is not supported") % format)
with open("/proc/swaps") as f:
if dev in map(lambda y: y.split(" ")[0],
filter(lambda x: x.startswith("/"),f)):
if dev in (x.split(" ")[0] for x in f if x.startswith("/")):
raise DistributiveError(
_("Failed to format %s: this partition is used as swap") % dev)
self._checkMount(dev)
@ -1291,8 +1278,7 @@ class PartitionDistributive(Distributive):
def formatSwapPartition(self, dev):
"""Format swap partition"""
with open("/proc/swaps") as f:
if dev in map(lambda y: y.split(" ")[0],
filter(lambda x: x.startswith("/"),f)):
if dev in (x.split(" ")[0] for x in f if x.startswith("/")):
raise DistributiveError(
_("Failed to execute 'mkswap %s': "
"the swap partition is used "
@ -1495,7 +1481,7 @@ class ContainerDistributive(ArchiveDistributive):
if self.exclude:
exclude_list = list(calculate_exclude(
directory, exclude=self.exclude, include=self.include))
params += map(lambda x: "--exclude=./%s" % x, exclude_list)
params += ["--exclude=./%s" % x for x in exclude_list]
params += ["."]
#debug_file = "/var/calculate/tmp/rootfs.tar.xz"
@ -1880,7 +1866,7 @@ class FlashDistributive(PartitionDistributive):
clear_match = re.compile(
r"^(boot|efi|isolinux|syslinux|id.*\.uefi|"
"ldlinux.c32|ldlinux.sys|livecd|livecd.squashfs)$")
for fn in filter(clear_match.match, listDirectory(dn)):
for fn in [x for x in listDirectory(dn) if clear_match.match(x)]:
full_path = path.join(dn, fn)
try:
if path.isdir(full_path):
@ -1891,7 +1877,7 @@ class FlashDistributive(PartitionDistributive):
raise DistributiveError(
_("Failed to remove %s") % fn)
else:
super(FlashDistributive, self).performFormat()
super().performFormat()
def getType(self):
return _("USB flash %s") % self.partition
@ -1924,7 +1910,7 @@ class FlashDistributive(PartitionDistributive):
d = DirectoryDistributive(mp)
d.no_unmount = True
return d
return super(FlashDistributive, self).convertToDirectory()
return super().convertToDirectory()
def releaseChild(self, child):
"""Umount child Directory distributive"""
@ -1990,7 +1976,7 @@ class LayeredDistributive(Distributive):
:param image_file: образ оригинала
:param parent: родительский дистрибутив
"""
super(LayeredDistributive, self).__init__(parent=parent)
super().__init__(parent=parent)
self.mdirectory = mdirectory
self.diff_directory = diff_directory
self.workdir = "%s-work" % self.diff_directory

@ -22,39 +22,56 @@ from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install3', sys.modules[__name__])
class FileSystemManager(object):
class FileSystemManager():
"""Convert dict install option"""
defaultOpt = ['noatime']
defaultBindOpts = ['bind']
#Python3 compat problem:
# dict keys() now sorted based on insertion order,
# instead of being sorted arbitrary by hash.
# Just so the order of keys could be the same as
# in older version, I swaped some pairs around.
supportFS = {
'ext2': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext2',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'ext3': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext3',
'formatparam': '{labelparam} {device}',
'f2fs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.f2fs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-l {labelname}',
'msdos': '83',
'ssd': [],
'compress': None,
'type': ['hdd', 'usb-hdd']},
'btrfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.btrfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd': ['ssd', 'discard', 'space_cache'],
'type': ['hdd', 'usb-hdd'],
'compress': None,
'compatible': ['btrfs-compress']},
'ntfs-3g': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'auto': False,
'msdos': '7',
'compress': None,
'compatible': ['ntfs']},
'ntfs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '7',
'auto': False,
'ssd': [],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'ext4': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext4',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': ['discard'],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'compatible': ['ntfs-3g']},
'reiserfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.reiserfs',
'formatparam': '{labelparam} -f {device}',
@ -64,16 +81,16 @@ class FileSystemManager(object):
'compress': None,
'ssd': [],
'type': ['hdd', 'usb-hdd']},
'btrfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.btrfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'ssd': ['ssd', 'discard', 'space_cache'],
'type': ['hdd', 'usb-hdd'],
'compress': None,
'compatible': ['btrfs-compress']},
'xfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.xfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'boot': '-i sparce=0',
'ssd': ['discard'],
'compress': None,
'type': ['hdd', 'usb-hdd']},
'btrfs-compress': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.btrfs',
'orig': 'btrfs',
@ -85,6 +102,53 @@ class FileSystemManager(object):
'ssd': ['ssd', 'discard', 'space_cache'],
'type': ['hdd', 'usb-hdd'],
'compatible': ['btrfs']},
'ext4': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext4',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': ['discard'],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'ext3': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext3',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'ext2': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.ext2',
'formatparam': '{labelparam} {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'msdos': '83',
'compress': None,
'type': ['hdd', 'usb-hdd']},
'uefi': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': 'EF00',
'label': '-n {labelname}',
'msdos': '0b',
'ssd': [],
'auto': False,
'compress': None,
'type': ['hdd']},
'vfat': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': '0700',
'label': '-n {labelname}',
'msdos': '0b',
'auto': False,
'ssd': ['discard'],
'compress': None,
'type': ['flash']},
'jfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.jfs',
'formatparam': '{labelparam} -f {device}',
@ -94,25 +158,6 @@ class FileSystemManager(object):
'ssd': ['discard'],
'compress': None,
'type': ['hdd', 'usb-hdd']},
'xfs': {'defaultopt': defaultOpt,
'format': '/sbin/mkfs.xfs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '83',
'boot': '-i sparce=0',
'ssd': ['discard'],
'compress': None,
'type': ['hdd', 'usb-hdd']},
'f2fs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.f2fs',
'formatparam': '{labelparam} -f {device}',
'gpt': '8300',
'label': '-l {labelname}',
'msdos': '83',
'ssd': [],
'compress': None,
'type': ['hdd', 'usb-hdd']},
# 'nilfs2': {'defaultopt': defaultOpt,
# 'format': '/sbin/mkfs.nilfs2',
# 'formatparam': '{labelparam} {device}',
@ -130,46 +175,7 @@ class FileSystemManager(object):
'auto': False,
'compress': None,
'msdos': '82'},
'uefi': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': 'EF00',
'label': '-n {labelname}',
'msdos': '0b',
'ssd': [],
'auto': False,
'compress': None,
'type': ['hdd']},
'vfat': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.vfat',
'formatparam': '{labelparam} -F 32 {device}',
'gpt': '0700',
'label': '-n {labelname}',
'msdos': '0b',
'auto': False,
'ssd': ['discard'],
'compress': None,
'type': ['flash']},
'ntfs': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'msdos': '7',
'auto': False,
'ssd': [],
'compress': None,
'compatible': ['ntfs-3g']},
'ntfs-3g': {'defaultopt': defaultOpt,
'format': '/usr/sbin/mkfs.ntfs',
'formatparam': '{labelparam} -FQ {device}',
'gpt': '8300',
'label': '-L {labelname}',
'ssd': [],
'auto': False,
'msdos': '7',
'compress': None,
'compatible': ['ntfs']}}
}
default_param = {'defaultopt': defaultOpt,
'gpt': '8300',

@ -80,10 +80,8 @@ class Install(MethodsInterface):
def canInstallGrub2(self, target):
"""Check that system has grub2 in current and installed system"""
if self.clVars.Get('os_grub2_path'):
return bool(
filter(lambda x: (x.startswith('grub-1.99') or
x.startswith('grub-2')),
listDirectory('/var/db/pkg/sys-boot')))
return bool([x for x in listDirectory('/var/db/pkg/sys-boot')
if (x.startswith('grub-1.99') or x.startswith('grub-2'))])
return False
def prepareBoot(self, target_distr):
@ -132,36 +130,56 @@ class Install(MethodsInterface):
if partition_table == "dos":
fdisk = process(fdisk_cmd, "-l", device_name)
DEVICENUM, AFLAG = 0, 1
change_active = map(
lambda x: x[DEVICENUM],
filter(
lambda x: (x[DEVICENUM] != partition_number and
x[AFLAG] == "*" or
x[DEVICENUM] == partition_number and
not x[AFLAG] == "*"),
list(map(
lambda x: [str(x[0]), x[1][1].strip()],
# enumerate partitions
enumerate(filter(None, map(
lambda x: x.split()[:2],
# drop string before information about partitions
dropwhile(
lambda x: not x.lstrip().startswith(
"Device"),
fdisk.readlines()))))))[1:]))
# change_active = map(
# lambda x: x[DEVICENUM],
# filter(
# lambda x: (x[DEVICENUM] != partition_number and
# x[AFLAG] == "*" or
# x[DEVICENUM] == partition_number and
# not x[AFLAG] == "*"),
# list(map(
# lambda x: [str(x[0]), x[1][1].strip()],
# # enumerate partitions
# enumerate(filter(None, map(
# lambda x: x.split()[:2],
# # drop string before information about partitions
# dropwhile(
# lambda x: not x.lstrip().startswith(
# "Device"),
# fdisk.readlines()))))))[1:]))
change_active = [x[DEVICENUM] for x
in [[str(y[0]), y[1][1].strip()] for y
in enumerate([z for z
in [o.split()[:2] for o
in dropwhile(lambda x: not x.lstrip().startswith("Device"),fdisk.readlines())]
if z])][1:]
if x[DEVICENUM] != partition_number and
x[AFLAG] == "*" or
x[DEVICENUM] == partition_number and
not x[AFLAG] == "*"]
else:
parted = process(parted_cmd, "-m", device_name, "print")
DEVICENUM, FLAGS = 0, 6
change_active = map(
lambda x: x[DEVICENUM], filter(
lambda x: (x[DEVICENUM] != partition_number and
boot_flag in x[FLAGS].strip(';').split(', ') or
x[DEVICENUM] == partition_number and
boot_flag not in
x[FLAGS].strip(';').split(', ')),
filter(lambda x: len(x) >= 7,
map(lambda x: x.split(':'),
parted.readlines()[2:]))))
# change_active = map(
# lambda x: x[DEVICENUM], filter(
# lambda x: (x[DEVICENUM] != partition_number and
# boot_flag in x[FLAGS].strip(';').split(', ') or
# x[DEVICENUM] == partition_number and
# boot_flag not in
# x[FLAGS].strip(';').split(', ')),
# filter(lambda x: len(x) >= 7,
# map(lambda x: x.split(':'),
# parted.readlines()[2:]))))
change_active = [x[DEVICENUM] for x
in [y for y
in [z.split(':') for z
in parted.readlines()[2:]]
if len(y) >= 7]
if x[DEVICENUM] != partition_number and
boot_flag in x[FLAGS].strip(';').split(', ') or
x[DEVICENUM] == partition_number and
boot_flag not in
x[FLAGS].strip(';').split(', ')]
if not change_active:
return True
if partition_table == "dos":
@ -269,9 +287,9 @@ class Install(MethodsInterface):
# если GRUB2 версии 2.00 и выше, обычная установка требует
# параметра --target=i386-pc, иначе GRUB2 может попытаться
# прописать себя как UEFI
if filter(lambda x: "2." in x,
process(*traverse([chrooting,
cmd_grub_install, '--version']))):
if [x for x
in process(*traverse([chrooting, cmd_grub_install, '--version']))
if "2." in x]:
platform = ["--target=i386-pc"]
else:
platform = []
@ -639,10 +657,10 @@ class Install(MethodsInterface):
"""
target_dir = target.getDirectory()
source_dir = source.getDirectory()
for f in filter(lambda x: x.endswith('.clt'),
chain(*map(lambda x: find(pathJoin(source_dir, x),
filetype="f"),
cltpath))):
for f in (x for x
in chain(*[find(pathJoin(source_dir, y), filetype="f") for y
in cltpath])
if x.endswith('.clt')):
copyWithPath(f, target_dir, prefix=source_dir)
return True
@ -654,10 +672,10 @@ class Install(MethodsInterface):
"/root/.ssh/(id_.*|known_hosts))")
target_dir = target.getDirectory()
source_dir = source.getDirectory()
for f in filter(file_mask.search,
chain(*map(lambda x: find(pathJoin(source_dir, x),
filetype="f"),
["/etc", "/root/.ssh"]))):
for f in (x for x
in chain(*(find(pathJoin(source_dir, y), filetype="f") for y
in ["/etc", "/root/.ssh"]))
if file_mask.search(x)):
copyWithPath(f, target_dir, prefix=source_dir)
return True
@ -667,7 +685,7 @@ class Install(MethodsInterface):
"""
"""Get random string with len 8 char"""
return "".join([choice(string.ascii_letters + string.digits)
for i in xrange(0, 8)])
for i in range(0, 8)])
def _getFreeDirectory(self, directory):
"""

@ -29,16 +29,17 @@ class MigrationError(Exception):
pass
class _shareData(object):
class _shareData():
"""Share class"""
_reNumb = re.compile("^\d+$")
def getDataInFile(self, fileName='', lenData=7):
"""Get data list from file"""
with open(fileName) as f:
return map(lambda x: x[:lenData],
filter(lambda x: len(x) >= lenData,
map(lambda x: x.rstrip().split(":"), f)))
return [x[:lenData] for x
in (y.rstrip().split(":") for y
in f)
if len(x) >= lenData]
class migrateGroups(_shareData):
@ -58,46 +59,39 @@ class migrateGroups(_shareData):
def getThisData(self):
"""Get data migrate groups in this system"""
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minGid <= int(
x[2]) <= self.maxGid,
self.getData())
return [x for x in self.getData()
if self._reNumb.match(x[2]) and self.minGid <= int(x[2]) <= self.maxGid]
def getNewData(self):
"""Get data migrate groups in new system"""
fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minGid <= int(
x[2]) <= self.maxGid,
self.getData(fileName=fileName))
return [x for x in self.getData(fileName=fileName)
if self._reNumb.match(x[2]) and self.minGid <= int(x[2]) <= self.maxGid]
def getNewDataSystemGroups(self):
"""Get data system groups in new system"""
fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2]) > self.maxGid or int(x[2]) < self.minGid),
self.getData(fileName=fileName))
return [x for x in self.getData(fileName=fileName)
if self._reNumb.match(x[2]) and (int(x[2]) > self.maxGid or int(x[2]) < self.minGid)]
def getNewProcessedData(self):
"""Get processed data migrate groups in new system"""
# data this Group no users
dataThisGroupsNoUsers = map(lambda x: x[:3] + [""], self.getThisData())
dataThisGroupsNoUsers = [x[:3] + [""] for x in self.getThisData()]
dataNewGroups = self.getNewData()
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
namesNewGroups = [x[0] for x in dataNewGroups]
gidsNewGroups = [x[2] for x in dataNewGroups]
for data in dataThisGroupsNoUsers:
nameGroup = data[0]
gid = data[2]
if nameGroup in namesNewGroups:
dataNewGroups = filter(lambda x: x[0] != nameGroup,
dataNewGroups)
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
dataNewGroups = [x for x in dataNewGroups if x[0] != nameGroup]
namesNewGroups = [x[0] for x in dataNewGroups]
gidsNewGroups = [x[2] for x in dataNewGroups]
if gid in gidsNewGroups:
dataNewGroups = filter(lambda x: x[2] != gid, dataNewGroups)
namesNewGroups = map(lambda x: x[0], dataNewGroups)
gidsNewGroups = map(lambda x: x[2], dataNewGroups)
dataNewGroups = [x for x in dataNewGroups if x[2] != gid]
namesNewGroups = [x[0] for x in dataNewGroups]
gidsNewGroups = [x[2] for x in dataNewGroups]
systemGroupsNewData = self.getNewDataSystemGroups()
return systemGroupsNewData, dataNewGroups, dataThisGroupsNoUsers
@ -119,81 +113,67 @@ class migrateUsers(_shareData):
def getThisData(self):
"""Get data migrate users in this system"""
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minId <= int(
x[2]) <= self.maxId,
self.getData())
return [x for x in self.getData()
if self._reNumb.match(x[2]) and self.minId <= int(x[2]) <= self.maxId]
def getNewData(self):
"""Get data migrate users in new system"""
fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
return filter(lambda x: \
self._reNumb.match(x[2]) and self.minId <= int(
x[2]) <= self.maxId,
self.getData(fileName=fileName))
return [x for x in self.getData(fileName=fileName)
if self._reNumb.match(x[2]) and self.minId <= int(x[2]) <= self.maxId]
def getNewDataSystemUsers(self):
"""Get data system users in new system"""
fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2] > self.maxId) or int(x[2]) < self.minId),
self.getData(fileName=fileName))
return [x for x in self.getData(fileName=fileName)
if self._reNumb.match(x[2]) and (int(x[2] > self.maxId) or int(x[2]) < self.minId)]
def getThisDataSystemUsers(self):
"""Get data system users in this system"""
fileName = self.filePasswd
return filter(lambda x: \
self._reNumb.match(x[2]) and \
(int(x[2] > self.maxId) or int(x[2]) < self.minId),
self.getData(fileName=fileName))
return [x for x in self.getData(fileName=fileName)
if self._reNumb.match(x[2]) and (int(x[2] > self.maxId) or int(x[2]) < self.minId)]
def getNewProcessedData(self, migrateUsers=()):
"""Get processed data migrate users in new system"""
dataThisUsers = self.getThisData()
if migrateUsers:
dataThisUsers = filter(lambda x: x[0] in migrateUsers,
dataThisUsers)
dataThisUsers = [x for x in dataThisUsers if x[0] in migrateUsers]
dataNewUsers = self.getNewData()
namesNewUsers = map(lambda x: x[0], dataNewUsers)
uidsNewUsers = map(lambda x: x[2], dataNewUsers)
namesNewUsers = [x[0] for x in dataNewUsers]
uidsNewUsers = [x[2] for x in dataNewUsers]
for data in dataThisUsers:
nameUser = data[0]
uid = data[2]
if nameUser in namesNewUsers:
dataNewUsers = filter(lambda x: x[0] != nameUser, dataNewUsers)
namesNewUsers = map(lambda x: x[0], dataNewUsers)
uidsNewUsers = map(lambda x: x[2], dataNewUsers)
dataNewUsers = [x for x in dataNewUsers if x[0] != nameUser]
namesNewUsers = [x[0] for x in dataNewUsers]
uidsNewUsers = [x[2] for x in dataNewUsers]
if uid in uidsNewUsers:
dataNewUsers = filter(lambda x: x[2] != uid, dataNewUsers)
namesNewUsers = map(lambda x: x[0], dataNewUsers)
uidsNewUsers = map(lambda x: x[2], dataNewUsers)
dataNewUsers = [x for x in dataNewUsers if x[2] != uid]
namesNewUsers = [x[0] for x in dataNewUsers]
uidsNewUsers = [x[2] for x in dataNewUsers]
systemUsersNewData = self.getNewDataSystemUsers()
systemUsersNewNames = map(lambda x: x[0], systemUsersNewData)
systemUsersNewUids = map(lambda x: x[2], systemUsersNewData)
systemUsersNewNames = [x[0] for x in systemUsersNewData]
systemUsersNewUids = [x[2] for x in systemUsersNewData]
systemUsersThisData = []
if migrateUsers:
# this users < minId
systemUsersThisData = filter(lambda x: int(x[2]) < self.minId and \
x[0] in migrateUsers,
self.getThisDataSystemUsers())
systemUsersThisData = [x for x in self.getThisDataSystemUsers()
if int(x[2]) < self.minId and x[0] in migrateUsers]
for data in systemUsersThisData:
nameUser = data[0]
uid = data[2]
if nameUser in systemUsersNewNames:
systemUsersNewData = filter(lambda x: x[0] != nameUser,
systemUsersNewData)
systemUsersNewNames = map(lambda x: x[0],
systemUsersNewData)
systemUsersNewUids = map(lambda x: x[2],
systemUsersNewData)
systemUsersNewData = [x for x in systemUsersNewData
if x[0] != nameUser]
systemUsersNewNames = [x[0] for x in systemUsersNewData]
systemUsersNewUids = [x[2] for x in systemUsersNewData]
if uid in systemUsersNewUids:
systemUsersNewData = filter(lambda x: x[2] != uid,
systemUsersNewData)
systemUsersNewNames = map(lambda x: x[0],
systemUsersNewData)
systemUsersNewUids = map(lambda x: x[2],
systemUsersNewData)
systemUsersNewData = [x for x in systemUsersNewData
if x[2] != uid]
systemUsersNewNames = [x[0] for x in systemUsersNewData]
systemUsersNewUids = [x[2] for x in systemUsersNewData]
return (systemUsersThisData, systemUsersNewData,
dataNewUsers, dataThisUsers)
@ -219,48 +199,48 @@ class migrateShadow(_shareData):
def getThisData(self):
"""Get data migrate users in this system"""
return filter(lambda x: x[0] in self.thisMigrateUsers, self.getData())
return [x for x in self.getData()
if x[0] in self.thisMigrateUsers]
def getNewData(self):
"""Get data migrate users in new system"""
return filter(lambda x: x[0] in self.newMigrateUsers,
self.getData(fileName=self.newFileName))
return [x for x in self.getData(fileName=self.newFileName)
if x[0] in self.newMigrateUsers]
def getNewDataSystemShadow(self):
"""Get data system users in new system"""
return filter(lambda x: x[0] in self.sysNewMigrateUsers,
self.getData(fileName=self.newFileName))
return [x for x in self.getData(fileName=self.newFileName)
if x[0] in self.sysNewMigrateUsers]
def getThisDataSystemShadow(self):
"""Get data system users in this system"""
return filter(lambda x: x[0] in self.sysThisMigrateUsers,
self.getData())
return [x for x in self.getData() if x[0] in self.sysThisMigrateUsers]
def getNewProcessedData(self):
"""Get processed data migrate shadow in new system"""
dataThisShadow = self.getThisData()
dataNewShadow = self.getNewData()
namesNewShadow = map(lambda x: x[0], dataNewShadow)
namesNewShadow = [x[0] for x in dataNewShadow]
for data in dataThisShadow:
nameUser = data[0]
if nameUser in namesNewShadow:
dataNewShadow = filter(lambda x: x[0] != nameUser,
dataNewShadow)
namesNewShadow = map(lambda x: x[0], dataNewShadow)
dataNewShadow = [x for x in dataNewShadow if x[0] != nameUser]
namesNewShadow = [x[0] for x in dataNewShadow]
systemShadowNewData = self.getNewDataSystemShadow()
systemShadowThisData = self.getThisDataSystemShadow()
systemShadowNewNames = map(lambda x: x[0], systemShadowNewData)
systemShadowNewNames = [x[0] for x in systemShadowNewData]
for data in systemShadowThisData:
nameUser = data[0]
if nameUser in systemShadowNewNames:
systemShadowNewData = filter(lambda x: x[0] != nameUser,
systemShadowNewData)
systemShadowNewNames = map(lambda x: x[0], systemShadowNewData)
systemShadowNewData = [x for x
in systemShadowNewData if x[0] != nameUser]
systemShadowNewNames = [x[0] for x in systemShadowNewData]
return (systemShadowThisData, systemShadowNewData, dataNewShadow,
dataThisShadow)
class migrate(object):
class migrate():
"""Migrate users ang groups to new system"""
templateShadow = "%(user)s:%(hash)s:%(days)s:0:%(maxDays)s:%(warnDays)s:::"
templateUser = "%(user)s:x:%(id)s:%(gid)s::/home/%(user)s:/bin/bash"
@ -285,14 +265,12 @@ class migrate(object):
def addThisUsersToGroups(self, users):
"""Add users to groups"""
thisGroupsData = self.objGroups.getData()
thisGroupsData = map(lambda x: (x[0], x[3].split(',')),
thisGroupsData)
thisGroupsData = [(x[0], x[3].split(',')) for x in thisGroupsData]
dataGroups = []
for data in self.dataGroups:
groupName = data[0]
thisUsersInGroup = map(lambda x: x[1],
filter(lambda x: x[0] == groupName,
thisGroupsData))
thisUsersInGroup = [x[1] for x in thisGroupsData if x[0] == groupName]
#??? whats the point of this?
thisUsersInGroup = reduce(lambda x, y: x + y, thisUsersInGroup, [])
addUsers = list(set(thisUsersInGroup) & set(users))
if addUsers:
@ -300,36 +278,30 @@ class migrate(object):
for user in addUsers:
if not user in newUsersInGroup:
newUsersInGroup.append(user)
data[3] = ','.join(filter(lambda x: x, newUsersInGroup))
data[3] = ','.join((x for x in newUsersInGroup if x))
dataGroups.append(data)
self.dataGroups = dataGroups
return self.dataGroups
def getNextUid(self):
"""get next uid"""
listUid = map(lambda x: int(x[2]),
filter(lambda x: \
self.objUsers._reNumb.match(x[2]) and \
self.minId <= int(x[2]) <= self.maxId,
self.dataUsers))
listUid = [int(x[2]) for x in self.dataUsers
if self.objUsers._reNumb.match(x[2]) and self.minId <= int(x[2]) <= self.maxId]
if listUid:
return max(listUid) + 1
return self.minId
def getNextGid(self):
"""get next gid"""
listGid = map(lambda x: int(x[2]),
filter(lambda x: \
self.objGroups._reNumb.match(x[2]) and \
self.minGid <= int(x[2]) <= self.maxGid,
self.dataGroups))
listGid = [int(x[2]) for x in self.dataGroups
if self.objUsers._reNumb.match(x[2]) and self.minGid <= int(x[2]) <= self.maxGid]
if listGid:
return max(listGid) + 1
return self.minGid
def isSystemUser(self, userName):
if filter(lambda x: x[0] == userName and int(x[2]) <= self.minSysId,
self.dataUsers):
if [x for x in self.dataUsers
if (x[0] == userName and int(x[2]) <= self.minSysId)]:
return True
return False
@ -343,7 +315,7 @@ class migrate(object):
usersInGroup = data[3].split(',')
if not userName in usersInGroup:
usersInGroup.append(userName)
data[3] = ','.join(filter(lambda x: x, usersInGroup))
data[3] = ','.join((x for x in usersInGroup if x))
dataGroups.append(data)
self.dataGroups = dataGroups
return self.dataGroups
@ -353,7 +325,7 @@ class migrate(object):
return self.addUserToGroups(userName, self.newUserGroups)
def changePassword(self, userName, pwdHash, maxDays="99999", warnDays="7"):
if not filter(lambda x: x[0] == userName, self.dataUsers):
if not [x for x in self.dataUsers if x[0] == userName]:
raise MigrationError(_("User %s not found") % userName)
indexFoundUser = False
for i, data in enumerate(self.dataShadow):
@ -380,14 +352,14 @@ class migrate(object):
def addUser(self, userName, userGroups, pwdHash):
"""Add user"""
# find user
if filter(lambda x: x[0] == userName, self.dataUsers):
if [x for x in self.dataUsers if x[0] == userName]:
return "EXISTS"
else:
strUid = str(self.getNextUid())
strGid = str(self.getNextGid())
groupName = userName
dataExistGroup = filter(lambda x: x[0] == groupName,
self.dataGroups)
dataExistGroup = [x for x in self.dataGroups
if x[0] == groupName]
if dataExistGroup:
strGid = dataExistGroup[0][2]
else:
@ -412,27 +384,25 @@ class migrate(object):
"""Check permission files"""
checkThisFiles = [migrateGroups.fileGroups, migrateUsers.filePasswd,
migrateShadow.fileShadow]
checkNewFiles = map(lambda x: pathJoin(self.prefixNewSystem, x),
checkThisFiles)
checkNewFiles = [pathJoin(self.prefixNewSystem, x) for x in checkThisFiles]
parentDir = lambda x: "".join(os.path.split(x)[:-1])
notRead = lambda x: not os.access(x, os.R_OK)
notWrite = lambda x: not os.access(x, os.W_OK)
filesNotRead = filter(notRead, checkThisFiles)
filesNotRead = [x for x in checkThisFiles if notRead(x)]
if filesNotRead:
raise MigrationError(_("Failed to read files") + _(": ") +
", ".join(filesNotRead))
filesNotWrite = filter(notWrite, checkNewFiles)
filesNotWrite = [x for x in checkNewFiles if notWrite(x)]
if filesNotWrite:
raise MigrationError(_("Failed to write to files") + _(": ") +
", ".join(filesNotWrite))
# Check permissions backup files
checkNewBackupFiles = map(
lambda x: pathJoin(self.prefixNewSystem, x + "-"),
checkThisFiles)
checkNewBackupFiles = (pathJoin(self.prefixNewSystem, x + "-") for x
in checkThisFiles)
notWriteBackup = lambda x: not os.access(x, os.W_OK) and \
(os.path.exists(x) or
not os.access(os.path.dirname(x), os.W_OK))
filesNotWrite = filter(notWriteBackup, checkNewBackupFiles)
filesNotWrite = [x for x in checkNewBackupFiles if notWriteBackup(x)]
if filesNotWrite:
raise MigrationError(_("Failed to write to files") + _(": ") +
", ".join(filesNotWrite))
@ -443,20 +413,20 @@ class migrate(object):
listFilesThisSystem = [migrateGroups.fileGroups,
migrateUsers.filePasswd,
migrateShadow.fileShadow]
listFiles = map(lambda x: (pathJoin(self.prefixNewSystem, x),
pathJoin(self.prefixNewSystem, x + "-")),
listFilesThisSystem)
listFiles = [(pathJoin(self.prefixNewSystem, x),
pathJoin(self.prefixNewSystem, x + "-")) for x
in listFilesThisSystem]
listData = [self.dataGroups, self.dataUsers, self.dataShadow]
allData = zip(listFiles, listData)
for fileNames, data in allData:
buff = "\n".join(map(lambda x: ":".join(x), data)) + "\n"
buff = "\n".join((":".join(x) for x in data)) + "\n"
for fileName in fileNames:
FD = open(fileName, "w+")
FD.write(buff)
FD.close()
def createUserGuest(self):
if filter(lambda x: int(x[2]) >= self.minSysId, self.dataUsers):
if [x for x in self.dataUsers if int(x[2]) >= self.minSysId]:
return True
else:
# add user guest
@ -480,11 +450,9 @@ class migrate(object):
os.mkdir(homedir)
os.chown(homedir, int(userdata[2]), int(userdata[3]))
os.chmod(homedir, perms)
users = list(
set(map(lambda x: x[0],
addUsersList) + existsMigrateUsers) - {"root"})
users = list(set([x[0] for x in addUsersList] + existsMigrateUsers) - {"root"})
try:
map(createHome, filter(lambda x: x[0] in users, self.dataUsers))
map(createHome, (x for x in self.dataUsers if x[0] in users))
except Exception as e:
raise MigrationError(
_("Failed to create the user's home directory"))
@ -502,8 +470,9 @@ class migrate(object):
existsMigrateUsers = []
if not self.checkPermFiles():
return False
migrateUsers = (["root"] +
map(lambda x: x[0], addUsersList + pwdUsersList))
migrateUsers = (["root"] + [x[0] for x in addUsersList + pwdUsersList])
for existMigrUser in existsMigrateUsers:
if existMigrUser not in migrateUsers:
migrateUsers.append(existMigrUser)
@ -511,7 +480,7 @@ class migrate(object):
dataUsers = self.objUsers.getNewProcessedData(migrateUsers)
dataGroups = self.objGroups.getNewProcessedData()
thisSystemUsers, newSystemUsers, newUsers, thisUsers = \
map(lambda x: map(lambda y: y[0], x), dataUsers)
[[y[0] for y in x] for x in dataUsers]
objShadow = migrateShadow(thisSystemUsers, newSystemUsers, newUsers,
thisUsers, self.prefixNewSystem)
dataShadow = objShadow.getNewProcessedData()
@ -547,7 +516,7 @@ class currentUsers(migrate):
"""Current users"""
def __init__(self):
super(currentUsers, self).__init__('/')
super().__init__('/')
def addUsers(self, *users_passwd):
"""Added users and groups to current system"""
@ -574,7 +543,5 @@ class currentUsers(migrate):
if not self.checkPermFiles():
return False
getDataInFile = _shareData().getDataInFile
self.dataUsers = map(lambda x: x[0],
getDataInFile(fileName=migrateUsers.filePasswd,
lenData=7))
self.dataUsers = [x[0] for x in getDataInFile(fileName=migrateUsers.filePasswd,lenData=7)]
return set(self.dataUsers) >= set(users)

@ -91,8 +91,7 @@ class ResolutionVariable(VideoVariable):
"1600x900", "1600x1200", "2048x1152", "2560x1440",
"2560x1600"]
if self.fbres:
return map(lambda x: "%s-32" % x,
resolutions)
return ["%s-32" % x for x in resolutions]
else:
return resolutions
@ -183,7 +182,7 @@ class VariableOsInstallX11VideoAvailable(VideoVariable):
return []
def humanReadable(self):
return map(lambda x: self.driver_names.get(x, x), self.Get())
return [self.driver_names.get(x, x) for x in self.Get()]
class VariableOsX11KmsVideoDrv(ReadonlyVariable):
@ -219,9 +218,9 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
if self.Get('os_install_x11_server_set') == 'on':
values = self.Get('os_install_x11_video_available')
else:
values = self.nox_video_drivers()
return map(lambda x: (x, self.driver_names.get(x, x)),
(x for x in self.driver_names.keys() if x in values))
values = self.nox_video_drivers()
return [(x, self.driver_names.get(x, x)) for x
in [y for y in self.driver_names.keys() if y in values]]
def get(self):
if self.Get('os_install_x11_server_set') == 'on':
@ -249,7 +248,7 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
return drv
return self.default_video
else:
for drv in map(lambda x: x[0], self.choice()):
for drv in (x[0] for x in self.choice()):
refcnt = device.sysfs.read(
device.sysfs.Path.Module, drv, "refcnt").strip()
if refcnt.isdigit() and int(refcnt) > 0:

@ -88,14 +88,12 @@ class VariableOsAudioAvailable(Variable):
with image as distr:
try:
distrPath = image.getDirectory()
return map(lambda x: x[0::2],
filter(lambda x: not x[1] or isPkgInstalled(x[1],
prefix=distrPath),
mapAudioConf))
return [x[0::2] for x
in mapAudioConf
if not x[1] or isPkgInstalled(x[1], prefix=distrPath)]
except DistributiveError as e:
pass
return sorted(map(lambda x: x[0::2], mapAudioConf[-1:]),
key=lambda x: x[1])
return sorted((x[0::2] for x in mapAudioConf[-1:]), key=lambda x: x[1])
class VariableOsAudioCardMap(ReadonlyVariable):

@ -71,7 +71,7 @@ class AutopartitionError(Exception):
pass
class SchemeOpt(object):
class SchemeOpt():
Swap = "swap"
Update = "update"
UEFI = "uefi"
@ -98,9 +98,7 @@ class VariableHrMemorySize(ReadonlyVariable):
def get(self):
reMemTotal = re.compile(r'^MemTotal:\s*(\d+)\s*kB$')
totalMemList = filter(lambda x: x,
map(reMemTotal.search,
readLinesFile('/proc/meminfo')))
totalMemList = [x for x in map(reMemTotal.search, readLinesFile('/proc/meminfo')) if x]
if totalMemList:
size = int(totalMemList[0].group(1)) * Sizes.K
return str(size)
@ -212,7 +210,7 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable):
self.label = _("Devices for install")
def get(self):
choiceVal = map(lambda x: x[0], self.choice())
choiceVal = [x[0] for x in self.choice()]
devicesTypes = self.Select(['os_device_dev','os_device_type'],
where='os_device_dev', _in=choiceVal)
notFlashDevices = [x[0] for x in devicesTypes if x[1] != 'flash']
@ -255,8 +253,9 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable):
def checkOnRaid(self, valuelist):
disks = self.Select('os_disk_dev',
where='os_disk_parent', _in=valuelist)
raids = filter(None, self.Select('os_disk_raid',
where='os_disk_dev', _in=disks))
raids = [x for x
in self.Select('os_disk_raid', where='os_disk_dev', _in=disks)
if x]
raidDisks = self.Select('os_disk_dev', where='os_disk_raid', _in=raids)
raidDevices = self.Select('os_disk_parent',
where='os_disk_dev',
@ -689,17 +688,29 @@ class VariableClAutopartitionLvmVgname(Variable):
"""
def get(self):
# def generateName(startName):
# yield startName
# for i in count(20):
# yield "%s%d" % (startName, i)
# instead this just so there won't be an infinite loop
def generateName(startName):
yield startName
for i in count(20):
for i in range(20, 1000):
yield "%s%d" % (startName, i)
for name in generateName("calculate"):
disks = self.Select('os_lvm_pvname', where='os_lvm_vgname', eq=name)
devices = self.Select('os_disk_parent',
where='os_disk_dev', _in=disks)
if set(devices) <= set(self.Get('cl_autopartition_device')):
return name
#TODO should replace this
raise Exception
class VariableClAutopartitionDiskData(ReadonlyTableVariable):
@ -772,10 +783,10 @@ class VariableClAutopartitionDiskSize(DiskFilter, ReadonlyVariable):
field = "disk_size"
def get(self):
return map(str, super(VariableClAutopartitionDiskSize, self).get())
return [str(x) for x in super().get()]
def humanReadable(self):
return map(humanreadableSize, self.Get())
return [humanreadableSize(x) for x in self.Get()]
class VariableClAutopartitionDiskDataFull(ReadonlyTableVariable):
@ -864,10 +875,10 @@ class VariableClAutopartitionDiskSizeFull(ReadonlyVariable):
def get(self):
var_factory = self.Get('cl_autopartition_factory')
return map(str, var_factory.disk_size)
return [str(x) for x in var_factory.disk_size]
def humanReadable(self):
return map(humanreadableSize, self.Get())
return [humanreadableSize(x) for x in self.Get()]
class VariableClAutopartitionRaid(ReadonlyVariable):
@ -1016,7 +1027,7 @@ class VariableClAutopartitionBindPath(FieldValue, ReadonlyVariable):
column = 0
def get(self):
return list(super(VariableClAutopartitionBindPath, self).get())
return list(super().get())
class VariableClAutopartitionBindMountpoint(FieldValue, ReadonlyVariable):
"""
@ -1027,4 +1038,4 @@ class VariableClAutopartitionBindMountpoint(FieldValue, ReadonlyVariable):
column = 1
def get(self):
return list(super(VariableClAutopartitionBindMountpoint, self).get())
return list(super().get())

@ -50,8 +50,7 @@ class DeviceHelper(VariableInterface):
def getBlockDevices(self):
"""Get interest devices from sys block path"""
return filter(self.rePassDevice.search,
device.udev.get_block_devices())
return [x for x in device.udev.get_block_devices() if self.rePassDevice.search(x)]
def separateDevice(self, dev):
"""
@ -59,8 +58,7 @@ class DeviceHelper(VariableInterface):
Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1)
"""
return map(lambda x: int(x) if x.isdigit() else x,
re.findall('\d+|\D+', dev))
return [int(x) if x.isdigit() else x for x in re.findall('\d+|\D+', dev)]
def mapUdevProperty(self, var, prop, default):
"""Get each element from var through udev [prop]"""
@ -180,8 +178,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
if device.udev.is_device(device.udev.get_device_info(x)) or
self.re_disk_raid.match(device.udev.get_device_type(path=x)))
return list(sorted((x for x in devnames),
key=self.separateDevice))
return list(sorted((x for x in devnames), key=self.separateDevice))
class VariableOsDeviceFulltype(ReadonlyVariable):
"""
@ -221,15 +218,13 @@ class VariableOsDeviceType(ReadonlyVariable):
# get usb device by '/dev/disk/by-id'(usb devices contain 'usb' in name)
diskIdPath = '/dev/disk/by-id'
if device.devfs.exists(diskIdPath):
self.usbdevices = \
map(lambda x: \
device.devfs.realpath(diskIdPath, x).rpartition('/')[2],
filter(lambda x: x.startswith('usb-'),
device.devfs.listdir(diskIdPath, fullpath=False)))
self.usbdevices = [device.devfs.realpath(diskIdPath, x).rpartition('/')[2] for x
in device.devfs.listdir(diskIdPath, fullpath=False)
if x.startswith('usb-')]
else:
self.usbdevices = []
return map(self.getType,
self.Get('os_device_dev'))
return [self.getType(x) for x in self.Get('os_device_dev')]
class VariableOsDeviceParent(ReadonlyVariable):
@ -313,8 +308,7 @@ class VariableOsDeviceMap(ReadonlyVariable):
type = "list"
def get(self):
return map(lambda x: str(x[0]),
enumerate(self.Get('os_device_dev')))
return [str(x[0]) for x in enumerate(self.Get('os_device_dev'))]
class VariableOsDeviceArraySet(ReadonlyVariable):
@ -334,9 +328,7 @@ class VariableOsDeviceArraySet(ReadonlyVariable):
else:
return "off"
return map(lambda x: isArray(*x),
zip(self.Get('os_device_dev'),
self.Get('os_device_name')))
return [isArray(*x) for x in zip(self.Get('os_device_dev'), self.Get('os_device_name'))]
class VariableOsDeviceSsdSet(ReadonlyVariable):
@ -361,9 +353,7 @@ class VariableOsDeviceSsdSet(ReadonlyVariable):
else:
return "off"
return map(lambda x: isSsd(*x),
zip(self.Get('os_device_dev'),
self.Get('os_device_name')))
return [isSsd(*x) for x in zip(self.Get('os_device_dev'), self.Get('os_device_name'))]
class VariableOsDeviceSyspath(ReadonlyVariable):
@ -403,10 +393,9 @@ class VariableOsDeviceVirtualSet(ReadonlyVariable):
else:
return "off"
return map(lambda x: isVirtual(*x),
zip(self.Get('os_device_dev'),
self.Get('os_device_name'),
self.Get('os_device_syspath')))
return [isVirtual(*x) for x in zip(self.Get('os_device_dev'),
self.Get('os_device_name'),
self.Get('os_device_syspath'))]
class VariableOsDeviceTable(ReadonlyVariable):
@ -444,8 +433,8 @@ class VariableOsDeviceTable(ReadonlyVariable):
else:
return getTable(dev)
return map(getByAutopartition,
self.Get('os_device_dev'))
return [getByAutopartition(x) for x in self.Get('os_device_dev')]
class VariableOsDeviceName(ReadonlyVariable):
@ -475,8 +464,7 @@ class VariableOsDeviceName(ReadonlyVariable):
return ""
def get(self):
return map(self.getName,
self.Get('os_device_dev'))
return [self.getName(x) for x in self.Get('os_device_dev')]
class VariableOsDeviceSize(ReadonlyVariable):
@ -487,12 +475,10 @@ class VariableOsDeviceSize(ReadonlyVariable):
def get(self):
"""Get device size"""
return map(lambda x: getPartitionSize(name=x, inBytes=True),
self.Get('os_device_dev'))
return [getPartitionSize(name=x, inBytes=True) for x in self.Get('os_device_dev')]
def humanReadable(self):
return map(humanreadableSize,
self.Get())
return [humanreadableSize(x) for x in self.Get()]
#############################################
@ -536,8 +522,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable):
return list(sorted((x for x in dev_names), key=self.separateDevice))
def humanReadable(self):
return map(self.getPerfectName,
self.Get())
return [self.getPerfectName(x) for x in self.Get()]
class VariableOsDiskMount(DeviceHelper, ReadonlyVariable):
@ -550,8 +535,7 @@ class VariableOsDiskMount(DeviceHelper, ReadonlyVariable):
disk_hash = self.Get('os_disk_dev')
fstab = FStab('/etc/fstab', devs=disk_hash)
rootdev = self.Get('os_root_dev')
return map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "",
self.Get('os_disk_dev'))
return ['/' if x == rootdev else fstab.getBy(eq=x) or "" for x in self.Get('os_disk_dev')]
class VariableOsDiskContent(ReadonlyVariable):
@ -564,8 +548,7 @@ class VariableOsDiskContent(ReadonlyVariable):
"""
TODO: need to write
"""
return map(lambda x: "",
self.Get('os_disk_dev'))
return ["" for x in self.Get('os_disk_dev')]
class VariableOsDiskFormat(ReadonlyVariable):
"""
@ -593,8 +576,7 @@ class VariableOsDiskFormat(ReadonlyVariable):
pass
return fs
return map(getFormat,
self.Get('os_disk_dev'))
return [getFormat(x) for x in self.Get('os_disk_dev')]
class VariableOsDiskType(ReadonlyVariable):
@ -607,8 +589,8 @@ class VariableOsDiskType(ReadonlyVariable):
def get(self):
"""Get partition scheme"""
types = map(lambda x: (x, device.udev.get_device_type(name=x)),
self.Get('os_disk_dev'))
types = [(x, device.udev.get_device_type(name=x)) for x in self.Get('os_disk_dev')]
lvmUsedDisks = {}
raidUsedDisks = {}
@ -622,7 +604,6 @@ class VariableOsDiskType(ReadonlyVariable):
",".join(
lvmUsedDisks[diskName]))
return diskName, diskType
for dev, diskType in types:
prop = device.udev.get_device_info(name=dev)
if self.re_raid.search(diskType):
@ -642,9 +623,8 @@ class VariableOsDiskType(ReadonlyVariable):
lvmUsedDisks[x].append(dev)
else:
lvmUsedDisks[x] = [dev]
return map(lambda x: x[1],
map(forMember,
types))
return [x[1] for x in map(forMember, types)]
class VariableOsDiskRaid(ReadonlyVariable):
@ -672,8 +652,7 @@ class VariableOsDiskLvm(DeviceHelper, ReadonlyVariable):
def get(self):
"""Get each element from var through udev [prop]"""
return map(self.getLvmName,
self.Get('os_disk_dev'))
return [self.getLvmName(x) for x in self.Get('os_disk_dev')]
class VariableOsDiskUuid(DeviceHelper, ReadonlyVariable):
@ -723,10 +702,9 @@ class VariableOsDiskId(DeviceHelper, ReadonlyVariable):
'21686148-6449-6e6f-744e-656564454649': 'EF02',
'c12a7328-f81f-11d2-ba4b-00a0c93ec93b': 'EF00',
'0fc63daf-8483-4772-8e79-3d69d8477de4': '8300'}
return map(lambda x: mapTypeUUID.get(x, x),
map(lambda x: x.rpartition("x")[2],
self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE',
'')))
return [mapTypeUUID.get(x, x) for x
in [y.rpartition("x")[2] for y
in self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE','')]]
class VariableOsDiskGrub(ReadonlyVariable):
@ -753,10 +731,10 @@ class VariableOsDiskGrub(ReadonlyVariable):
else:
return ""
return map(getGrubMap,
zip(self.Get('os_disk_dev'),
self.Get('os_disk_type'),
self.Get('os_disk_parent')))
return [getGrubMap(x) for x
in zip(self.Get('os_disk_dev'),
self.Get('os_disk_type'),
self.Get('os_disk_parent'))]
class VariableOsDiskPart(ReadonlyVariable):
@ -766,7 +744,7 @@ class VariableOsDiskPart(ReadonlyVariable):
If gpt then gpt
"""
type = "list"
def get(self):
def generator():
for disk_dev, disk_type in self.ZipVars(
@ -786,12 +764,10 @@ class VariableOsDiskSize(ReadonlyVariable):
def get(self):
"""Get disk size"""
return map(lambda x: getPartitionSize(name=x, inBytes=True),
self.Get('os_disk_dev'))
return [getPartitionSize(name=x, inBytes=True) for x in self.Get('os_disk_dev')]
def humanReadable(self):
return map(humanreadableSize,
self.Get())
return [humanreadableSize(x) for x in self.Get()]
class VariableOsDiskName(DeviceHelper, ReadonlyVariable):
@ -817,9 +793,7 @@ class VariableOsDiskOptions(ReadonlyVariable):
def getFormat(dev):
return fstab.getBy(what=fstab.OPTS, eq=dev)
return map(getFormat,
self.Get('os_disk_dev'))
return [getFormat(x) for x in self.Get('os_disk_dev')]
################################################
# Bind mount points
@ -1042,11 +1016,11 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable):
return path.normpath(val)
return val
return map(normpath, value)
return [normpath(x) for x in value]
def choice(self):
return map(lambda x: (x, self.getPerfectName(x) or x),
self.fixOsDiskDev(self.availDevs(choice=True))) + [("", "")]
return [(x, self.getPerfectName(x) or x) for x
in self.fixOsDiskDev(self.availDevs(choice=True))] + [("", "")]
def fixOsDiskDev(self, sourcelist=None):
"""
@ -1081,23 +1055,21 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable):
###########################
# check wrong dev
###########################
disks = filter(lambda x: x.startswith('/dev/'), value)
disks = [x for x in value if x.startswith('/dev/')]
# get original /dev names
cnDisks = (device.udev.get_device_info(name=x).get('DEVNAME', x)
for x in disks)
wrongDevices = list(set(cnDisks) -
set(self.fixOsDiskDev()))
wrongDevices = list(set(cnDisks) - set(self.fixOsDiskDev()))
if wrongDevices:
raise VariableError(_("Wrong device '%s'") % wrongDevices[0])
wrongSource = filter(lambda x: x and not x.startswith('/'), value)
wrongSource = [x for x in value if x and not x.startswith('/')]
if wrongSource:
raise VariableError(
_("Wrong bind mount point '%s'") % wrongSource[0])
##########################
# detect duplicate devices
##########################
dupDevices = list(set(filter(lambda x: disks.count(x) > 1,
disks)))
dupDevices = [x for x in disks if disks.count(x) > 1]
if dupDevices:
raise VariableError(
_("Device '%s' is used more than once") % dupDevices[0])
@ -1141,12 +1113,10 @@ class VariableOsLocationDest(LocationHelper, Variable):
return ""
return mount
return map(installMountPoint,
filter(lambda x: x[0] in source,
zip(self.Get('os_disk_dev'),
self.Get('os_disk_mount')) + \
zip(self.Get('os_bind_path'),
self.Get('os_bind_mountpoint'))))
return [installMountPoint(x) for x
in list(zip(self.Get('os_disk_dev'),self.Get('os_disk_mount'))) + \
list(zip(self.Get('os_bind_path'),self.Get('os_bind_mountpoint')))
if x[0] in source]
def set(self, value):
"""Add abilitiy not specify root"""
@ -1157,7 +1127,7 @@ class VariableOsLocationDest(LocationHelper, Variable):
return val
value = map(normpath, value)
return map(lambda x: x or "/", value)
return [x or "/" for x in value]
def choice(self):
if self.Get('cl_install_type') == 'flash':
@ -1177,10 +1147,8 @@ class VariableOsLocationDest(LocationHelper, Variable):
osInstallRootType = self.Get('os_install_root_type')
if osInstallRootType != "flash" and \
not "/usr" in value:
for mp, size in filter(lambda x: x[0] == '/' and x[1].isdigit() and \
int(x[1]) < minroot,
izip(value,
self.Get("os_location_size"))):
for mp, size in (x for x in zip(value, self.Get("os_location_size"))
if x[0] == '/' and x[1].isdigit() and int(x[1]) < minroot):
raise VariableError(
_("The root partition should be at least %s") % "7 Gb")
source = self.Get("os_location_source")
@ -1189,15 +1157,13 @@ class VariableOsLocationDest(LocationHelper, Variable):
################################
if not source:
return
if not filter(lambda x: x == "/", value):
if not [x for x in value if x == "/"]:
raise VariableError(_("To install the system, you need to "
"specify the root device"))
################################
disks = filter(lambda x: x[0].startswith('/dev/') and x[1],
zip(source, value))
disksDevs = map(lambda x: x[0], disks)
binds = filter(lambda x: not x[0].startswith('/dev/') and x[1],
zip(source, value))
disks = [x for x in zip(source, value) if x[0].startswith('/dev/') and x[1]]
disksDevs = [x[0] for x in disks]
binds = [x for x in zip(source, value) if not x[0].startswith('/dev/') and x[1]]
##########################
# detect efi specifing
##########################
@ -1213,18 +1179,16 @@ class VariableOsLocationDest(LocationHelper, Variable):
##########################
# detect duplicate mps
##########################
dupMP = list(set(filter(lambda x: value.count(x) > 1,
filter(lambda x: x and x != "swap",
value))))
dupMP = list(set([x for x in [y for y in value if y and y != "swap"] if value.count(x) > 1]))
if dupMP:
raise VariableError(
_("Mount point '%s' is used more than once") % dupMP[0])
#########################
# detect wrong bind
#########################
wrongBind = filter(lambda x: not x[0].startswith("/") or
not x[1].startswith("/"),
binds)
wrongBind = [x for x in binds
if not x[0].startswith("/") or
not x[1].startswith("/")]
if wrongBind:
raise VariableError(
_("Incorrect mount point (bind '%(bindSrc)s' to "
@ -1234,8 +1198,8 @@ class VariableOsLocationDest(LocationHelper, Variable):
#########################################
# Check '/' in start path of dest pointst
#########################################
wrongMP = filter(lambda x: x and not x.startswith("/") and x != "swap",
value)
wrongMP = [x for x in value
if x and not x.startswith("/") and x != "swap"]
if wrongMP:
raise VariableError(_("Wrong mount point '%s'") % wrongMP[0])
#########################################
@ -1269,12 +1233,11 @@ class VariableOsLocationDest(LocationHelper, Variable):
# check cross bind mount points
###############################
DEVICE, MP = 0, 1
srcMountPoints = map(lambda x: x[DEVICE], binds)
destMountPoints = map(lambda x: x[MP], binds)
wrongBind = filter(lambda x: x in destMountPoints, srcMountPoints)
srcMountPoints = (x[DEVICE] for x in binds)
destMountPoints = (x[MP] for x in binds)
wrongBind = [x for x in srcMountPoints if x in destMountPoints]
if wrongBind:
incompBind = filter(lambda x: x[1] == wrongBind[0],
zip(srcMountPoints, destMountPoints))
incompBind = [x for x in zip(srcMountPoints, destMountPoints) if x[1] == wrongBind[0]]
raise VariableError(
_("Source directory %(src)s is already used "
"for binding '%(bindSrc)s' to '%(bindDst)s'") \
@ -1286,10 +1249,10 @@ class VariableOsLocationDest(LocationHelper, Variable):
#######################################
osInstallRootType = self.Get('os_install_root_type')
if osInstallRootType == "flash":
if filter(lambda x: x and x != '/', value):
if [x for x in value if x and x != '/']:
raise VariableError(
_("Flash install does not support multipartition mode"))
if filter(lambda x: x == "swap", value):
if [x for x in value if x == "swap"]:
raise VariableError(
_("Flash install does not support swap disks"))
########################################
@ -1298,8 +1261,7 @@ class VariableOsLocationDest(LocationHelper, Variable):
installTypes = zip(self.Get('os_install_disk_dev'),
self.Get('os_install_disk_type'))
for checkType in ("raid", "lvm"):
memberData = filter(lambda x: checkType + "member" in x[1],
installTypes)
memberData = [x for x in installTypes if checkType + "member" in x[1]]
if memberData:
raise VariableError(
_("Unable to use {part} partition used by active "
@ -1317,13 +1279,12 @@ class VariableOsLocationFormat(LocationHelper, Variable):
def get(self):
if self.Get('cl_autopartition_set') == "on":
return self.Get('cl_autopartition_disk_format') + \
map(lambda x: "", self.Get('cl_autopartition_bind_path'))
["" for x in self.Get('cl_autopartition_bind_path')]
else:
mount = self.Get("os_location_dest")
source = self.Get("os_location_source")
value = [""] * len(source)
return map(self.defaultFormat(),
zip(source, mount, value))
return [self.defaultFormat()(x) for x in zip(source, mount, value)]
def choice(self):
if self.Get('cl_install_type') == "flash":
@ -1381,11 +1342,10 @@ class VariableOsLocationFormat(LocationHelper, Variable):
return wrap
def set(self, value):
value = map(lambda x: "vfat" if x == "uefi" else x, value)
value = ["vfat" if x == "uefi" else x for x in value]
mount = self.Get("os_location_dest")
source = self.Get("os_location_source")
return map(self.defaultFormat(),
zip(source, mount, value))
return [self.defaultFormat()(x) for x in zip(source, mount, value)]
def check(self, value):
osInstallRootType = self.Get('os_install_root_type')
@ -1423,17 +1383,14 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable):
def get(self):
if self.Get('cl_autopartition_set') == "on":
return map(lambda x: "on",
self.Get('cl_autopartition_disk_format')) + \
map(lambda x: "",
self.Get('cl_autopartition_bind_path'))
return ["on" for x in self.Get('cl_autopartition_disk_format')] + \
["" for x in self.Get('cl_autopartition_bind_path')]
else:
mount = self.Get("os_location_dest")
source = self.Get("os_location_source")
fs = self.Get("os_location_format")
value = [""] * len(source)
return map(self.defaultPerformFormat(),
zip(source, mount, fs, value))
return [self.defaultPerformFormat()(x) for x in zip(source, mount, fs, value)]
fixNtfs = lambda self, x: {'ntfs-3g': 'ntfs'}.get(x, x)
@ -1531,11 +1488,9 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable):
self.Get('os_location_dest'),
self.Get('os_location_format'),
value)
return map(self.defaultPerformFormat(),
map(lambda x: [x[DEV], x[MP], x[FS], ""] \
if x[FORMAT] == "off" and not x[DEV].startswith("/dev/")
else x,
info))
return [self.defaultPerformFormat()(x) for x
in [[y[DEV], y[MP], y[FS], ""]
if y[FORMAT] == "off" and not y[DEV].startswith("/dev/") else y for y in info]]
class VariableOsLocationSize(LocationHelper, SourceReadonlyVariable):
@ -1678,8 +1633,7 @@ class VariableOsInstallDiskDev(ReadonlyVariable, DeviceHelper):
self.Get('os_install_disk_dev_base'))
def humanReadable(self):
return map(lambda x: self.getPerfectName(x, defaultValue=x),
self.Get())
return [self.getPerfectName(x, defaultValue=x) for x in self.Get()]
class VariableOsInstallDiskUuid(ReadonlyVariable):
@ -1691,7 +1645,7 @@ class VariableOsInstallDiskUuid(ReadonlyVariable):
def get(self):
diskDev = self.Get('os_install_disk_dev')
hashUUID = getUUIDDict(revers=True)
return map(lambda x: hashUUID.get(x, "")[5:], diskDev)
return [hashUUID.get(x, "")[5:] for x in diskDev]
class VariableOsInstallDiskPartuuid(ReadonlyVariable):
"""
@ -1756,9 +1710,8 @@ class VariableOsInstallDiskUse(ReadonlyVariable):
def get(self):
"""Get real id (by cl_uuid_set) device"""
if self.Get('cl_uuid_set') == "on":
return map(lambda x: "UUID=%s" % x[0] if x[0] else x[1],
zip(self.Get('os_install_disk_uuid'),
self.Get('os_install_disk_dev')))
return ["UUID=%s" % x[0] if x[0] else x[1] for x
in zip(self.Get('os_install_disk_uuid'), self.Get('os_install_disk_dev'))]
else:
return self.Get('os_install_disk_dev')
@ -1820,11 +1773,11 @@ class VariableOsInstallDiskPerformFormat(ReadonlyVariable):
type = "bool-list"
def get(self):
_format = map(lambda x: x[2],
filter(lambda x: x[0].startswith('/dev/') and x[1],
zip(self.Get('os_location_source'),
self.Get('os_location_dest'),
self.Get('os_location_perform_format'))))
_format = [x[2] for x
in zip(self.Get('os_location_source'),
self.Get('os_location_dest'),
self.Get('os_location_perform_format'))
if x[0].startswith('/dev/') and x[1]]
if self.GetBool('cl_autopartition_set'):
efiformat = ['on' for x in self.Get('os_install_uefi')]
res = efiformat + _format
@ -1880,9 +1833,7 @@ class VariableOsInstallDiskName(Variable):
else:
return diskLabel.get(dev, '')
return map(changeLabel,
self.ZipVars('os_install_disk_dev',
'os_install_disk_mount'))
return [changeLabel(x) for x in self.ZipVars('os_install_disk_dev','os_install_disk_mount')]
class VariableOsInstallDiskSize(SourceReadonlyVariable):
@ -2118,7 +2069,7 @@ class VariableOsInstallUefi(LocationHelper, Variable):
return self.select('os_device_efi',
os_device_dev=efidev, limit=1) or efidev
return efidev
return filter(lambda x: x != "off", map(transform, value))
return [x for x in map(transform, value) if x != "off"]
def choice(self):
deviceParentMap = self.ZipVars('os_device_dev',
@ -2209,8 +2160,7 @@ class VariableOsInstallMbr(LocationHelper, Variable):
return self.Get('cl_autopartition_mbr')
if self.Get('os_install_root_type') in ("flash", "usb-hdd"):
rootdev = self.Get('os_install_root_dev')
device = filter(lambda x: x in rootdev,
self.Get('os_device_dev'))
device = [x for x in self.Get('os_device_dev') if x in rootdev]
if device:
return [device[0]]
else:
@ -2233,7 +2183,7 @@ class VariableOsInstallMbr(LocationHelper, Variable):
def set(self, value):
# support off value
return filter(lambda x: x != "off", value)
return [x for x in value if x != "off"]
def check(self, value):
if self.GetBool('cl_autopartition_set'):
@ -2435,9 +2385,8 @@ class VariableOsInstallFstabMountConf(DeviceHelper, ReadonlyVariable):
bindData = self.ZipVars('os_install_bind_path',
'os_install_bind_mountpoint')
bindLines = "\n".join(map(lambda x: "%s\t%s\tnone\tbind\t0 0" \
% (x[0], x[1]), bindData))
return "\n".join(filter(lambda x: x, [rootLine, otherLines, bindLines]))
bindLines = "\n".join(("%s\t%s\tnone\tbind\t0 0" % (x[0], x[1]) for x in bindData))
return "\n".join((x for x in [rootLine, otherLines, bindLines] if x))
class VariableOsInstallFstabEfiConf(VariableOsInstallFstabMountConf):
@ -2464,7 +2413,7 @@ class VariableOsInstallFstabEfiConf(VariableOsInstallFstabMountConf):
for used, mp, fs, opts, dev in devicesForFstab
)
return "\n".join(filter(lambda x: x, [efiLines]))
return "\n".join((x for x in [efiLines] if x))
class VariableOsInstallFstabSwapConf(VariableOsInstallFstabMountConf):
@ -2473,13 +2422,12 @@ class VariableOsInstallFstabSwapConf(VariableOsInstallFstabMountConf):
"""
def get(self):
return "\n".join(map(lambda x: "%s\tnone\tswap\tsw\t0 0" % \
self._commentFstab(x[0], "swap", x[2]),
self.Select(['os_install_disk_use',
'os_install_disk_mount',
'os_install_disk_dev'],
where='os_install_disk_mount',
eq='swap')))
return "\n".join(("%s\tnone\tswap\tsw\t0 0" % self._commentFstab(x[0], "swap", x[2]) for x
in self.Select(['os_install_disk_use',
'os_install_disk_mount',
'os_install_disk_dev'],
where='os_install_disk_mount',
eq='swap')))
class VariableClInstallType(Variable):

@ -34,7 +34,7 @@ from calculate.install.distr import (Distributive, PartitionDistributive,
from calculate.lib.cl_lang import setLocalTranslate, _
from calculate.install.fs_manager import FileSystemManager
from functools import reduce
from functools import reduce, cmp_to_key
setLocalTranslate('cl_install3', sys.modules[__name__])
@ -93,11 +93,10 @@ class DistroRepository(Linux):
def _getAvailableShortnames(self, dirs):
"""Get available distributives shortnames"""
distros = filter(lambda x: x,
map(self.reDistName.search,
self._getAvailableDistributives(dirs)))
return sorted(list(set(map(lambda x: x.groupdict()['name'], distros))))
distros = [x for x
in map(self.reDistName.search, self._getAvailableDistributives(dirs))
if x]
return sorted(list(set([x.groupdict()['name'] for x in distros])))
def opcompareByString(self, buf):
if buf:
reOp = re.compile("^(!=|=|==|<=|>=|>|<)?(\d+.*)$")
@ -161,19 +160,15 @@ class DistroRepository(Linux):
return [pathname]
else:
# discard inner directories
return filter(lambda x: not path.isdir(path.join(pathname, x)),
listDirectory(pathname))
return [x for x in listDirectory(pathname) if not path.isdir(path.join(pathname, x))]
# get lists files in directories
allFiles = map(lambda x: map(lambda y: path.join(x, y),
listdistr(x)),
dirs)
allFiles = [[path.join(x, y) for y in listdistr(x)] for x in dirs]
# filter distributives
return filter(distfilter,
# join files lists to one list
reduce(lambda x, y: x + y,
allFiles, []))
# join files lists to one list
return [x for x in reduce(lambda x, y: x + y, allFiles, []) if distfilter(x)]
@staticmethod
def extcomparator(self, *exts):
"""Compare extensions"""
mapExts = {'iso': 0,
@ -181,9 +176,16 @@ class DistroRepository(Linux):
'isodir': -2,
'partdir': -3,
'dir': -4}
return cmp(mapExts.get(exts[0], -4), mapExts.get(exts[1], -4))
# return cmp(mapExts.get(exts[0], -4), mapExts.get(exts[1], -4))
#no cmp in python3, instead do (a > b) - (a < b)
return (mapExts.get(exts[0], -4) > mapExts.get(exts[1], -4)) - \
(mapExts.get(exts[0], -4) < mapExts.get(exts[1], -4))
def sortdistrfunc(self, x, y):
@staticmethod
def sortdistrfunc(x, y):
"""Func of comparing two distributive"""
ver1, ver2 = x[1].get('os_linux_ver', ""), y[1].get('os_linux_ver', "")
if ver1 and ver2 and ver1 != "0" and ver2 != "0" and ver1 != ver2:
@ -199,7 +201,7 @@ class DistroRepository(Linux):
return cmp(int(ser1), int(ser2))
ext1 = x[1].get('ext', "")
ext2 = y[1].get('ext', "")
return self.extcomparator(ext1, ext2)
return DistroRepository.extcomparator(ext1, ext2)
def getAvailableDristibutives(self, dirs, system=None, shortname=None,
march=None, version=None, build=None,
@ -210,12 +212,10 @@ class DistroRepository(Linux):
availDistrs = self._getAvailableDistributives(dirs, system, shortname,
march, version,
build)
availDistrs = filter(lambda x: x[1] and "ext" in x[1] and
not x[1]["ext"] in discardType,
map(lambda x: (x, self._getDistrInfo(x)),
availDistrs))
return map(lambda x: x[0],
sorted(availDistrs, self.sortdistrfunc, reverse=True))
availDistrs = (x for x
in [(y, self._getDistrInfo(y)) for y in availDistrs]
if x[1] and "ext" in x[1] and not x[1]["ext"] in discardType)
return [x[0] for x in sorted(availDistrs, key=cmp_to_key(DistroRepository.sortdistrfunc), reverse=True)]
def getBestDistributive(self, dirs, system=None, shortname=None, march=None,
version=None, build=None, discardType=()):
@ -237,7 +237,7 @@ class DistroRepository(Linux):
path.join(y, x)),
listDirectory(y)),
existsdirs, [])
listimgs = filter(lambda x: x, listimgs)
listimgs = [x for x in listimgs if x]
if listimgs:
return max(listimgs, key=keyfunc).group()
return ""
@ -383,9 +383,7 @@ class VariableClImageFilename(DistroRepository, Variable):
discardType=discardType)
if self.wasSet and not self.value in distros:
distros.append(self.value)
return sorted(map(lambda x: (
x, self.humanImageName(self._getDistrInfo(x), x)), distros),
key=itemgetter(1))
return sorted(((x, self.humanImageName(self._getDistrInfo(x), x)) for x in distros), key=itemgetter(1))
class VariableClImageArchMachine(DistroRepository, Variable):
@ -500,21 +498,17 @@ class VariableClImagePath(ReadonlyVariable):
livedistr = ['/run/initramfs/squashfs',
'/run/initramfs/live',
'/mnt/cdrom']
livedistr = filter(listDirectory,
livedistr)[:1]
livedistr = [x for x in livedistr if listDirectory(x)][:1]
else:
livedistr = []
# search all partition for source installation distributive
rootDev = self.Get('os_install_root_dev')
livedistr += \
map(lambda x: x[0],
filter(lambda x: " live" in x[1] and x[0] != rootDev,
zip(self.Get('os_disk_dev'),
self.Get('os_disk_content'))))
livedistr = [x[0] for x
in zip(self.Get('os_disk_dev'), self.Get('os_disk_content'))
if " live" in x[1] and x[0] != rootDev]
# add to standard path
return filter(path.exists,
['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr)
return [x for x in ['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr if path.exists(x)]
class VariableClSource(ReadonlyVariable):

@ -77,7 +77,7 @@ class VariableOsInstallKernelScheduler(Variable):
else:
currentScheduler = getValueFromCmdLine(
CmdlineParams.IOScheduler)
if currentScheduler in map(lambda x: x[0], self.choice()):
if currentScheduler in (x[0] for x in self.choice()):
return currentScheduler
return self.Get('os_install_kernel_schedule_default')
@ -104,7 +104,7 @@ class VariableOsInstallKernelScheduler(Variable):
return _("I/O scheduler unavailable for Flash install")
class KernelConfig(object):
class KernelConfig():
def __init__(self, kernel_config):
self.data = readFile(kernel_config).split('\n')
self.config = kernel_config
@ -224,9 +224,9 @@ class VariableOsInstallKernelScheduleData(ReadonlyTableVariable):
'CONFIG_IOSCHED_NOOP=y': 'noop',
'CONFIG_IOSCHED_CFQ=y': 'cfq',
'CONFIG_IOSCHED_DEADLINE=y': 'deadline'}
installed = map(schedulers.get,
filter(lambda x: x in schedulers,
self.Get('os_install_kernel_config'))) or ['cfq']
installed = [schedulers.get(x) for x
in self.Get('os_install_kernel_config')
if x in schedulers] or ['cfq']
return [[x, "on" if x in installed else "off"]
for x in sorted(schedulers.values())]
@ -336,15 +336,13 @@ class KernelHelper(VariableInterface):
def getFilesByType(self, pathname, descr):
"""Get files from "pathname" has "descr" in descriptions"""
filelist = map(lambda x: path.join(pathname, x), os.listdir(pathname))
filelist = [path.join(pathname, x) for x in os.listdir(pathname)]
ftype = typeFile(magic=MAGIC_COMPRESS | MAGIC_SYMLINK).getMType
filesWithType = map(lambda x: (x, ftype(x)),
filter(path.exists,
filelist))
return filter(lambda x: x[1] and descr in x[1], filesWithType)
filesWithType = [(x, ftype(x)) for x in filelist if path.exists(x)]
return [x for x in filesWithType if x[1] and descr in x[1]]
def getInitrdFiles(self, pathname):
filelist = map(lambda x: path.join(pathname, x), os.listdir(pathname))
filelist = [path.join(pathname, x) for x in os.listdir(pathname)]
return [x for x in filelist if path.exists(x) and InitrdFile.is_cpio(x)]
def getInitrd(self, arch, shortname, chroot, kernel, suffix="",
@ -372,14 +370,12 @@ class KernelHelper(VariableInterface):
bootdir = path.join(chroot, 'boot')
initramfsFiles = self.getInitrdFiles(bootdir)
initramfsWithVer = \
filter(lambda x: (kernelVersion in x[1] or
origKernelVer in x[1]) and \
x[0].endswith(suffix) and \
(
not notsuffix or not x[0].endswith(notsuffix)),
map(lambda x: (x, initrd_version_by_name(x)),
initramfsFiles))
initramfsWithVer = [x for x
in [(y, initrd_version_by_name(y)) for y in initramfsFiles]
if (kernelVersion in x[1] or
origKernelVer in x[1]) and
x[0].endswith(suffix) and
(not notsuffix or not x[0].endswith(notsuffix))]
if initramfsWithVer:
return path.split(min(initramfsWithVer,
key=itemgetter(0))[0])[-1]
@ -397,18 +393,28 @@ class VariableOsInstallKernel(ReadonlyVariable, KernelHelper):
validKernel = listDirectory(modulesdir)
kernelFiles = self.getFilesByType(bootdir, "Linux kernel")
installMarch = self.Get('os_install_arch_machine')
kernelsWithVer = \
map(lambda x: (
x[0], (getTupleVersion("".join(x[1].groups()[0:3:2])),
path.getmtime(x[0]))),
# convert version to tuple( versionTuple, mtime)
# version detect, for this version lib contains moudules
# kernel arch equal install arch
ifilter(lambda x: x[1] and x[1].group() in validKernel and
installMarch in x[0].rpartition('/')[2],
# (filename,version)
imap(lambda x: (x[0], self.reFindVer.search(x[1])),
kernelFiles)))
# kernelsWithVer = \
# list(map(lambda x: (
# x[0], (getTupleVersion("".join(x[1].groups()[0:3:2])),
# path.getmtime(x[0]))),
# # convert version to tuple( versionTuple, mtime)
# # version detect, for this version lib contains moudules
# # kernel arch equal install arch
# filter(lambda x: x[1] and x[1].group() in validKernel and
# installMarch in x[0].rpartition('/')[2],
# # (filename,version)
# map(lambda x: (x[0], self.reFindVer.search(x[1])),
# kernelFiles))))
kernelsWithVer = [(x[0],
(getTupleVersion("".join(x[1].groups()[0:3:2])),
path.getmtime(x[0]))) for x
# convert version to tuple( versionTuple, mtime)
# version detect, for this version lib contains moudules
# kernel arch equal install arch
in [y for y
# (filename,version)
in [(z[0], self.reFindVer.search(z[1])) for z in kernelFiles]
if y[1] and y[1].group() in validKernel and installMarch in y[0].rpartition('/')[2]]]
if kernelsWithVer:
return path.split(max(kernelsWithVer, key=itemgetter(1))[0])[-1]
else:
@ -469,9 +475,8 @@ class VariableOsInstallKernelCpufreq(ReadonlyVariable):
def get(self):
"""Get cpufreq (and other from modules_3= param) from conf.d/modules"""
cpufreqmods = map(lambda x: x.partition('=')[2].strip("\n '\""),
filter(lambda x: x.startswith('modules_3'),
readLinesFile('/etc/conf.d/modules')))
cpufreqmods = [x.partition('=')[2].strip("\n '\"") for x
in readLinesFile('/etc/conf.d/modules') if x.startswith('modules_3')]
if cpufreqmods:
return cpufreqmods[0]
else:

@ -53,9 +53,8 @@ class VariableOsInstallLinguas(LocaleVariable):
def get(self):
def get_linguas(lines):
linguas = map(lambda x: x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("LINGUAS="),
lines))
linguas = [x.strip().rpartition('=')[-1].strip('"\'') for x
in lines if x.startswith("LINGUAS=")]
return linguas[-1] if linguas else ""
makeconf = '/etc/make.conf'
@ -69,11 +68,8 @@ class VariableOsInstallLinguas(LocaleVariable):
# get linguas from make.conf, emerge --info or default
curlanguage = self.Get('os_install_locale_language')
return get_linguas(readLinesFile(makeconf)) or \
" ".join(filter(lambda x: x == "en" or x == curlanguage,
get_linguas(
process(
*infocommand).readlines() or "").split())) or \
defaultLinguas
" ".join((x for x in get_linguas(process(*infocommand).readlines() or "").split() if x == "en" or x == curlanguage)) or defaultLinguas
class VariableOsInstallLocaleConsolefont(LocaleVariable):
@ -137,8 +133,8 @@ class VariableOsInstallLocaleLang(LocaleVariable):
return self.Get('os_locale_lang')
def choice(self):
return zip(self.Get('os_lang'),
map(str, self.Get('os_lang', humanreadable=True)))
return list(zip(self.Get('os_lang'),
map(str, self.Get('os_lang', humanreadable=True))))
class VariableOsInstallLocaleKeyboardLayout(LocaleVariable):
@ -164,8 +160,8 @@ class VariableOsInstallLocaleKeyboardLayout(LocaleVariable):
return self.Get('os_locale_keyboard_layout')
def choice(self):
return zip(self.Get('os_keyboard_layout'),
map(str, self.Get('os_keyboard_layout', humanreadable=True)))
return list(zip(self.Get('os_keyboard_layout'),
map(str, self.Get('os_keyboard_layout', humanreadable=True))))
class VariableOsInstallLocaleLanguage(LocaleVariable):
@ -337,11 +333,9 @@ class VariableOsInstallClockTimezone(LocaleVariable):
try:
lang = self.Get(self.locale_varname).split('_')[1]
nativeTZ = map(lambda x: x.encode('utf-8'),
country_timezones[lang])
nativeTZ = [x.encode('utf-8') for x in country_timezones[lang]]
source = nativeTZ + ["---"] + \
sorted(filter(lambda x: not x in nativeTZ, source),
key=sortkey)
sorted([x for x in source if not x in nativeTZ], key=sortkey)
except (KeyError, IndexError) as e:
pass
return list(self.generateComments(source))

@ -188,8 +188,7 @@ class VariableOsNetInterfacesInfo(NetHelper, ReadonlyVariable):
else:
listInterfacesInfo.append((interface,
ipaddr if ipaddr else _("Off")))
return ", ".join(map(lambda x: "%s (%s)" % (x[0], x[1]),
listInterfacesInfo))
return ", ".join(("%s (%s)" % (x[0], x[1]) for x in listInterfacesInfo))
class VariableOsInstallNetData(NetHelper, TableVariable):
@ -310,11 +309,9 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable):
return ""
pciEthernet = lspci(shortInfo=True)
return map(lambda x: "{vendor} {name}".format(**x),
map(lambda x: pciEthernet.get(getPci(x),
{'vendor': _("Unknown"),
'name': _("vendor")}),
self.Get('os_install_net_interfaces')))
return ["{vendor} {name}".format(**x) for x
in [pciEthernet.get(getPci(y), {'vendor': _("Unknown"), 'name': _("vendor")}) for y
in self.Get('os_install_net_interfaces')]]
class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable):
@ -336,7 +333,7 @@ class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable):
return "local"
def get(self):
return map(self._mactype, self.Get('os_install_net_mac'))
return [self._mactype(x) for x in self.Get('os_install_net_mac')]
class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
@ -349,8 +346,7 @@ class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
self.label = _("MAC")
def get(self):
return map(lambda x: getMac(x).lower(),
self.Get('os_install_net_interfaces'))
return [getMac(x).lower() for x in self.Get('os_install_net_interfaces')]
class VariableOsInstallNetStatus(NetHelper, Variable):
@ -363,8 +359,7 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
self.label = _("IP address")
def get(self):
return map(self.getDefaultValue,
self.Get('os_install_net_interfaces'))
return [self.getDefaultValue(x) for x in self.Get('os_install_net_interfaces')]
def getDefaultValue(self, iface):
def statusValue(ipaddr, dhcp):
@ -387,16 +382,14 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
if rootDevNfs or isDhcpIp(iface) else "off")
def set(self, value):
value = map(lambda x: x.lower() if x else x, value)
value = (x.lower() if x else x for x in value)
ifaces = self.Get('os_install_net_interfaces')
return map(lambda x: self.getDefaultValue(x[1]) \
if x[0] == "auto" else x[0],
zip(value, ifaces))
return [self.getDefaultValue(x[1]) if x[0] == "auto" else x[0] for x
in zip(value, ifaces)]
def check(self, value):
for status in value:
if status not in map(lambda x: x[0], self.choice()) and \
not checkIp(status):
if status not in (x[0] for x in self.choice()) and not checkIp(status):
raise VariableError(_("Wrong IP address %s") % status)
def choice(self):
@ -415,10 +408,10 @@ class VariableOsInstallNetIp(NetHelper, ReadonlyVariable):
self.label = _("IP address")
def get(self):
return map(lambda x: "" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1],
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status')))
return ["" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1] for x
in zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status'))]
# def check(self,value):
# dhcps = self.Get('os_install_net_dhcp_set')
@ -439,9 +432,9 @@ class VariableOsInstallNetNetwork(NetHelper, ReadonlyVariable):
self.label = _("Network")
def get(self):
return map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "",
zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask')))
return [getIpNet(x[0], x[1]) if x[0] and x[1] else "" for x
in zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask'))]
class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable):
@ -457,8 +450,7 @@ class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable):
"""
Get CIDR of ip,net (Example: 24)
"""
return map(lambda x: maskToCidr(x) if x else '',
self.Get('os_install_net_mask'))
return [maskToCidr(x) if x else '' for x in self.Get('os_install_net_mask')]
class VariableOsInstallNetMask(NetHelper, Variable):
@ -471,8 +463,8 @@ class VariableOsInstallNetMask(NetHelper, Variable):
self.label = _("Mask")
def get(self):
return map(lambda x: cidrToMask(getMask(x)),
self.Get('os_install_net_interfaces'))
return [cidrToMask(getMask(x)) for x
in self.Get('os_install_net_interfaces')]
def set(self, value):
"""
@ -485,14 +477,13 @@ class VariableOsInstallNetMask(NetHelper, Variable):
else:
return x
res = map(convertCidrToMask, value)
res = [convertCidrToMask(x) for x in value]
return res
def check(self, value):
dhcps = self.Get('os_install_net_status')
wrongMask = filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \
not checkMask(x[0]),
zip(value, dhcps))
wrongMask = [x for x in zip(value, dhcps)
if (x[0] or not x[1] in ("off", "dhcp")) and not checkMask(x[0])]
if wrongMask:
raise VariableError(_("Wrong mask %s") % wrongMask[0][0])
@ -514,8 +505,8 @@ class VariableOsInstallNetDhcpSet(NetHelper, Variable):
self.label = _("DHCP")
def get(self):
return map(lambda x: "on" if x == "dhcp" else "off",
self.Get('os_install_net_status'))
return ["on" if x == "dhcp" else "off" for x
in self.Get('os_install_net_status')]
class VariableOsInstallNetRouteData(NetHelper, TableVariable):
@ -544,19 +535,18 @@ class VariableOsInstallNetRouteData(NetHelper, TableVariable):
interfaces = self.Get('os_install_net_interfaces')
interfaces_status = self.Get('os_install_net_status')
interfaces_network = self.Get('os_install_net_network')
staticInterface = \
map(itemgetter(0, 2),
filter(lambda x: not x[1] in ("off", "dhcp"),
zip(interfaces, interfaces_status, interfaces_network)))
staticInterface = [itemgetter(0, 2)(x) for x
in zip(interfaces, interfaces_status, interfaces_network)
if not x[1] in ("off", "dhcp")]
route_data = []
if staticInterface:
staticInterface, skipNet = zip(*staticInterface)
return map(lambda x: [x[0],
x[1].get('via', ''),
x[1].get('dev', ''),
x[1].get('src', '')],
ifilter(lambda x: not x[0] in skipNet,
ip.getRouteTable(staticInterface))) or [[]]
return [[x[0],
x[1].get('via', ''),
x[1].get('dev', ''),
x[1].get('src', '')] for x
in ip.getRouteTable(staticInterface)
if not x[0] in skipNet] or [[]]
return [[]]
def getHumanReadableAuto(self):
@ -598,12 +588,11 @@ class VariableOsInstallNetRouteNetwork(NetHelper, FieldValue, Variable):
##########################
# detect duplicate network
##########################
for wrongnet in ifilterfalse(ip.checkNet,
ifilter("default".__ne__,
for wrongnet in filterfalse(ip.checkNet,
filter("default".__ne__,
value)):
raise VariableError(_("Wrong network %s") % wrongnet)
dupNetwork = list(set(filter(lambda x: value.count(x) > 1,
value)))
dupNetwork = list(set([x for x in value if value.count(x) > 1]))
if dupNetwork:
raise VariableError(
_("Network '%s' is used more than once") % dupNetwork[0])
@ -626,19 +615,14 @@ class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable):
NET, GW = 0, 1
netsGw = zip(self.Get('os_install_net_route_network'),
value)
nets = filter(lambda x: x and x != "default",
chain(self.Get('os_install_net_route_network'),
self.Get('os_install_net_network')))
nets = [x for x in chain(self.Get('os_install_net_route_network'),
self.Get('os_install_net_network'))
if x and x != "default"]
for wrongip in ifilterfalse(ip.checkIp, value):
for wrongip in filterfalse(ip.checkIp, value):
raise VariableError(_("Wrong gateway IP %s") % wrongip)
wrongGws = map(lambda x: x[GW],
filter(lambda x: not ip.isIpInNet(x[GW],
*(set(nets) - set(
x[NET]))),
filter(lambda x: x[GW],
netsGw)))
wrongGws = [x[GW] for x in [y for y in netsGw if y[GW]]
if not ip.isIpInNet(x[GW], *(set(nets) - set(x[NET])))]
if wrongGws:
raise VariableError(_("Gateways %s are unreachable") %
(",".join(wrongGws)))
@ -674,12 +658,11 @@ class VariableOsInstallNetRouteSrc(NetHelper, FieldValue, Variable):
return [""] + self.Get('os_install_net_ip')
def check(self, value):
for wrongip in ifilterfalse(ip.checkIp,
ifilter(None, value)):
for wrongip in filterfalse(ip.checkIp,
filter(None, value)):
raise VariableError(_("Wrong source IP %s") % wrongip)
ipAddrs = self.Get('os_install_net_ip')
wrongIps = filter(lambda x: x and not x in ipAddrs,
value)
wrongIps = [x for x in value if x and not x in ipAddrs]
if wrongIps:
raise VariableError(
_("Wrong IP address %s in the specified source IP") %
@ -697,14 +680,13 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
self.Get('os_install_net_route_dev'),
self.Get('os_install_net_route_src'))
DEV, IP, CIDR, NET = 0, 1, 2, 1
return map(lambda x: performFunc(x[DEV], x[NET], routeMatrix),
# union ip and mask to ip/net
map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \
if x[IP] and x[CIDR] else (x[DEV], ""),
# filter(lambda x:x[IP] and x[CIDR],
zip(self.Get('os_install_net_interfaces'),
return [performFunc(x[DEV], x[NET], routeMatrix) for x
# ip and mask to ip/net
in [(y[DEV], ip.getIpNet(y[IP], cidr=y[CIDR]))
if y[IP] and y[CIDR] else (y[DEV], "") for y
in zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'),
self.Get('os_install_net_cidr'))))
self.Get('os_install_net_cidr'))]]
def get(self):
"""Route info for conf.d/net"""
@ -719,10 +701,11 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
NET, GW, DEV, SRC = 0, 1, 2, 3
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
route_list = filter(lambda x: (interface == x[DEV] or defaultDev and
interface == defaultDev) \
and net != x[NET], routeMatrix)
route_list = [x for x in routeMatrix
if (interface == x[DEV] or
defaultDev and
interface == defaultDev) and
net != x[NET]]
nets = []
route_list_uniqnet = []
for net, gw, dev, src in route_list:
@ -730,10 +713,9 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
route_list_uniqnet.append([net, gw, dev, src])
nets.append(net)
route_strs = map(lambda x: "{net}{gateway}{src}".format(
net=x[NET],
gateway=" via %s" % x[GW] if x[GW] else "",
src=" src %s" % x[SRC] if x[SRC] else ""), route_list_uniqnet)
route_strs = ("{net}{gateway}{src}".format(net=x[NET], gateway=" via %s" % x[GW]
if x[GW] else "", src=" src %s" % x[SRC] if x[SRC] else "") for x
in route_list_uniqnet)
# build string for route from net,gateway,dev and src
return "\n".join(route_strs)
@ -757,29 +739,42 @@ class VariableOsInstallNetNmroute(VariableOsInstallNetRoute):
def getRouteForInterfaceNM(interface, net, routeMatrix):
NET, GW, DEV, SRC = 0, 1, 2, 3
defaultGw = map(lambda x: "%s;" % x[GW],
filter(lambda x: interface == x[DEV] and \
x[NET] == "default",
routeMatrix))
return "{0}\n".format(defaultGw[0] if defaultGw else "") + \
"\n".join(
# build string for route from net,gateway,dev and src
map(lambda
x: "routes{num}={ip};{cidr};{gateway};0;".format(
defaultGw = ["%s;" % x[GW] for x in routeMatrix
if interface == x[DEV] and x[NET] == "default"]
# return "{0}\n".format(defaultGw[0] if defaultGw else "") + \
# "\n".join(
# # build string for route from net,gateway,dev and src
# map(lambda
# x: "routes{num}={ip};{cidr};{gateway};0;".format(
# num=x[0] + 1,
# ip=x[1][NET].partition('/')[0],
# cidr=x[1][NET].partition('/')[2],
# gateway=x[1][GW] if x[1][GW] else "0.0.0.0"),
# # filter by interface and discard direct routes
# # example: for 192.168.1.5/24 discard 192.168.1.0/24 net
# enumerate(
# filter(lambda x: (interface == x[
# DEV] or defaultDev and
# interface == defaultDev) and net !=
# x[
# NET] and \
# x[NET] != "default",
# routeMatrix))))
return "{0}\n".format(defaultGw[0] if defaultGw else "") + "\n".join(
# build string for route from net,gateway,dev and src
("routes{num}={ip};{cidr};{gateway};0;".format(
num=x[0] + 1,
ip=x[1][NET].partition('/')[0],
cidr=x[1][NET].partition('/')[2],
gateway=x[1][GW] if x[1][GW] else "0.0.0.0"),
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
enumerate(
filter(lambda x: (interface == x[
DEV] or defaultDev and
interface == defaultDev) and net !=
x[
NET] and \
x[NET] != "default",
routeMatrix))))
gateway=x[1][GW] if x[1][GW] else "0.0.0.0") for x
# filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net
in enumerate((x for x in routeMatrix
if (interface == x[DEV] or
defaultDev and
interface == defaultDev) and
net !=x[NET] and
x[NET] != "default"))))
return self.performRouteData(getRouteForInterfaceNM)
@ -799,10 +794,8 @@ class VariableOsInstallNetConfAvailable(NetHelper, Variable):
with image as distr:
try:
distrPath = image.getDirectory()
return map(itemgetter(0, 2),
filter(lambda x: not x[1] or isPkgInstalled(x[1],
prefix=distrPath),
mapNetConf))
return [itemgetter(0, 2)(x) for x in mapNetConf
if not x[1] or isPkgInstalled(x[1], prefix=distrPath)]
except DistributiveError as e:
pass
return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1))
@ -822,10 +815,9 @@ class VariableOsInstallNetConf(NetHelper, Variable):
def get(self):
"""Net setup (networkmanager or openrc)"""
if filter(lambda x: x.lower() == "networkmanager",
listDirectory('/etc/runlevels/boot') +
listDirectory('/etc/runlevels/default')) \
or self.Get('os_root_type') == "livecd":
if [x for x in listDirectory('/etc/runlevels/boot') +
listDirectory('/etc/runlevels/default')
if x.lower() == "networkmanager"] or self.Get('os_root_type') == "livecd":
nm = "networkmanager"
else:
nm = ""
@ -867,10 +859,9 @@ class VariableOsInstallNetDnsSearch(NetHelper, Variable):
def get(self):
"""Get current name servers"""
dnsSearch = " ".join(
map(lambda x: x.strip().partition("search")[2].strip(),
filter(lambda x: x.lstrip().startswith("search"),
readLinesFile('/etc/resolv.conf'))))
dnsSearch = " ".join((x.strip().partition("search")[2].strip() for x
in readLinesFile('/etc/resolv.conf')
if x.lstrip().startswith("search")))
return "" if self.isDNSByDHCP() else dnsSearch
def humanReadable(self):
@ -894,17 +885,16 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
return " ".join(re.split('[; ,]', value))
def get(self):
dnsIps = filter(ip.checkIp,
map(lambda x: x.strip().partition("nameserver")[
2].strip(),
filter(
lambda x: x.lstrip().startswith("nameserver"),
readLinesFile('/etc/resolv.conf'))))
dnsIps = (x for x
in (y.strip().partition("nameserver")[2].strip() for y
in readLinesFile('/etc/resolv.conf')
if y.lstrip().startswith("nameserver"))
if ip.checkIp(x))
return "" if self.isDNSByDHCP() else " ".join(dnsIps)
def check(self, value):
reIp = re.compile(ip.IP_ADDR)
if any(ifilterfalse(reIp.match, value.split(' '))):
if any(filterfalse(reIp.match, value.split(' '))):
raise VariableError(_("Wrong IP address for DNS"))
def humanReadable(self):
@ -938,11 +928,11 @@ class VariableOsInstallPxeIp(Variable):
def get(self):
ips = self.Get('os_net_ip').split(',')
for ipaddr in ifilter(None, ips):
for ipaddr in filter(None, ips):
return ipaddr
else:
return ""
def choice(self):
ips = self.Get('os_net_ip').split(',')
return filter(None, ips)
return [x for x in ips if x]

@ -121,7 +121,7 @@ class VariableOsFormatType(ReadonlyVariable):
def get(self):
"""Filesystem format support by calcualte-install"""
return FileSystemManager.supportFS.keys()
return list(FileSystemManager.supportFS.keys())
class VariableOsFormatUse(ReadonlyVariable):
@ -141,7 +141,7 @@ class VariableOsFormatUse(ReadonlyVariable):
return "no"
def get(self):
return map(self.checkFunc, self.Get('os_format_type'))
return [self.checkFunc(x) for x in self.Get('os_format_type')]
class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable):
@ -194,10 +194,9 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable):
содержит пустую строку
"""
def get(self):
rootPasswd = map(lambda x: x[1],
filter("root".__eq__,
map(lambda x: x.split(':')[0:2],
readLinesFile('/etc/shadow'))))
rootPasswd = [x[1] for x
in [y.split(':')[0:2] for y in readLinesFile('/etc/shadow')]
if "root".__eq__(x)]
if rootPasswd:
rootPasswd = rootPasswd[0]
else:
@ -419,7 +418,7 @@ class VariableClMigrateAdmin(UserHelper, Variable):
for x in self.Get('cl_migrate_user')]
def set(self, value):
return map(lambda x: x if x else self.default_value, value)
return [x if x else self.default_value for x in value]
class VariableOsAvailableGroups(ReadonlyVariable):
@ -476,8 +475,7 @@ class VariableClMigrateUserGroups(UserHelper, Variable):
yield value
def set(self, value):
value = map(lambda x: sorted(list(set(self.process_groups(x)))),
value)
value = [sorted(list(set(self.process_groups(x)))) for x in value]
return value
def getPrimaryGroup(self, username):
@ -491,11 +489,9 @@ class VariableClMigrateUserGroups(UserHelper, Variable):
User groups
"""
passwdList = getPasswdUsers()
return map(lambda x: sorted(self.getPrimaryGroup(x) +
(getUserGroups(x)
if x in passwdList else
self.getDefaultGroups())),
self.Get('cl_migrate_user'))
return [sorted(self.getPrimaryGroup(x) + (getUserGroups(x)
if x in passwdList else self.getDefaultGroups())) for x
in self.Get('cl_migrate_user')]
def choice(self):
"""
@ -525,15 +521,13 @@ class VariableClMigrateUserPwd(UserHelper, Variable):
if migrateusers:
lenData = 9
with open(fileName) as f:
shadowData = filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), f))
shadowData = filter(lambda x: x[0] in migrateusers, shadowData)
shadowData = map(lambda x: (x[0], x[1]), shadowData)
shadowUsers = map(lambda x: x[0], shadowData)
shadowData = [x for x in [y.rstrip().split(":") for y in f] if len(x) == lenData]
shadowData = [x for x in shadowData if x[0] in migrateusers]
shadowData = [(x[0], x[1]) for x in shadowData]
shadowUsers = [x[0] for x in shadowData]
for userName in migrateusers:
if userName in shadowUsers:
userData = filter(lambda x: x[0] == userName,
shadowData)
userData = [x for x in shadowData if x[0] == userName]
hashPwd = userData[0][1]
if (sha256_crypt.identify(hashPwd) and
sha256_crypt.verify("guest", hashPwd)):
@ -559,8 +553,7 @@ class VariableClMigrateUserPwd(UserHelper, Variable):
"""
shadow_hash = get_shadow_hash()
return map(lambda x: x if shadow_hash.identify(x) or not x else \
shadow_hash.hash(x), value)
return [x if shadow_hash.identify(x) or not x else shadow_hash.hash(x) for x in value]
class VariableClAutologin(UserHelper, Variable):
@ -587,8 +580,8 @@ class VariableClAutologin(UserHelper, Variable):
if (not cmdDomainSet and
self.Get('os_install_root_type') == "livecd") or \
self.Get('os_install_linux_shortname') == "CMC":
nonRootUsers = filter(lambda x: x != "root",
self.Get('cl_migrate_user'))
nonRootUsers = [x for x in self.Get('cl_migrate_user') if x != "root"]
if nonRootUsers:
return nonRootUsers[0]
else:
@ -716,14 +709,10 @@ class VariableOsNvidiaMask(ReadonlyVariable):
category = "0300"
vendor = "10de:"
lsPciProg = getProgPath("/usr/sbin/lspci")
nvidiacards = filter(lambda x: " %s: " % category in x,
process(lsPciProg, "-d", vendor, "-n"))
cardsid = \
map(lambda x: x.groups()[0],
filter(lambda x: x,
map(lambda x: re.search(
"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x),
nvidiacards)))
nvidiacards = [x for x in process(lsPciProg, "-d", vendor, "-n")
if " %s: " % category in x]
cardsid = [x.groups()[0] for x
in [re.search("[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", y) for y in nvidiacards] if x]
if not cardsid:
return set()
return set(cardsid)
@ -838,9 +827,10 @@ class VariableOsGrub2Path(Variable):
return grubInstall
# find grub-install and check, that this is grub2-install (ver 1.99)
grubInstall = getProgPath('/usr/sbin/grub-install', prefix=chroot_path)
if grubInstall and filter(lambda x: "1.99" in x or "2." in x,
process(chroot_cmd, chroot_path,
grubInstall, '--version')):
if grubInstall and [x for x
in process(chroot_cmd, chroot_path, grubInstall, '--version')
if "1.99" in x or "2." in x]:
return grubInstall
return ""

Loading…
Cancel
Save