Py3 changes

py3_forced
idziubenko 3 years ago
parent 409534d108
commit b1a5dc6e64

6
.gitignore vendored

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

@ -374,9 +374,9 @@ 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, list(map(joinFrom,
ifilterfalse(byfile or operator.not_, 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)
@ -386,8 +386,8 @@ 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 = list(filter(byfile,
listDirectory(fromdir)) listDirectory(fromdir)))
if len(percFiles) > 1: if len(percFiles) > 1:
maxPercOnFile = 100 / len(percFiles) maxPercOnFile = 100 / len(percFiles)
recountPerc = \ recountPerc = \
@ -441,9 +441,9 @@ 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 = list(filter(lambda x: x,
map(self.reLive.search, map(self.reLive.search,
listDirectory(directory))) listDirectory(directory))))
if squashfiles: if squashfiles:
return max(squashfiles, key=self._getSquashNum).group() return max(squashfiles, key=self._getSquashNum).group()
return None return None
@ -822,27 +822,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 list(map(lambda x: x.systemId, 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 list(map(lambda x: x.partitionTable, 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 list(map(lambda x: x.isFormat, 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 list(map(lambda x: x.fileSystem, 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 list(map(lambda x: x.dev, 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 list(map(lambda x: x.mountPoint, self.listPartitions))
class FormatProcess(process): class FormatProcess(process):
@ -1084,8 +1084,8 @@ 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 = list(filter(lambda x: x[2] == "bind",
self.getMultipartData()) 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 \
@ -1166,10 +1166,10 @@ 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 = list(map(lambda x: (x[FS], x[DEV], x[NEWID], x[MP]),
filter( filter(
lambda x: x[NEEDFORMAT] and x[FS] != "bind", lambda x: x[NEEDFORMAT] and x[FS] != "bind",
dataPartitions)) 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 +1194,9 @@ 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 = list(map(lambda x: (x[NEWID], x[DEV], x[PARTTABLE]),
filter(lambda x: x[NEWID], filter(lambda x: x[NEWID],
dataPartitions)) 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
@ -1495,7 +1495,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 += list(map(lambda x: "--exclude=./%s" % x, exclude_list))
params += ["."] params += ["."]
#debug_file = "/var/calculate/tmp/rootfs.tar.xz" #debug_file = "/var/calculate/tmp/rootfs.tar.xz"
@ -1880,7 +1880,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 list(filter(clear_match.match, listDirectory(dn))):
full_path = path.join(dn, fn) full_path = path.join(dn, fn)
try: try:
if path.isdir(full_path): if path.isdir(full_path):

@ -91,8 +91,8 @@ 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 list(map(lambda x: "%s-32" % x,
resolutions) resolutions))
else: else:
return resolutions return resolutions
@ -100,7 +100,7 @@ class ResolutionVariable(VideoVariable):
""" """
Check resolution format 1234x567 Check resolution format 1234x567
""" """
if not re.match('^\d+x\d+(-\d+(@\d+)?)?$', value): if not re.match(r'^\d+x\d+(-\d+(@\d+)?)?$', value):
raise VariableError( raise VariableError(
_("Wrong resolution {resolution} {example}").format( _("Wrong resolution {resolution} {example}").format(
resolution=value, resolution=value,
@ -183,7 +183,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 list(map(lambda x: self.driver_names.get(x, x), self.Get()))
class VariableOsX11KmsVideoDrv(ReadonlyVariable): class VariableOsX11KmsVideoDrv(ReadonlyVariable):
@ -220,8 +220,8 @@ class VariableOsInstallX11VideoDrv(VideoVariable):
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 list(map(lambda x: (x, self.driver_names.get(x, x)),
(x for x in self.driver_names.keys() if x in values)) (x for x in self.driver_names.keys() if x 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':

@ -88,10 +88,10 @@ 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 list(map(lambda x: x[0::2],
filter(lambda x: not x[1] or isPkgInstalled(x[1], filter(lambda x: not x[1] or isPkgInstalled(x[1],
prefix=distrPath), prefix=distrPath),
mapAudioConf)) mapAudioConf)))
except DistributiveError as e: except DistributiveError as e:
pass pass
return sorted(map(lambda x: x[0::2], mapAudioConf[-1:]), return sorted(map(lambda x: x[0::2], mapAudioConf[-1:]),
@ -134,7 +134,7 @@ class VariableOsAudioData(ReadonlyTableVariable):
def get(self, hr=HumanReadable.No): def get(self, hr=HumanReadable.No):
# /proc/asound/card*/pcm*p/info # /proc/asound/card*/pcm*p/info
data = readFile('/proc/asound/cards') data = readFile('/proc/asound/cards')
cards = re.findall('^\s*(\d+).*\s-\s(.+)\n\s+\S.* at .*$', cards = re.findall(r'^\s*(\d+).*\s-\s(.+)\n\s+\S.* at .*$',
data, re.M) data, re.M)
if cards: if cards:
return list(self.generate_cards(cards)) return list(self.generate_cards(cards))
@ -211,12 +211,12 @@ class VariableOsAudioHw(Variable):
def get_deprecated(self): def get_deprecated(self):
asound_data = readFile('/etc/asound.conf') asound_data = readFile('/etc/asound.conf')
default_card_re = re.compile('defaults.ctl.card\s+(\d+)') default_card_re = re.compile(r'defaults.ctl.card\s+(\d+)')
entry = default_card_re.search(asound_data) entry = default_card_re.search(asound_data)
if entry and entry.groups()[0] in self.Get('os_audio_id'): if entry and entry.groups()[0] in self.Get('os_audio_id'):
return "%s,0" % entry.groups()[0] return "%s,0" % entry.groups()[0]
default_card_re = re.compile( default_card_re = re.compile(
'pcm.!default {[^}]+card\s+(\d+)[^}]+device\s+(\d+)[^}]+}') r'pcm.!default {[^}]+card\s+(\d+)[^}]+device\s+(\d+)[^}]+}')
entry = default_card_re.search(asound_data) entry = default_card_re.search(asound_data)
if entry: if entry:
entry = "%s,%s" % entry.groups() entry = "%s,%s" % entry.groups()

@ -43,16 +43,16 @@ class SizeHelper(VariableInterface):
def set(self, value): def set(self, value):
# convert table from value to MB # convert table from value to MB
sizeMap = {'kB': Sizes.kB, sizeMap = {r'kB': Sizes.kB,
'K': Sizes.K, r'K': Sizes.K,
'M': Sizes.M, r'M': Sizes.M,
'Mb': Sizes.Mb, r'Mb': Sizes.Mb,
'G': Sizes.G, r'G': Sizes.G,
'Gb': Sizes.Gb, r'Gb': Sizes.Gb,
'T': Sizes.T, r'T': Sizes.T,
'Tb': Sizes.Tb} r'Tb': Sizes.Tb}
value = value.strip() value = value.strip()
reSizeValue = re.compile('^(\d+)\s*(%s)?' % "|".join(sizeMap.keys())) reSizeValue = re.compile(r'^(\d+)\s*(%s)?' % r"|".join(sizeMap.keys()))
res = reSizeValue.search(value) res = reSizeValue.search(value)
if not res: if not res:
return "0" return "0"
@ -98,9 +98,9 @@ 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 = list(filter(lambda x: x,
map(reMemTotal.search, map(reMemTotal.search,
readLinesFile('/proc/meminfo'))) 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)
@ -149,7 +149,7 @@ class VariableClAutopartitionDeviceData(ReadonlyTableVariable):
'cl_autopartition_device_size', 'cl_autopartition_device_size',
'cl_autopartition_device_name'] 'cl_autopartition_device_name']
re_raid = re.compile("raid[1-9]") re_raid = re.compile(r"raid[1-9]")
def get(self, hr=HumanReadable.No): def get(self, hr=HumanReadable.No):
def generator(): def generator():
@ -212,7 +212,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 = list(map(lambda x: x[0], 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 +255,8 @@ 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 = list(filter(None, self.Select('os_disk_raid',
where='os_disk_dev', _in=disks)) where='os_disk_dev', _in=disks)))
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',
@ -288,7 +288,7 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable):
""" """
Проверить схемы RAID, чтобы исключить базирование их на lvm Проверить схемы RAID, чтобы исключить базирование их на lvm
""" """
typecheck = re.compile("lvm.*raid") typecheck = re.compile(r"lvm.*raid")
for dev, fulltype in self.ZipVars("os_device_dev", for dev, fulltype in self.ZipVars("os_device_dev",
"os_device_fulltype"): "os_device_fulltype"):
if dev in valuelist: if dev in valuelist:
@ -689,17 +689,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 +784,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 list(map(str, super(VariableClAutopartitionDiskSize, self).get()))
def humanReadable(self): def humanReadable(self):
return map(humanreadableSize, self.Get()) return list(map(humanreadableSize, self.Get()))
class VariableClAutopartitionDiskDataFull(ReadonlyTableVariable): class VariableClAutopartitionDiskDataFull(ReadonlyTableVariable):
@ -864,10 +876,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 list(map(str, var_factory.disk_size))
def humanReadable(self): def humanReadable(self):
return map(humanreadableSize, self.Get()) return list(map(humanreadableSize, self.Get()))
class VariableClAutopartitionRaid(ReadonlyVariable): class VariableClAutopartitionRaid(ReadonlyVariable):

@ -45,13 +45,13 @@ setLocalTranslate('cl_install3', sys.modules[__name__])
class DeviceHelper(VariableInterface): class DeviceHelper(VariableInterface):
rePassDevice = re.compile("^/block/(?!%s)" % "|".join(['sr', 'fd', rePassDevice = re.compile(r"^/block/(?!%s)" % r"|".join([r'sr', r'fd',
'ram', 'loop'])) r'ram', r'loop']))
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 list(filter(self.rePassDevice.search,
device.udev.get_block_devices()) device.udev.get_block_devices()))
def separateDevice(self, dev): def separateDevice(self, dev):
""" """
@ -59,8 +59,8 @@ 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 list(map(lambda x: int(x) if x.isdigit() else x,
re.findall('\d+|\D+', dev)) re.findall(r'\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]"""
@ -164,7 +164,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
Disk devices Disk devices
""" """
type = "list" type = "list"
re_disk_raid = re.compile("^disk-.*-raid\d+$", re.I) re_disk_raid = re.compile(r"^disk-.*-raid\d+$", re.I)
def init(self): def init(self):
pass pass
@ -228,8 +228,8 @@ class VariableOsDeviceType(ReadonlyVariable):
device.devfs.listdir(diskIdPath, fullpath=False))) device.devfs.listdir(diskIdPath, fullpath=False)))
else: else:
self.usbdevices = [] self.usbdevices = []
return map(self.getType, return list(map(self.getType,
self.Get('os_device_dev')) self.Get('os_device_dev')))
class VariableOsDeviceParent(ReadonlyVariable): class VariableOsDeviceParent(ReadonlyVariable):
@ -313,8 +313,8 @@ class VariableOsDeviceMap(ReadonlyVariable):
type = "list" type = "list"
def get(self): def get(self):
return map(lambda x: str(x[0]), return list(map(lambda x: str(x[0]),
enumerate(self.Get('os_device_dev'))) enumerate(self.Get('os_device_dev'))))
class VariableOsDeviceArraySet(ReadonlyVariable): class VariableOsDeviceArraySet(ReadonlyVariable):
@ -334,9 +334,9 @@ class VariableOsDeviceArraySet(ReadonlyVariable):
else: else:
return "off" return "off"
return map(lambda x: isArray(*x), return list(map(lambda x: isArray(*x),
zip(self.Get('os_device_dev'), zip(self.Get('os_device_dev'),
self.Get('os_device_name'))) self.Get('os_device_name'))))
class VariableOsDeviceSsdSet(ReadonlyVariable): class VariableOsDeviceSsdSet(ReadonlyVariable):
@ -361,9 +361,9 @@ class VariableOsDeviceSsdSet(ReadonlyVariable):
else: else:
return "off" return "off"
return map(lambda x: isSsd(*x), return list(map(lambda x: isSsd(*x),
zip(self.Get('os_device_dev'), zip(self.Get('os_device_dev'),
self.Get('os_device_name'))) self.Get('os_device_name'))))
class VariableOsDeviceSyspath(ReadonlyVariable): class VariableOsDeviceSyspath(ReadonlyVariable):
@ -403,10 +403,10 @@ class VariableOsDeviceVirtualSet(ReadonlyVariable):
else: else:
return "off" return "off"
return map(lambda x: isVirtual(*x), return list(map(lambda x: isVirtual(*x),
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 +444,8 @@ class VariableOsDeviceTable(ReadonlyVariable):
else: else:
return getTable(dev) return getTable(dev)
return map(getByAutopartition, return list(map(getByAutopartition,
self.Get('os_device_dev')) self.Get('os_device_dev')))
class VariableOsDeviceName(ReadonlyVariable): class VariableOsDeviceName(ReadonlyVariable):
@ -475,8 +475,8 @@ class VariableOsDeviceName(ReadonlyVariable):
return "" return ""
def get(self): def get(self):
return map(self.getName, return list(map(self.getName,
self.Get('os_device_dev')) self.Get('os_device_dev')))
class VariableOsDeviceSize(ReadonlyVariable): class VariableOsDeviceSize(ReadonlyVariable):
@ -487,12 +487,12 @@ 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 list(map(lambda x: getPartitionSize(name=x, inBytes=True),
self.Get('os_device_dev')) self.Get('os_device_dev')))
def humanReadable(self): def humanReadable(self):
return map(humanreadableSize, return list(map(humanreadableSize,
self.Get()) self.Get()))
############################################# #############################################
@ -526,7 +526,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable):
def get(self): def get(self):
# получить блочные утсройства, в списке устройства с таблицей раздела # получить блочные утсройства, в списке устройства с таблицей раздела
# разделены '/' # разделены '/'
re_parent = re.compile("^/block/[^/]+") re_parent = re.compile(r"^/block/[^/]+")
disks = self.getBlockDevices() disks = self.getBlockDevices()
parents = {re_parent.search(x).group() parents = {re_parent.search(x).group()
for x in disks if x.count("/") > 2} for x in disks if x.count("/") > 2}
@ -536,8 +536,8 @@ 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 list(map(self.getPerfectName,
self.Get()) self.Get()))
class VariableOsDiskMount(DeviceHelper, ReadonlyVariable): class VariableOsDiskMount(DeviceHelper, ReadonlyVariable):
@ -550,8 +550,8 @@ 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 list(map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "",
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
class VariableOsDiskContent(ReadonlyVariable): class VariableOsDiskContent(ReadonlyVariable):
@ -564,8 +564,8 @@ class VariableOsDiskContent(ReadonlyVariable):
""" """
TODO: need to write TODO: need to write
""" """
return map(lambda x: "", return list(map(lambda x: "",
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
class VariableOsDiskFormat(ReadonlyVariable): class VariableOsDiskFormat(ReadonlyVariable):
""" """
@ -593,8 +593,8 @@ class VariableOsDiskFormat(ReadonlyVariable):
pass pass
return fs return fs
return map(getFormat, return list(map(getFormat,
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
class VariableOsDiskType(ReadonlyVariable): class VariableOsDiskType(ReadonlyVariable):
@ -602,8 +602,8 @@ class VariableOsDiskType(ReadonlyVariable):
List type (lvm,raid,partition,disk) List type (lvm,raid,partition,disk)
""" """
type = "list" type = "list"
re_raid = re.compile("-raid\d+$") re_raid = re.compile(r"-raid\d+$")
re_raid_partition = re.compile("-raid\d+-partition$") re_raid_partition = re.compile(r"-raid\d+-partition$")
def get(self): def get(self):
"""Get partition scheme""" """Get partition scheme"""
@ -642,9 +642,9 @@ 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], return list(map(lambda x: x[1],
map(forMember, map(forMember,
types)) types)))
class VariableOsDiskRaid(ReadonlyVariable): class VariableOsDiskRaid(ReadonlyVariable):
@ -672,8 +672,8 @@ 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 list(map(self.getLvmName,
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
class VariableOsDiskUuid(DeviceHelper, ReadonlyVariable): class VariableOsDiskUuid(DeviceHelper, ReadonlyVariable):
@ -723,10 +723,10 @@ 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 list(map(lambda x: mapTypeUUID.get(x, x),
map(lambda x: x.rpartition("x")[2], map(lambda x: x.rpartition("x")[2],
self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE', self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE',
''))) ''))))
class VariableOsDiskGrub(ReadonlyVariable): class VariableOsDiskGrub(ReadonlyVariable):
@ -753,10 +753,10 @@ class VariableOsDiskGrub(ReadonlyVariable):
else: else:
return "" return ""
return map(getGrubMap, return list(map(getGrubMap,
zip(self.Get('os_disk_dev'), 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):
@ -786,12 +786,12 @@ 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 list(map(lambda x: getPartitionSize(name=x, inBytes=True),
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
def humanReadable(self): def humanReadable(self):
return map(humanreadableSize, return list(map(humanreadableSize,
self.Get()) self.Get()))
class VariableOsDiskName(DeviceHelper, ReadonlyVariable): class VariableOsDiskName(DeviceHelper, ReadonlyVariable):
@ -817,8 +817,8 @@ 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 list(map(getFormat,
self.Get('os_disk_dev')) self.Get('os_disk_dev')))
################################################ ################################################
@ -1042,11 +1042,11 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable):
return path.normpath(val) return path.normpath(val)
return val return val
return map(normpath, value) return list(map(normpath, value))
def choice(self): def choice(self):
return map(lambda x: (x, self.getPerfectName(x) or x), return list(map(lambda x: (x, self.getPerfectName(x) or x),
self.fixOsDiskDev(self.availDevs(choice=True))) + [("", "")] self.fixOsDiskDev(self.availDevs(choice=True)))) + [("", "")]
def fixOsDiskDev(self, sourcelist=None): def fixOsDiskDev(self, sourcelist=None):
""" """
@ -1141,12 +1141,12 @@ class VariableOsLocationDest(LocationHelper, Variable):
return "" return ""
return mount return mount
return map(installMountPoint, return list(map(installMountPoint,
filter(lambda x: x[0] in source, filter(lambda x: x[0] in source,
zip(self.Get('os_disk_dev'), list(zip(self.Get('os_disk_dev'),
self.Get('os_disk_mount')) + \ self.Get('os_disk_mount'))) + \
zip(self.Get('os_bind_path'), list(zip(self.Get('os_bind_path'),
self.Get('os_bind_mountpoint')))) 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 +1157,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 list(map(lambda x: x or "/", value))
def choice(self): def choice(self):
if self.Get('cl_install_type') == 'flash': if self.Get('cl_install_type') == 'flash':
@ -1179,7 +1179,7 @@ class VariableOsLocationDest(LocationHelper, Variable):
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 filter(lambda x: x[0] == '/' and x[1].isdigit() and \
int(x[1]) < minroot, int(x[1]) < minroot,
izip(value, zip(value,
self.Get("os_location_size"))): 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")
@ -1189,19 +1189,19 @@ class VariableOsLocationDest(LocationHelper, Variable):
################################ ################################
if not source: if not source:
return return
if not filter(lambda x: x == "/", value): if not list(filter(lambda x: x == "/", value)):
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 = list(filter(lambda x: x[0].startswith('/dev/') and x[1],
zip(source, value)) zip(source, value)))
disksDevs = map(lambda x: x[0], disks) disksDevs = list(map(lambda x: x[0], disks))
binds = filter(lambda x: not x[0].startswith('/dev/') and x[1], binds = list(filter(lambda x: not x[0].startswith('/dev/') and x[1],
zip(source, value)) zip(source, value)))
########################## ##########################
# detect efi specifing # detect efi specifing
########################## ##########################
reEfi = re.compile("/u?efi", re.I) reEfi = re.compile(r"/u?efi", re.I)
if any(reEfi.search(x) for x in value): if any(reEfi.search(x) for x in value):
if self.Get('cl_client_type') == 'gui': if self.Get('cl_client_type') == 'gui':
raise VariableError( raise VariableError(
@ -1271,10 +1271,10 @@ class VariableOsLocationDest(LocationHelper, Variable):
DEVICE, MP = 0, 1 DEVICE, MP = 0, 1
srcMountPoints = map(lambda x: x[DEVICE], binds) srcMountPoints = map(lambda x: x[DEVICE], binds)
destMountPoints = map(lambda x: x[MP], binds) destMountPoints = map(lambda x: x[MP], binds)
wrongBind = filter(lambda x: x in destMountPoints, srcMountPoints) wrongBind = list(filter(lambda x: x in destMountPoints, srcMountPoints))
if wrongBind: if wrongBind:
incompBind = filter(lambda x: x[1] == wrongBind[0], incompBind = list(filter(lambda x: x[1] == wrongBind[0],
zip(srcMountPoints, destMountPoints)) 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'") \
@ -1298,8 +1298,8 @@ 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 = list(filter(lambda x: checkType + "member" in x[1],
installTypes) 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 +1317,13 @@ 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')) list(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")
value = [""] * len(source) value = [""] * len(source)
return map(self.defaultFormat(), return list(map(self.defaultFormat(),
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":
@ -1384,8 +1384,8 @@ class VariableOsLocationFormat(LocationHelper, Variable):
value = map(lambda x: "vfat" if x == "uefi" else x, value) value = map(lambda x: "vfat" if x == "uefi" else x, 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 list(map(self.defaultFormat(),
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 +1423,17 @@ 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 list(map(lambda x: "on",
self.Get('cl_autopartition_disk_format')) + \ self.Get('cl_autopartition_disk_format'))) + \
map(lambda x: "", list(map(lambda x: "",
self.Get('cl_autopartition_bind_path')) 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 list(map(self.defaultPerformFormat(),
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 +1531,11 @@ 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 list(map(self.defaultPerformFormat(),
map(lambda x: [x[DEV], x[MP], x[FS], ""] \ map(lambda x: [x[DEV], x[MP], x[FS], ""] \
if x[FORMAT] == "off" and not x[DEV].startswith("/dev/") if x[FORMAT] == "off" and not x[DEV].startswith("/dev/")
else x, else x,
info)) info)))
class VariableOsLocationSize(LocationHelper, SourceReadonlyVariable): class VariableOsLocationSize(LocationHelper, SourceReadonlyVariable):
@ -1678,8 +1678,8 @@ 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 list(map(lambda x: self.getPerfectName(x, defaultValue=x),
self.Get()) self.Get()))
class VariableOsInstallDiskUuid(ReadonlyVariable): class VariableOsInstallDiskUuid(ReadonlyVariable):
@ -1691,7 +1691,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 list(map(lambda x: hashUUID.get(x, "")[5:], diskDev))
class VariableOsInstallDiskPartuuid(ReadonlyVariable): class VariableOsInstallDiskPartuuid(ReadonlyVariable):
""" """
@ -1756,9 +1756,9 @@ 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 list(map(lambda x: "UUID=%s" % x[0] if x[0] else x[1],
zip(self.Get('os_install_disk_uuid'), 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 +1820,11 @@ class VariableOsInstallDiskPerformFormat(ReadonlyVariable):
type = "bool-list" type = "bool-list"
def get(self): def get(self):
_format = map(lambda x: x[2], _format = list(map(lambda x: x[2],
filter(lambda x: x[0].startswith('/dev/') and x[1], filter(lambda x: x[0].startswith('/dev/') and x[1],
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 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 +1880,9 @@ class VariableOsInstallDiskName(Variable):
else: else:
return diskLabel.get(dev, '') return diskLabel.get(dev, '')
return map(changeLabel, return list(map(changeLabel,
self.ZipVars('os_install_disk_dev', self.ZipVars('os_install_disk_dev',
'os_install_disk_mount')) 'os_install_disk_mount')))
class VariableOsInstallDiskSize(SourceReadonlyVariable): class VariableOsInstallDiskSize(SourceReadonlyVariable):
@ -2058,7 +2058,7 @@ class VariableOsInstallUefi(LocationHelper, Variable):
opt = ["--uefi"] opt = ["--uefi"]
metavalue = "EFI" metavalue = "EFI"
re_not0_raid = re.compile("-raid[1-9]") re_not0_raid = re.compile(r"-raid[1-9]")
def init(self): def init(self):
self.label = _("UEFI boot") self.label = _("UEFI boot")
@ -2118,7 +2118,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 list(filter(lambda x: x != "off", map(transform, value)))
def choice(self): def choice(self):
deviceParentMap = self.ZipVars('os_device_dev', deviceParentMap = self.ZipVars('os_device_dev',
@ -2233,7 +2233,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 list(filter(lambda x: x != "off", value))
def check(self, value): def check(self, value):
if self.GetBool('cl_autopartition_set'): if self.GetBool('cl_autopartition_set'):

@ -42,21 +42,21 @@ setLocalTranslate('cl_install3', sys.modules[__name__])
class DistroRepository(Linux): class DistroRepository(Linux):
contentCache = {} contentCache = {}
marches = ['i686', 'x86_64'] marches = [r'i686', r'x86_64']
extensiton = ['iso', 'tar.bz2', 'tar.gz', 'tar.7z', 'tar.lzma'] extensiton = [r'iso', r'tar.bz2', r'tar.gz', r'tar.7z', r'tar.lzma']
reDistName = re.compile(""" reDistName = re.compile(r"""
^.*/(?P<os_linux_shortname>%(name)s) ^.*/(?P<os_linux_shortname>%(name)s)
-(?P<os_linux_ver>%(ver)s) -(?P<os_linux_ver>%(ver)s)
(?:-(?P<serial_id>%(ser)s))? (?:-(?P<serial_id>%(ser)s))?
-(?P<os_arch_machine>%(march)s) -(?P<os_arch_machine>%(march)s)
.(?P<ext>%(ext)s)$""" % .(?P<ext>%(ext)s)$""" %
{'name': "[a-z0-9]+", {r'name': r"[a-z0-9]+",
'ver': r"(\d+\.)*\d+", r'ver': r"(\d+\.)*\d+",
'ser': r"\d+", r'ser': r"\d+",
'march': "|".join(marches), r'march': r"|".join(marches),
'ext': "|".join(extensiton) r'ext': r"|".join(extensiton)
}, re.X) }, re.X)
def _getDistrInfo(self, filename): def _getDistrInfo(self, filename):
@ -71,9 +71,9 @@ class DistroRepository(Linux):
distdic = match.groupdict() distdic = match.groupdict()
distdic["os_linux_build"] = "" distdic["os_linux_build"] = ""
if "os_linux_ver" in distdic: if "os_linux_ver" in distdic:
if re.match("^\d{8}$", distdic["os_linux_ver"]): if re.match(r"^\d{8}$", distdic["os_linux_ver"]):
distdic["os_linux_build"] = distdic["os_linux_ver"] distdic[r"os_linux_build"] = distdic["os_linux_ver"]
distdic["os_linux_ver"] = "" distdic[r"os_linux_ver"] = ""
return distdic return distdic
def getImage(self, scratch, rootType, imagePath, march=None, def getImage(self, scratch, rootType, imagePath, march=None,
@ -100,7 +100,7 @@ class DistroRepository(Linux):
def opcompareByString(self, buf): def opcompareByString(self, buf):
if buf: if buf:
reOp = re.compile("^(!=|=|==|<=|>=|>|<)?(\d+.*)$") reOp = re.compile(r"^(!=|=|==|<=|>=|>|<)?(\d+.*)$")
res = reOp.search(buf) res = reOp.search(buf)
if res: if res:
return ({'!=': operator.ne, return ({'!=': operator.ne,
@ -161,18 +161,18 @@ 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 list(filter(lambda x: not path.isdir(path.join(pathname, x)),
listDirectory(pathname)) listDirectory(pathname)))
# get lists files in directories # get lists files in directories
allFiles = map(lambda x: map(lambda y: path.join(x, y), allFiles = map(lambda x: map(lambda y: path.join(x, y),
listdistr(x)), listdistr(x)),
dirs) dirs)
# filter distributives # filter distributives
return filter(distfilter, return list(filter(distfilter,
# join files lists to one list # join files lists to one list
reduce(lambda x, y: x + y, reduce(lambda x, y: x + y,
allFiles, [])) allFiles, [])))
def extcomparator(self, *exts): def extcomparator(self, *exts):
"""Compare extensions""" """Compare extensions"""
@ -210,12 +210,12 @@ 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 = list(filter(lambda x: x[1] and "ext" in x[1] and
not x[1]["ext"] in discardType, not x[1]["ext"] in discardType,
map(lambda x: (x, self._getDistrInfo(x)), map(lambda x: (x, self._getDistrInfo(x)),
availDistrs)) availDistrs)))
return map(lambda x: x[0], return list(map(lambda x: x[0],
sorted(availDistrs, self.sortdistrfunc, reverse=True)) 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 = list(filter(lambda x: x, listimgs))
if listimgs: if listimgs:
return max(listimgs, key=keyfunc).group() return max(listimgs, key=keyfunc).group()
return "" return ""
@ -245,15 +245,15 @@ class DistroRepository(Linux):
def getBestStage(self, dirs, march=None, hardened=None): def getBestStage(self, dirs, march=None, hardened=None):
"""Get latest stage by march""" """Get latest stage by march"""
if march: if march:
march = {'x86_64': 'amd64'}.get(march, march) march = {r'x86_64': r'amd64'}.get(march, march)
else: else:
march = "[^-]+" march = r"[^-]+"
if hardened is None: if hardened is None:
hardened = "(?:-hardened)?" hardened = r"(?:-hardened)?"
elif hardened is True: elif hardened is True:
hardened = "-hardened" hardened = r"-hardened"
elif hardened is False: elif hardened is False:
hardened = "" hardened = r""
reStage = re.compile(r'^.*/stage3-%s%s-(\d+)\.tar\.bz2$' % reStage = re.compile(r'^.*/stage3-%s%s-(\d+)\.tar\.bz2$' %
(march, hardened), re.S) (march, hardened), re.S)
return self._findLatestFile(dirs, reStage, lambda x: x.groups()[0]) return self._findLatestFile(dirs, reStage, lambda x: x.groups()[0])
@ -500,21 +500,21 @@ 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 = list(filter(listDirectory,
livedistr)[: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 += \
map(lambda x: x[0], list(map(lambda x: x[0],
filter(lambda x: " live" in x[1] and x[0] != rootDev, filter(lambda x: " live" in x[1] and x[0] != rootDev,
zip(self.Get('os_disk_dev'), zip(self.Get('os_disk_dev'),
self.Get('os_disk_content')))) self.Get('os_disk_content')))))
# add to standard path # add to standard path
return filter(path.exists, return list(filter(path.exists,
['/var/calculate/remote/linux', ['/var/calculate/remote/linux',
'/var/calculate/linux'] + livedistr) '/var/calculate/linux'] + livedistr))
class VariableClSource(ReadonlyVariable): class VariableClSource(ReadonlyVariable):

@ -142,10 +142,10 @@ class VariableOsInstallKernelConfig(ReadonlyVariable):
makefile_path = path.join(distr_path, kernel_src, "Makefile") makefile_path = path.join(distr_path, kernel_src, "Makefile")
# get version from Makefile # get version from Makefile
re_makefile = re.compile("^VERSION = (\S+)\n" re_makefile = re.compile(r"^VERSION = (\S+)\n"
"PATCHLEVEL = (\S+)\n" r"PATCHLEVEL = (\S+)\n"
"SUBLEVEL = (\S+)\n" r"SUBLEVEL = (\S+)\n"
"EXTRAVERSION = (\S*)\n", re.M) r"EXTRAVERSION = (\S*)\n", re.M)
if path.exists(makefile_path): if path.exists(makefile_path):
with open(makefile_path) as f: with open(makefile_path) as f:
match = re_makefile.search(f.read(200)) match = re_makefile.search(f.read(200))
@ -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 = list(map(schedulers.get,
filter(lambda x: x in schedulers, filter(lambda x: x in schedulers,
self.Get('os_install_kernel_config'))) or ['cfq'] self.Get('os_install_kernel_config')))) 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())]
@ -332,7 +332,7 @@ class KernelHelper(VariableInterface):
Helper for kernel variables Helper for kernel variables
""" """
reFindVer = re.compile( reFindVer = re.compile(
"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)") r"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)")
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"""
@ -341,16 +341,16 @@ class KernelHelper(VariableInterface):
filesWithType = map(lambda x: (x, ftype(x)), filesWithType = map(lambda x: (x, ftype(x)),
filter(path.exists, filter(path.exists,
filelist)) filelist))
return filter(lambda x: x[1] and descr in x[1], filesWithType) return list(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 = list(map(lambda x: path.join(pathname, x), 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="",
notsuffix=""): notsuffix=""):
"""Get initrd for kernel""" """Get initrd for kernel"""
reInitrdVer = re.compile("(initrd|initramfs)-(.+?)(-install)?$", re.S) reInitrdVer = re.compile(r"(initrd|initramfs)-(.+?)(-install)?$", re.S)
def initrd_version_by_name(filename): def initrd_version_by_name(filename):
resInitrdVer = reInitrdVer.search(filename) resInitrdVer = reInitrdVer.search(filename)
@ -373,13 +373,13 @@ class KernelHelper(VariableInterface):
bootdir = path.join(chroot, 'boot') bootdir = path.join(chroot, 'boot')
initramfsFiles = self.getInitrdFiles(bootdir) initramfsFiles = self.getInitrdFiles(bootdir)
initramfsWithVer = \ initramfsWithVer = \
filter(lambda x: (kernelVersion in x[1] or list(filter(lambda x: (kernelVersion in x[1] or
origKernelVer in x[1]) and \ origKernelVer in x[1]) and \
x[0].endswith(suffix) 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)), map(lambda x: (x, initrd_version_by_name(x)),
initramfsFiles)) 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]
@ -398,17 +398,17 @@ class VariableOsInstallKernel(ReadonlyVariable, KernelHelper):
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))))
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 +469,9 @@ 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 = list(map(lambda x: x.partition('=')[2].strip("\n '\""),
filter(lambda x: x.startswith('modules_3'), filter(lambda x: x.startswith('modules_3'),
readLinesFile('/etc/conf.d/modules'))) readLinesFile('/etc/conf.d/modules'))))
if cpufreqmods: if cpufreqmods:
return cpufreqmods[0] return cpufreqmods[0]
else: else:

@ -53,9 +53,9 @@ 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 = list(map(lambda x: x.strip().rpartition('=')[-1].strip('"\''),
filter(lambda x: x.startswith("LINGUAS="), filter(lambda x: x.startswith("LINGUAS="),
lines)) lines)))
return linguas[-1] if linguas else "" return linguas[-1] if linguas else ""
makeconf = '/etc/make.conf' makeconf = '/etc/make.conf'
@ -137,8 +137,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 +164,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,8 +337,8 @@ 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 = list(map(lambda x: x.encode('utf-8'),
country_timezones[lang]) country_timezones[lang]))
source = nativeTZ + ["---"] + \ source = nativeTZ + ["---"] + \
sorted(filter(lambda x: not x in nativeTZ, source), sorted(filter(lambda x: not x in nativeTZ, source),
key=sortkey) key=sortkey)

@ -310,11 +310,11 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable):
return "" return ""
pciEthernet = lspci(shortInfo=True) pciEthernet = lspci(shortInfo=True)
return map(lambda x: "{vendor} {name}".format(**x), return list(map(lambda x: "{vendor} {name}".format(**x),
map(lambda x: pciEthernet.get(getPci(x), map(lambda x: pciEthernet.get(getPci(x),
{'vendor': _("Unknown"), {'vendor': _("Unknown"),
'name': _("vendor")}), 'name': _("vendor")}),
self.Get('os_install_net_interfaces'))) self.Get('os_install_net_interfaces'))))
class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable): class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable):
@ -336,7 +336,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 list(map(self._mactype, self.Get('os_install_net_mac')))
class VariableOsInstallNetMac(NetHelper, ReadonlyVariable): class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
@ -349,8 +349,8 @@ class VariableOsInstallNetMac(NetHelper, ReadonlyVariable):
self.label = _("MAC") self.label = _("MAC")
def get(self): def get(self):
return map(lambda x: getMac(x).lower(), return list(map(lambda x: getMac(x).lower(),
self.Get('os_install_net_interfaces')) self.Get('os_install_net_interfaces')))
class VariableOsInstallNetStatus(NetHelper, Variable): class VariableOsInstallNetStatus(NetHelper, Variable):
@ -363,8 +363,8 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
self.label = _("IP address") self.label = _("IP address")
def get(self): def get(self):
return map(self.getDefaultValue, return list(map(self.getDefaultValue,
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):
@ -389,9 +389,9 @@ class VariableOsInstallNetStatus(NetHelper, Variable):
def set(self, value): def set(self, value):
value = map(lambda x: x.lower() if x else x, value) value = map(lambda x: x.lower() if x else x, value)
ifaces = self.Get('os_install_net_interfaces') ifaces = self.Get('os_install_net_interfaces')
return map(lambda x: self.getDefaultValue(x[1]) \ return list(map(lambda x: self.getDefaultValue(x[1]) \
if x[0] == "auto" else x[0], if x[0] == "auto" else x[0],
zip(value, ifaces)) zip(value, ifaces)))
def check(self, value): def check(self, value):
for status in value: for status in value:
@ -415,10 +415,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 list(map(lambda x: "" 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],
zip(self.Get('os_install_net_interfaces'), 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 +439,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 list(map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "",
zip(self.Get('os_install_net_ip'), 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 +457,8 @@ 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 list(map(lambda x: maskToCidr(x) if x else '',
self.Get('os_install_net_mask')) self.Get('os_install_net_mask')))
class VariableOsInstallNetMask(NetHelper, Variable): class VariableOsInstallNetMask(NetHelper, Variable):
@ -471,8 +471,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 list(map(lambda x: cidrToMask(getMask(x)),
self.Get('os_install_net_interfaces')) self.Get('os_install_net_interfaces')))
def set(self, value): def set(self, value):
""" """
@ -490,9 +490,9 @@ class VariableOsInstallNetMask(NetHelper, Variable):
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 = list(filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \
not checkMask(x[0]), not checkMask(x[0]),
zip(value, dhcps)) 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 +514,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 list(map(lambda x: "on" if x == "dhcp" else "off",
self.Get('os_install_net_status')) self.Get('os_install_net_status')))
class VariableOsInstallNetRouteData(NetHelper, TableVariable): class VariableOsInstallNetRouteData(NetHelper, TableVariable):
@ -545,18 +545,18 @@ class VariableOsInstallNetRouteData(NetHelper, TableVariable):
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 = \
map(itemgetter(0, 2), list(map(itemgetter(0, 2),
filter(lambda x: not x[1] in ("off", "dhcp"), filter(lambda x: not x[1] in ("off", "dhcp"),
zip(interfaces, interfaces_status, interfaces_network))) 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 list(map(lambda x: [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', '')],
ifilter(lambda x: not x[0] in skipNet, filter(lambda x: not x[0] in skipNet,
ip.getRouteTable(staticInterface))) or [[]] ip.getRouteTable(staticInterface)))) or [[]]
return [[]] return [[]]
def getHumanReadableAuto(self): def getHumanReadableAuto(self):
@ -598,8 +598,8 @@ 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(filter(lambda x: value.count(x) > 1,
@ -630,15 +630,15 @@ class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable):
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')))
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 = map(lambda x: x[GW], wrongGws = list(map(lambda x: x[GW],
filter(lambda x: not ip.isIpInNet(x[GW], filter(lambda x: not ip.isIpInNet(x[GW],
*(set(nets) - set( *(set(nets) - set(
x[NET]))), x[NET]))),
filter(lambda x: x[GW], filter(lambda x: x[GW],
netsGw))) netsGw))))
if wrongGws: if wrongGws:
raise VariableError(_("Gateways %s are unreachable") % raise VariableError(_("Gateways %s are unreachable") %
(",".join(wrongGws))) (",".join(wrongGws)))
@ -674,12 +674,12 @@ 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 = list(filter(lambda x: x and not x in ipAddrs,
value) 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 +697,14 @@ 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 list(map(lambda x: performFunc(x[DEV], x[NET], routeMatrix),
# union ip and mask to ip/net # union ip and mask to ip/net
map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \ map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \
if x[IP] and x[CIDR] else (x[DEV], ""), if x[IP] and x[CIDR] else (x[DEV], ""),
# filter(lambda x:x[IP] and x[CIDR], # filter(lambda x:x[IP] and x[CIDR],
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"""
@ -757,10 +757,10 @@ 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 = list(map(lambda x: "%s;" % x[GW],
filter(lambda x: interface == x[DEV] and \ filter(lambda x: interface == x[DEV] and \
x[NET] == "default", x[NET] == "default",
routeMatrix)) routeMatrix)))
return "{0}\n".format(defaultGw[0] if defaultGw else "") + \ return "{0}\n".format(defaultGw[0] if defaultGw else "") + \
"\n".join( "\n".join(
# build string for route from net,gateway,dev and src # build string for route from net,gateway,dev and src
@ -799,10 +799,10 @@ 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 list(map(itemgetter(0, 2),
filter(lambda x: not x[1] or isPkgInstalled(x[1], filter(lambda x: not x[1] or isPkgInstalled(x[1],
prefix=distrPath), prefix=distrPath),
mapNetConf)) 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,9 +822,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 list(filter(lambda x: x.lower() == "networkmanager",
listDirectory('/etc/runlevels/boot') + listDirectory('/etc/runlevels/boot') +
listDirectory('/etc/runlevels/default')) \ listDirectory('/etc/runlevels/default'))) \
or self.Get('os_root_type') == "livecd": or self.Get('os_root_type') == "livecd":
nm = "networkmanager" nm = "networkmanager"
else: else:
@ -863,7 +863,7 @@ class VariableOsInstallNetDnsSearch(NetHelper, Variable):
return False return False
def set(self, value): def set(self, value):
return " ".join(re.split('[; ,]', value)) return " ".join(re.split(r'[; ,]', value))
def get(self): def get(self):
"""Get current name servers""" """Get current name servers"""
@ -891,7 +891,7 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
self.help = _("domain name server (comma-separated)") self.help = _("domain name server (comma-separated)")
def set(self, value): def set(self, value):
return " ".join(re.split('[; ,]', value)) return " ".join(re.split(r'[; ,]', value))
def get(self): def get(self):
dnsIps = filter(ip.checkIp, dnsIps = filter(ip.checkIp,
@ -904,7 +904,7 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch):
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 +938,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 list(filter(None, ips))

@ -69,7 +69,7 @@ class GrubHelper(VariableInterface):
Получить пароль из конфигурационного файла grub Получить пароль из конфигурационного файла grub
""" """
data = readFile(self.grub_passwd_file) data = readFile(self.grub_passwd_file)
reRootPwd = re.compile("password_pbkdf2 root (\S+)") reRootPwd = re.compile(r"password_pbkdf2 root (\S+)")
pwd = reRootPwd.search(data) pwd = reRootPwd.search(data)
if pwd: if pwd:
return pwd.group(1) return pwd.group(1)
@ -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 list(map(self.checkFunc, self.Get('os_format_type')))
class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable): class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable):
@ -194,10 +194,10 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable):
содержит пустую строку содержит пустую строку
""" """
def get(self): def get(self):
rootPasswd = map(lambda x: x[1], rootPasswd = list(map(lambda x: x[1],
filter("root".__eq__, filter("root".__eq__,
map(lambda x: x.split(':')[0:2], map(lambda x: x.split(':')[0:2],
readLinesFile('/etc/shadow')))) readLinesFile('/etc/shadow')))))
if rootPasswd: if rootPasswd:
rootPasswd = rootPasswd[0] rootPasswd = rootPasswd[0]
else: else:
@ -419,7 +419,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 list(map(lambda x: x if x else self.default_value, value))
class VariableOsAvailableGroups(ReadonlyVariable): class VariableOsAvailableGroups(ReadonlyVariable):
@ -476,8 +476,8 @@ 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 = list(map(lambda x: sorted(list(set(self.process_groups(x)))),
value) value))
return value return value
def getPrimaryGroup(self, username): def getPrimaryGroup(self, username):
@ -491,11 +491,11 @@ class VariableClMigrateUserGroups(UserHelper, Variable):
User groups User groups
""" """
passwdList = getPasswdUsers() passwdList = getPasswdUsers()
return map(lambda x: sorted(self.getPrimaryGroup(x) + return list(map(lambda x: sorted(self.getPrimaryGroup(x) +
(getUserGroups(x) (getUserGroups(x)
if x in passwdList else if x in passwdList else
self.getDefaultGroups())), self.getDefaultGroups())),
self.Get('cl_migrate_user')) self.Get('cl_migrate_user')))
def choice(self): def choice(self):
""" """
@ -525,15 +525,15 @@ 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 = list(filter(lambda x: len(x) == lenData,
map(lambda x: x.rstrip().split(":"), f)) map(lambda x: x.rstrip().split(":"), f)))
shadowData = filter(lambda x: x[0] in migrateusers, shadowData) shadowData = list(filter(lambda x: x[0] in migrateusers, shadowData))
shadowData = map(lambda x: (x[0], x[1]), shadowData) shadowData = list(map(lambda x: (x[0], x[1]), shadowData))
shadowUsers = map(lambda x: x[0], shadowData) shadowUsers = list(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 = list(filter(lambda x: x[0] == userName,
shadowData) 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 +559,8 @@ 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 list(map(lambda x: x if shadow_hash.identify(x) or not x else \
shadow_hash.hash(x), value) shadow_hash.hash(x), value))
class VariableClAutologin(UserHelper, Variable): class VariableClAutologin(UserHelper, Variable):
@ -587,8 +587,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", nonRootUsers = list(filter(lambda x: x != "root",
self.Get('cl_migrate_user')) self.Get('cl_migrate_user')))
if nonRootUsers: if nonRootUsers:
return nonRootUsers[0] return nonRootUsers[0]
else: else:
@ -716,14 +716,14 @@ 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 = list(filter(lambda x: " %s: " % category in x,
process(lsPciProg, "-d", vendor, "-n")) process(lsPciProg, "-d", vendor, "-n")))
cardsid = \ cardsid = \
map(lambda x: x.groups()[0], list(map(lambda x: x.groups()[0],
filter(lambda x: x, filter(lambda x: x,
map(lambda x: re.search( map(lambda x: re.search(
"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x), r"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x),
nvidiacards))) nvidiacards))))
if not cardsid: if not cardsid:
return set() return set()
return set(cardsid) return set(cardsid)
@ -748,7 +748,7 @@ class VariableOsNvidiaMask(ReadonlyVariable):
eclassdata = readFile(nvidiaeclass) eclassdata = readFile(nvidiaeclass)
reBlock = re.compile( reBlock = re.compile(
r"if has \$\{nvidia_gpu\}\s+\\([^;]+);\s*then(.*?)fi", re.S) r"if has \$\{nvidia_gpu\}\s+\\([^;]+);\s*then(.*?)fi", re.S)
reMask = re.compile('>=x11-drivers/nvidia-drivers[^"]+') reMask = re.compile(r'>=x11-drivers/nvidia-drivers[^"]+')
masks = [] masks = []
for block in reBlock.findall(eclassdata): for block in reBlock.findall(eclassdata):
nvidia_ids, mask_data = block nvidia_ids, mask_data = block
@ -838,9 +838,9 @@ 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, if grubInstall and list(filter(lambda x: "1.99" in x or "2." in x,
process(chroot_cmd, chroot_path, process(chroot_cmd, chroot_path,
grubInstall, '--version')): grubInstall, '--version'))):
return grubInstall return grubInstall
return "" return ""
@ -964,7 +964,7 @@ class VariableOsInstallGrubTerminal(Variable):
if getValueFromConfig(grubDefault, 'GRUB_TERMINAL') == 'console': if getValueFromConfig(grubDefault, 'GRUB_TERMINAL') == 'console':
return 'console' return 'console'
grubCfg = '/boot/grub/grub.cfg' grubCfg = '/boot/grub/grub.cfg'
if re.search('^terminal_output\s*console', readFile(grubCfg), re.M): if re.search(r'^terminal_output\s*console', readFile(grubCfg), re.M):
return 'console' return 'console'
return 'gfxterm' return 'gfxterm'

Loading…
Cancel
Save