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

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

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

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

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

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

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

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

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

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

@ -188,8 +188,7 @@ class VariableOsNetInterfacesInfo(NetHelper, ReadonlyVariable):
else: else:
listInterfacesInfo.append((interface, listInterfacesInfo.append((interface,
ipaddr if ipaddr else _("Off"))) ipaddr if ipaddr else _("Off")))
return ", ".join(map(lambda x: "%s (%s)" % (x[0], x[1]), return ", ".join(("%s (%s)" % (x[0], x[1]) for x in listInterfacesInfo))
listInterfacesInfo))
class VariableOsInstallNetData(NetHelper, TableVariable): class VariableOsInstallNetData(NetHelper, TableVariable):
@ -310,11 +309,9 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable):
return "" return ""
pciEthernet = lspci(shortInfo=True) pciEthernet = lspci(shortInfo=True)
return map(lambda x: "{vendor} {name}".format(**x), return ["{vendor} {name}".format(**x) for x
map(lambda x: pciEthernet.get(getPci(x), in [pciEthernet.get(getPci(y), {'vendor': _("Unknown"), 'name': _("vendor")}) for y
{'vendor': _("Unknown"), in self.Get('os_install_net_interfaces')]]
'name': _("vendor")}),
self.Get('os_install_net_interfaces')))
class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable): class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable):
@ -336,7 +333,7 @@ class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable):
return "local" return "local"
def get(self): 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): class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
@ -349,8 +346,7 @@ class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
self.label = _("MAC") self.label = _("MAC")
def get(self): def get(self):
return map(lambda x: getMac(x).lower(), return [getMac(x).lower() for x in self.Get('os_install_net_interfaces')]
self.Get('os_install_net_interfaces'))
class VariableOsInstallNetStatus(NetHelper, Variable): class VariableOsInstallNetStatus(NetHelper, Variable):
@ -363,8 +359,7 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
self.label = _("IP address") self.label = _("IP address")
def get(self): def get(self):
return map(self.getDefaultValue, return [self.getDefaultValue(x) for x in self.Get('os_install_net_interfaces')]
self.Get('os_install_net_interfaces'))
def getDefaultValue(self, iface): def getDefaultValue(self, iface):
def statusValue(ipaddr, dhcp): def statusValue(ipaddr, dhcp):
@ -387,16 +382,14 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
if rootDevNfs or isDhcpIp(iface) else "off") if rootDevNfs or isDhcpIp(iface) else "off")
def set(self, value): 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') ifaces = self.Get('os_install_net_interfaces')
return map(lambda x: self.getDefaultValue(x[1]) \ return [self.getDefaultValue(x[1]) if x[0] == "auto" else x[0] for x
if x[0] == "auto" else x[0], in zip(value, ifaces)]
zip(value, ifaces))
def check(self, value): def check(self, value):
for status in value: for status in value:
if status not in map(lambda x: x[0], self.choice()) and \ if status not in (x[0] for x in self.choice()) and not checkIp(status):
not checkIp(status):
raise VariableError(_("Wrong IP address %s") % status) raise VariableError(_("Wrong IP address %s") % status)
def choice(self): def choice(self):
@ -415,10 +408,10 @@ class VariableOsInstallNetIp(NetHelper, ReadonlyVariable):
self.label = _("IP address") self.label = _("IP address")
def get(self): def get(self):
return map(lambda x: "" if x[1].lower() == "off" else return ["" if x[1].lower() == "off" else
getIp(x[0]) if x[1].lower() == "dhcp" else x[1], getIp(x[0]) if x[1].lower() == "dhcp" else x[1] for x
zip(self.Get('os_install_net_interfaces'), in zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_status'))) self.Get('os_install_net_status'))]
# def check(self,value): # def check(self,value):
# dhcps = self.Get('os_install_net_dhcp_set') # dhcps = self.Get('os_install_net_dhcp_set')
@ -439,9 +432,9 @@ class VariableOsInstallNetNetwork(NetHelper, ReadonlyVariable):
self.label = _("Network") self.label = _("Network")
def get(self): def get(self):
return map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "", return [getIpNet(x[0], x[1]) if x[0] and x[1] else "" for x
zip(self.Get('os_install_net_ip'), in zip(self.Get('os_install_net_ip'),
self.Get('os_install_net_mask'))) self.Get('os_install_net_mask'))]
class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable): class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable):
@ -457,8 +450,7 @@ class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable):
""" """
Get CIDR of ip,net (Example: 24) Get CIDR of ip,net (Example: 24)
""" """
return map(lambda x: maskToCidr(x) if x else '', return [maskToCidr(x) if x else '' for x in self.Get('os_install_net_mask')]
self.Get('os_install_net_mask'))
class VariableOsInstallNetMask(NetHelper, Variable): class VariableOsInstallNetMask(NetHelper, Variable):
@ -471,8 +463,8 @@ class VariableOsInstallNetMask(NetHelper, Variable):
self.label = _("Mask") self.label = _("Mask")
def get(self): def get(self):
return map(lambda x: cidrToMask(getMask(x)), return [cidrToMask(getMask(x)) for x
self.Get('os_install_net_interfaces')) in self.Get('os_install_net_interfaces')]
def set(self, value): def set(self, value):
""" """
@ -485,14 +477,13 @@ class VariableOsInstallNetMask(NetHelper, Variable):
else: else:
return x return x
res = map(convertCidrToMask, value) res = [convertCidrToMask(x) for x in value]
return res return res
def check(self, value): def check(self, value):
dhcps = self.Get('os_install_net_status') dhcps = self.Get('os_install_net_status')
wrongMask = filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \ wrongMask = [x for x in zip(value, dhcps)
not checkMask(x[0]), if (x[0] or not x[1] in ("off", "dhcp")) and not checkMask(x[0])]
zip(value, dhcps))
if wrongMask: if wrongMask:
raise VariableError(_("Wrong mask %s") % wrongMask[0][0]) raise VariableError(_("Wrong mask %s") % wrongMask[0][0])
@ -514,8 +505,8 @@ class VariableOsInstallNetDhcpSet(NetHelper, Variable):
self.label = _("DHCP") self.label = _("DHCP")
def get(self): def get(self):
return map(lambda x: "on" if x == "dhcp" else "off", return ["on" if x == "dhcp" else "off" for x
self.Get('os_install_net_status')) in self.Get('os_install_net_status')]
class VariableOsInstallNetRouteData(NetHelper, TableVariable): class VariableOsInstallNetRouteData(NetHelper, TableVariable):
@ -544,19 +535,18 @@ class VariableOsInstallNetRouteData(NetHelper, TableVariable):
interfaces = self.Get('os_install_net_interfaces') interfaces = self.Get('os_install_net_interfaces')
interfaces_status = self.Get('os_install_net_status') interfaces_status = self.Get('os_install_net_status')
interfaces_network = self.Get('os_install_net_network') interfaces_network = self.Get('os_install_net_network')
staticInterface = \ staticInterface = [itemgetter(0, 2)(x) for x
map(itemgetter(0, 2), in zip(interfaces, interfaces_status, interfaces_network)
filter(lambda x: not x[1] in ("off", "dhcp"), if not x[1] in ("off", "dhcp")]
zip(interfaces, interfaces_status, interfaces_network)))
route_data = [] route_data = []
if staticInterface: if staticInterface:
staticInterface, skipNet = zip(*staticInterface) staticInterface, skipNet = zip(*staticInterface)
return map(lambda x: [x[0], return [[x[0],
x[1].get('via', ''), x[1].get('via', ''),
x[1].get('dev', ''), x[1].get('dev', ''),
x[1].get('src', '')], x[1].get('src', '')] for x
ifilter(lambda x: not x[0] in skipNet, in ip.getRouteTable(staticInterface)
ip.getRouteTable(staticInterface))) or [[]] if not x[0] in skipNet] or [[]]
return [[]] return [[]]
def getHumanReadableAuto(self): def getHumanReadableAuto(self):
@ -598,12 +588,11 @@ class VariableOsInstallNetRouteNetwork(NetHelper, FieldValue, Variable):
########################## ##########################
# detect duplicate network # detect duplicate network
########################## ##########################
for wrongnet in ifilterfalse(ip.checkNet, for wrongnet in filterfalse(ip.checkNet,
ifilter("default".__ne__, filter("default".__ne__,
value)): value)):
raise VariableError(_("Wrong network %s") % wrongnet) raise VariableError(_("Wrong network %s") % wrongnet)
dupNetwork = list(set(filter(lambda x: value.count(x) > 1, dupNetwork = list(set([x for x in value if value.count(x) > 1]))
value)))
if dupNetwork: if dupNetwork:
raise VariableError( raise VariableError(
_("Network '%s' is used more than once") % dupNetwork[0]) _("Network '%s' is used more than once") % dupNetwork[0])
@ -626,19 +615,14 @@ class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable):
NET, GW = 0, 1 NET, GW = 0, 1
netsGw = zip(self.Get('os_install_net_route_network'), netsGw = zip(self.Get('os_install_net_route_network'),
value) value)
nets = filter(lambda x: x and x != "default", nets = [x for x in chain(self.Get('os_install_net_route_network'),
chain(self.Get('os_install_net_route_network'), self.Get('os_install_net_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) raise VariableError(_("Wrong gateway IP %s") % wrongip)
wrongGws = [x[GW] for x in [y for y in netsGw if y[GW]]
wrongGws = map(lambda x: x[GW], if not ip.isIpInNet(x[GW], *(set(nets) - set(x[NET])))]
filter(lambda x: not ip.isIpInNet(x[GW],
*(set(nets) - set(
x[NET]))),
filter(lambda x: x[GW],
netsGw)))
if wrongGws: if wrongGws:
raise VariableError(_("Gateways %s are unreachable") % raise VariableError(_("Gateways %s are unreachable") %
(",".join(wrongGws))) (",".join(wrongGws)))
@ -674,12 +658,11 @@ class VariableOsInstallNetRouteSrc(NetHelper, FieldValue, Variable):
return [""] + self.Get('os_install_net_ip') return [""] + self.Get('os_install_net_ip')
def check(self, value): def check(self, value):
for wrongip in ifilterfalse(ip.checkIp, for wrongip in filterfalse(ip.checkIp,
ifilter(None, value)): filter(None, value)):
raise VariableError(_("Wrong source IP %s") % wrongip) raise VariableError(_("Wrong source IP %s") % wrongip)
ipAddrs = self.Get('os_install_net_ip') ipAddrs = self.Get('os_install_net_ip')
wrongIps = filter(lambda x: x and not x in ipAddrs, wrongIps = [x for x in value if x and not x in ipAddrs]
value)
if wrongIps: if wrongIps:
raise VariableError( raise VariableError(
_("Wrong IP address %s in the specified source IP") % _("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_dev'),
self.Get('os_install_net_route_src')) self.Get('os_install_net_route_src'))
DEV, IP, CIDR, NET = 0, 1, 2, 1 DEV, IP, CIDR, NET = 0, 1, 2, 1
return map(lambda x: performFunc(x[DEV], x[NET], routeMatrix), return [performFunc(x[DEV], x[NET], routeMatrix) for x
# union ip and mask to ip/net # ip and mask to ip/net
map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \ in [(y[DEV], ip.getIpNet(y[IP], cidr=y[CIDR]))
if x[IP] and x[CIDR] else (x[DEV], ""), if y[IP] and y[CIDR] else (y[DEV], "") for y
# filter(lambda x:x[IP] and x[CIDR], in zip(self.Get('os_install_net_interfaces'),
zip(self.Get('os_install_net_interfaces'),
self.Get('os_install_net_ip'), self.Get('os_install_net_ip'),
self.Get('os_install_net_cidr')))) self.Get('os_install_net_cidr'))]]
def get(self): def get(self):
"""Route info for conf.d/net""" """Route info for conf.d/net"""
@ -719,10 +701,11 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
NET, GW, DEV, SRC = 0, 1, 2, 3 NET, GW, DEV, SRC = 0, 1, 2, 3
# filter by interface and discard direct routes # filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net # 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 route_list = [x for x in routeMatrix
interface == defaultDev) \ if (interface == x[DEV] or
and net != x[NET], routeMatrix) defaultDev and
interface == defaultDev) and
net != x[NET]]
nets = [] nets = []
route_list_uniqnet = [] route_list_uniqnet = []
for net, gw, dev, src in route_list: for net, gw, dev, src in route_list:
@ -730,10 +713,9 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable):
route_list_uniqnet.append([net, gw, dev, src]) route_list_uniqnet.append([net, gw, dev, src])
nets.append(net) nets.append(net)
route_strs = map(lambda x: "{net}{gateway}{src}".format( route_strs = ("{net}{gateway}{src}".format(net=x[NET], gateway=" via %s" % x[GW]
net=x[NET], if x[GW] else "", src=" src %s" % x[SRC] if x[SRC] else "") for x
gateway=" via %s" % x[GW] if x[GW] else "", in route_list_uniqnet)
src=" src %s" % x[SRC] if x[SRC] else ""), route_list_uniqnet)
# build string for route from net,gateway,dev and src # build string for route from net,gateway,dev and src
return "\n".join(route_strs) return "\n".join(route_strs)
@ -757,29 +739,42 @@ class VariableOsInstallNetNmroute(VariableOsInstallNetRoute):
def getRouteForInterfaceNM(interface, net, routeMatrix): def getRouteForInterfaceNM(interface, net, routeMatrix):
NET, GW, DEV, SRC = 0, 1, 2, 3 NET, GW, DEV, SRC = 0, 1, 2, 3
defaultGw = map(lambda x: "%s;" % x[GW], defaultGw = ["%s;" % x[GW] for x in routeMatrix
filter(lambda x: interface == x[DEV] and \ if interface == x[DEV] and x[NET] == "default"]
x[NET] == "default", # return "{0}\n".format(defaultGw[0] if defaultGw else "") + \
routeMatrix)) # "\n".join(
return "{0}\n".format(defaultGw[0] if defaultGw else "") + \ # # build string for route from net,gateway,dev and src
"\n".join( # map(lambda
# build string for route from net,gateway,dev and src # x: "routes{num}={ip};{cidr};{gateway};0;".format(
map(lambda # num=x[0] + 1,
x: "routes{num}={ip};{cidr};{gateway};0;".format( # 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, num=x[0] + 1,
ip=x[1][NET].partition('/')[0], ip=x[1][NET].partition('/')[0],
cidr=x[1][NET].partition('/')[2], cidr=x[1][NET].partition('/')[2],
gateway=x[1][GW] if x[1][GW] else "0.0.0.0"), gateway=x[1][GW] if x[1][GW] else "0.0.0.0") for x
# filter by interface and discard direct routes # filter by interface and discard direct routes
# example: for 192.168.1.5/24 discard 192.168.1.0/24 net # example: for 192.168.1.5/24 discard 192.168.1.0/24 net
enumerate( in enumerate((x for x in routeMatrix
filter(lambda x: (interface == x[ if (interface == x[DEV] or
DEV] or defaultDev and defaultDev and
interface == defaultDev) and net != interface == defaultDev) and
x[ net !=x[NET] and
NET] and \ x[NET] != "default"))))
x[NET] != "default",
routeMatrix))))
return self.performRouteData(getRouteForInterfaceNM) return self.performRouteData(getRouteForInterfaceNM)
@ -799,10 +794,8 @@ class VariableOsInstallNetConfAvailable(NetHelper, Variable):
with image as distr: with image as distr:
try: try:
distrPath = image.getDirectory() distrPath = image.getDirectory()
return map(itemgetter(0, 2), return [itemgetter(0, 2)(x) for x in mapNetConf
filter(lambda x: not x[1] or isPkgInstalled(x[1], if not x[1] or isPkgInstalled(x[1], prefix=distrPath)]
prefix=distrPath),
mapNetConf))
except DistributiveError as e: except DistributiveError as e:
pass pass
return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1)) return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1))
@ -822,10 +815,9 @@ class VariableOsInstallNetConf(NetHelper, Variable):
def get(self): def get(self):
"""Net setup (networkmanager or openrc)""" """Net setup (networkmanager or openrc)"""
if filter(lambda x: x.lower() == "networkmanager", if [x for x in listDirectory('/etc/runlevels/boot') +
listDirectory('/etc/runlevels/boot') + listDirectory('/etc/runlevels/default')
listDirectory('/etc/runlevels/default')) \ if x.lower() == "networkmanager"] or self.Get('os_root_type') == "livecd":
or self.Get('os_root_type') == "livecd":
nm = "networkmanager" nm = "networkmanager"
else: else:
nm = "" nm = ""
@ -867,10 +859,9 @@ class VariableOsInstallNetDnsSearch(NetHelper, Variable):
def get(self): def get(self):
"""Get current name servers""" """Get current name servers"""
dnsSearch = " ".join( dnsSearch = " ".join((x.strip().partition("search")[2].strip() for x
map(lambda x: x.strip().partition("search")[2].strip(), in readLinesFile('/etc/resolv.conf')
filter(lambda x: x.lstrip().startswith("search"), if x.lstrip().startswith("search")))
readLinesFile('/etc/resolv.conf'))))
return "" if self.isDNSByDHCP() else dnsSearch return "" if self.isDNSByDHCP() else dnsSearch
def humanReadable(self): def humanReadable(self):
@ -894,17 +885,16 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
return " ".join(re.split('[; ,]', value)) return " ".join(re.split('[; ,]', value))
def get(self): def get(self):
dnsIps = filter(ip.checkIp, dnsIps = (x for x
map(lambda x: x.strip().partition("nameserver")[ in (y.strip().partition("nameserver")[2].strip() for y
2].strip(), in readLinesFile('/etc/resolv.conf')
filter( if y.lstrip().startswith("nameserver"))
lambda x: x.lstrip().startswith("nameserver"), if ip.checkIp(x))
readLinesFile('/etc/resolv.conf'))))
return "" if self.isDNSByDHCP() else " ".join(dnsIps) return "" if self.isDNSByDHCP() else " ".join(dnsIps)
def check(self, value): def check(self, value):
reIp = re.compile(ip.IP_ADDR) 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")) raise VariableError(_("Wrong IP address for DNS"))
def humanReadable(self): def humanReadable(self):
@ -938,11 +928,11 @@ class VariableOsInstallPxeIp(Variable):
def get(self): def get(self):
ips = self.Get('os_net_ip').split(',') ips = self.Get('os_net_ip').split(',')
for ipaddr in ifilter(None, ips): for ipaddr in filter(None, ips):
return ipaddr return ipaddr
else: else:
return "" return ""
def choice(self): def choice(self):
ips = self.Get('os_net_ip').split(',') 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): def get(self):
"""Filesystem format support by calcualte-install""" """Filesystem format support by calcualte-install"""
return FileSystemManager.supportFS.keys() return list(FileSystemManager.supportFS.keys())
class VariableOsFormatUse(ReadonlyVariable): class VariableOsFormatUse(ReadonlyVariable):
@ -141,7 +141,7 @@ class VariableOsFormatUse(ReadonlyVariable):
return "no" return "no"
def get(self): 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): class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable):
@ -194,10 +194,9 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable):
содержит пустую строку содержит пустую строку
""" """
def get(self): def get(self):
rootPasswd = map(lambda x: x[1], rootPasswd = [x[1] for x
filter("root".__eq__, in [y.split(':')[0:2] for y in readLinesFile('/etc/shadow')]
map(lambda x: x.split(':')[0:2], if "root".__eq__(x)]
readLinesFile('/etc/shadow'))))
if rootPasswd: if rootPasswd:
rootPasswd = rootPasswd[0] rootPasswd = rootPasswd[0]
else: else:
@ -419,7 +418,7 @@ class VariableClMigrateAdmin(UserHelper, Variable):
for x in self.Get('cl_migrate_user')] for x in self.Get('cl_migrate_user')]
def set(self, value): 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): class VariableOsAvailableGroups(ReadonlyVariable):
@ -476,8 +475,7 @@ class VariableClMigrateUserGroups(UserHelper, Variable):
yield value yield value
def set(self, value): def set(self, value):
value = map(lambda x: sorted(list(set(self.process_groups(x)))), value = [sorted(list(set(self.process_groups(x)))) for x in value]
value)
return value return value
def getPrimaryGroup(self, username): def getPrimaryGroup(self, username):
@ -491,11 +489,9 @@ class VariableClMigrateUserGroups(UserHelper, Variable):
User groups User groups
""" """
passwdList = getPasswdUsers() passwdList = getPasswdUsers()
return map(lambda x: sorted(self.getPrimaryGroup(x) + return [sorted(self.getPrimaryGroup(x) + (getUserGroups(x)
(getUserGroups(x) if x in passwdList else self.getDefaultGroups())) for x
if x in passwdList else in self.Get('cl_migrate_user')]
self.getDefaultGroups())),
self.Get('cl_migrate_user'))
def choice(self): def choice(self):
""" """
@ -525,15 +521,13 @@ class VariableClMigrateUserPwd(UserHelper, Variable):
if migrateusers: if migrateusers:
lenData = 9 lenData = 9
with open(fileName) as f: with open(fileName) as f:
shadowData = filter(lambda x: len(x) == lenData, shadowData = [x for x in [y.rstrip().split(":") for y in f] if len(x) == lenData]
map(lambda x: x.rstrip().split(":"), f)) shadowData = [x for x in shadowData if x[0] in migrateusers]
shadowData = filter(lambda x: x[0] in migrateusers, shadowData) shadowData = [(x[0], x[1]) for x in shadowData]
shadowData = map(lambda x: (x[0], x[1]), shadowData) shadowUsers = [x[0] for x in shadowData]
shadowUsers = map(lambda x: x[0], shadowData)
for userName in migrateusers: for userName in migrateusers:
if userName in shadowUsers: if userName in shadowUsers:
userData = filter(lambda x: x[0] == userName, userData = [x for x in shadowData if x[0] == userName]
shadowData)
hashPwd = userData[0][1] hashPwd = userData[0][1]
if (sha256_crypt.identify(hashPwd) and if (sha256_crypt.identify(hashPwd) and
sha256_crypt.verify("guest", hashPwd)): sha256_crypt.verify("guest", hashPwd)):
@ -559,8 +553,7 @@ class VariableClMigrateUserPwd(UserHelper, Variable):
""" """
shadow_hash = get_shadow_hash() shadow_hash = get_shadow_hash()
return map(lambda x: x if shadow_hash.identify(x) or not x else \ return [x if shadow_hash.identify(x) or not x else shadow_hash.hash(x) for x in value]
shadow_hash.hash(x), value)
class VariableClAutologin(UserHelper, Variable): class VariableClAutologin(UserHelper, Variable):
@ -587,8 +580,8 @@ class VariableClAutologin(UserHelper, Variable):
if (not cmdDomainSet and if (not cmdDomainSet and
self.Get('os_install_root_type') == "livecd") or \ self.Get('os_install_root_type') == "livecd") or \
self.Get('os_install_linux_shortname') == "CMC": 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: if nonRootUsers:
return nonRootUsers[0] return nonRootUsers[0]
else: else:
@ -716,14 +709,10 @@ class VariableOsNvidiaMask(ReadonlyVariable):
category = "0300" category = "0300"
vendor = "10de:" vendor = "10de:"
lsPciProg = getProgPath("/usr/sbin/lspci") lsPciProg = getProgPath("/usr/sbin/lspci")
nvidiacards = filter(lambda x: " %s: " % category in x, nvidiacards = [x for x in process(lsPciProg, "-d", vendor, "-n")
process(lsPciProg, "-d", vendor, "-n")) if " %s: " % category in x]
cardsid = \ cardsid = [x.groups()[0] for x
map(lambda x: x.groups()[0], in [re.search("[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", y) for y in nvidiacards] if x]
filter(lambda x: x,
map(lambda x: re.search(
"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x),
nvidiacards)))
if not cardsid: if not cardsid:
return set() return set()
return set(cardsid) return set(cardsid)
@ -838,9 +827,10 @@ class VariableOsGrub2Path(Variable):
return grubInstall return grubInstall
# find grub-install and check, that this is grub2-install (ver 1.99) # find grub-install and check, that this is grub2-install (ver 1.99)
grubInstall = getProgPath('/usr/sbin/grub-install', prefix=chroot_path) 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, if grubInstall and [x for x
grubInstall, '--version')): in process(chroot_cmd, chroot_path, grubInstall, '--version')
if "1.99" in x or "2." in x]:
return grubInstall return grubInstall
return "" return ""

Loading…
Cancel
Save