diff --git a/pym/install/distr.py b/pym/install/distr.py index 3ac4d11..7713da6 100644 --- a/pym/install/distr.py +++ b/pym/install/distr.py @@ -374,10 +374,10 @@ class Distributive(object): joinFrom = partial(path.join, fromdir) params = [cpCmd, "-x"] + \ (["--no-preserve=mode,ownership"] if noperm else ["-a"]) + \ - list(map(joinFrom, - filterfalse(byfile or operator.not_, - listDirectory(fromdir)))) + \ - [todir] + [joinFrom(x) for x + in filterfalse(byfile or operator.not_, + listDirectory(fromdir))] + \ + [todir] cpProcess = cpProcessProgress(*params, maxfiles=filesnum, stderr=STDOUT) for perc in cpProcess.progress(): @@ -386,8 +386,7 @@ class Distributive(object): errmes = cpProcess.read() # copy by one file if byfile: - percFiles = list(filter(byfile, - listDirectory(fromdir))) + percFiles = [x for x in listDirectory(fromdir) if byfile(x)] if len(percFiles) > 1: maxPercOnFile = 100 / len(percFiles) recountPerc = \ @@ -441,9 +440,7 @@ class Distributive(object): def _getLastLive(self, directory): """Get last live squashfs image from directory""" - squashfiles = list(filter(lambda x: x, - map(self.reLive.search, - listDirectory(directory)))) + squashfiles = [x for x in map(self.reLive.search, listDirectory(directory)) if x] if squashfiles: return max(squashfiles, key=self._getSquashNum).group() return None @@ -822,27 +819,27 @@ class MultiPartitions: def getSystemId(self): """Get systemID for change [None,82,...]""" - return list(map(lambda x: x.systemId, self.listPartitions)) + return [x.systemId for x in self.listPartitions] def getPartitionTable(self): """Get systemID for change [dos,gpt,...]""" - return list(map(lambda x: x.partitionTable, self.listPartitions)) + return [x.partitionTable for x in self.listPartitions] def getIsFormat(self): """Get list is format [True,...]""" - return list(map(lambda x: x.isFormat, self.listPartitions)) + return [x.isFormat for x in self.listPartitions] def getFileSystems(self): """Get list filesystems ["reiserfs",...]""" - return list(map(lambda x: x.fileSystem, self.listPartitions)) + return [x.fileSystem for x in self.listPartitions] def getPartitions(self): """Get list partition ["/dev/sda",...]""" - return list(map(lambda x: x.dev, self.listPartitions)) + return [x.dev for x in self.listPartitions] def getMountPoints(self): """Get list mount point ["/boot",...]""" - return list(map(lambda x: x.mountPoint, self.listPartitions)) + return [x.mountPoint for x in self.listPartitions] class FormatProcess(process): @@ -1084,8 +1081,7 @@ class PartitionDistributive(Distributive): def postinstallMountBind(self): """Mount bind mount point and create mount dirs""" if self.multipartition and self.DirectoryObject: - mulipartDataBind = list(filter(lambda x: x[2] == "bind", - self.getMultipartData())) + mulipartDataBind = [x for x in self.getMultipartData() if x[2] == "bind"] dirObj = self.DirectoryObject mdirectory = dirObj.directory for srcDir, destDir, fileSystem, isFormat, partTable \ @@ -1166,10 +1162,8 @@ class PartitionDistributive(Distributive): self.multipartition.getMountPoints() + \ ["/"]) # get partition which need format - formatPartitions = list(map(lambda x: (x[FS], x[DEV], x[NEWID], x[MP]), - filter( - lambda x: x[NEEDFORMAT] and x[FS] != "bind", - dataPartitions))) + formatPartitions = [(x[FS], x[DEV], x[NEWID], x[MP]) for x + in dataPartitions if x[NEEDFORMAT] and x[FS] != "bind"] # if has separate /boot partition bootmp = ["/boot", "/"] purpose_map = {"/boot": "boot", @@ -1194,9 +1188,8 @@ class PartitionDistributive(Distributive): self.formatPartition(dev, format=fileSystem, purpose=purpose_map.get(mp, None)) # change system id for partitions - changeidPartitions = list(map(lambda x: (x[NEWID], x[DEV], x[PARTTABLE]), - filter(lambda x: x[NEWID], - dataPartitions))) + changeidPartitions = [(x[NEWID], x[DEV], x[PARTTABLE]) for x + in dataPartitions if x[NEWID]] for systemid, dev, partTable in changeidPartitions: self.changeSystemID(dev, systemid, partTable) return True @@ -1495,7 +1488,7 @@ class ContainerDistributive(ArchiveDistributive): if self.exclude: exclude_list = list(calculate_exclude( directory, exclude=self.exclude, include=self.include)) - params += list(map(lambda x: "--exclude=./%s" % x, exclude_list)) + params += ["--exclude=./%s" % x for x in exclude_list] params += ["."] #debug_file = "/var/calculate/tmp/rootfs.tar.xz" @@ -1880,7 +1873,7 @@ class FlashDistributive(PartitionDistributive): clear_match = re.compile( r"^(boot|efi|isolinux|syslinux|id.*\.uefi|" "ldlinux.c32|ldlinux.sys|livecd|livecd.squashfs)$") - for fn in list(filter(clear_match.match, listDirectory(dn))): + for fn in [x for x in listDirectory(dn) if clear_match.match(x)]: full_path = path.join(dn, fn) try: if path.isdir(full_path): diff --git a/pym/install/fs_manager.py b/pym/install/fs_manager.py index 2a4fc11..148e846 100644 --- a/pym/install/fs_manager.py +++ b/pym/install/fs_manager.py @@ -27,34 +27,51 @@ class FileSystemManager(object): defaultOpt = ['noatime'] defaultBindOpts = ['bind'] + #Python3 compat problem: + # dict keys() now sorted based on insertion order, + # instead of being sorted arbitrary by hash. + # Just so the order of keys could be the same as + # in older version, I swaped some pairs around. supportFS = { - 'ext2': {'defaultopt': defaultOpt, - 'format': '/sbin/mkfs.ext2', - 'formatparam': '{labelparam} {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'ssd': [], - 'msdos': '83', - 'compress': None, - 'type': ['hdd', 'usb-hdd']}, - 'ext3': {'defaultopt': defaultOpt, - 'format': '/sbin/mkfs.ext3', - 'formatparam': '{labelparam} {device}', + 'f2fs': {'defaultopt': defaultOpt, + 'format': '/usr/sbin/mkfs.f2fs', + 'formatparam': '{labelparam} -f {device}', + 'gpt': '8300', + 'label': '-l {labelname}', + 'msdos': '83', + 'ssd': [], + 'compress': None, + 'type': ['hdd', 'usb-hdd']}, + 'btrfs': {'defaultopt': defaultOpt, + 'format': '/sbin/mkfs.btrfs', + 'formatparam': '{labelparam} -f {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'msdos': '83', + 'ssd': ['ssd', 'discard', 'space_cache'], + 'type': ['hdd', 'usb-hdd'], + 'compress': None, + 'compatible': ['btrfs-compress']}, + 'ntfs-3g': {'defaultopt': defaultOpt, + 'format': '/usr/sbin/mkfs.ntfs', + 'formatparam': '{labelparam} -FQ {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'ssd': [], + 'auto': False, + 'msdos': '7', + 'compress': None, + 'compatible': ['ntfs']}, + 'ntfs': {'defaultopt': defaultOpt, + 'format': '/usr/sbin/mkfs.ntfs', + 'formatparam': '{labelparam} -FQ {device}', 'gpt': '8300', 'label': '-L {labelname}', + 'msdos': '7', + 'auto': False, 'ssd': [], - 'msdos': '83', 'compress': None, - 'type': ['hdd', 'usb-hdd']}, - 'ext4': {'defaultopt': defaultOpt, - 'format': '/sbin/mkfs.ext4', - 'formatparam': '{labelparam} {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'ssd': ['discard'], - 'msdos': '83', - 'compress': None, - 'type': ['hdd', 'usb-hdd']}, + 'compatible': ['ntfs-3g']}, 'reiserfs': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.reiserfs', 'formatparam': '{labelparam} -f {device}', @@ -64,16 +81,16 @@ class FileSystemManager(object): 'compress': None, 'ssd': [], 'type': ['hdd', 'usb-hdd']}, - 'btrfs': {'defaultopt': defaultOpt, - 'format': '/sbin/mkfs.btrfs', - 'formatparam': '{labelparam} -f {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'msdos': '83', - 'ssd': ['ssd', 'discard', 'space_cache'], - 'type': ['hdd', 'usb-hdd'], - 'compress': None, - 'compatible': ['btrfs-compress']}, + 'xfs': {'defaultopt': defaultOpt, + 'format': '/sbin/mkfs.xfs', + 'formatparam': '{labelparam} -f {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'msdos': '83', + 'boot': '-i sparce=0', + 'ssd': ['discard'], + 'compress': None, + 'type': ['hdd', 'usb-hdd']}, 'btrfs-compress': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.btrfs', 'orig': 'btrfs', @@ -85,6 +102,53 @@ class FileSystemManager(object): 'ssd': ['ssd', 'discard', 'space_cache'], 'type': ['hdd', 'usb-hdd'], 'compatible': ['btrfs']}, + 'ext4': {'defaultopt': defaultOpt, + 'format': '/sbin/mkfs.ext4', + 'formatparam': '{labelparam} {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'ssd': ['discard'], + 'msdos': '83', + 'compress': None, + 'type': ['hdd', 'usb-hdd']}, + 'ext3': {'defaultopt': defaultOpt, + 'format': '/sbin/mkfs.ext3', + 'formatparam': '{labelparam} {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'ssd': [], + 'msdos': '83', + 'compress': None, + 'type': ['hdd', 'usb-hdd']}, + 'ext2': {'defaultopt': defaultOpt, + 'format': '/sbin/mkfs.ext2', + 'formatparam': '{labelparam} {device}', + 'gpt': '8300', + 'label': '-L {labelname}', + 'ssd': [], + 'msdos': '83', + 'compress': None, + 'type': ['hdd', 'usb-hdd']}, + 'uefi': {'defaultopt': defaultOpt, + 'format': '/usr/sbin/mkfs.vfat', + 'formatparam': '{labelparam} -F 32 {device}', + 'gpt': 'EF00', + 'label': '-n {labelname}', + 'msdos': '0b', + 'ssd': [], + 'auto': False, + 'compress': None, + 'type': ['hdd']}, + 'vfat': {'defaultopt': defaultOpt, + 'format': '/usr/sbin/mkfs.vfat', + 'formatparam': '{labelparam} -F 32 {device}', + 'gpt': '0700', + 'label': '-n {labelname}', + 'msdos': '0b', + 'auto': False, + 'ssd': ['discard'], + 'compress': None, + 'type': ['flash']}, 'jfs': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.jfs', 'formatparam': '{labelparam} -f {device}', @@ -94,25 +158,6 @@ class FileSystemManager(object): 'ssd': ['discard'], 'compress': None, 'type': ['hdd', 'usb-hdd']}, - 'xfs': {'defaultopt': defaultOpt, - 'format': '/sbin/mkfs.xfs', - 'formatparam': '{labelparam} -f {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'msdos': '83', - 'boot': '-i sparce=0', - 'ssd': ['discard'], - 'compress': None, - 'type': ['hdd', 'usb-hdd']}, - 'f2fs': {'defaultopt': defaultOpt, - 'format': '/usr/sbin/mkfs.f2fs', - 'formatparam': '{labelparam} -f {device}', - 'gpt': '8300', - 'label': '-l {labelname}', - 'msdos': '83', - 'ssd': [], - 'compress': None, - 'type': ['hdd', 'usb-hdd']}, # 'nilfs2': {'defaultopt': defaultOpt, # 'format': '/sbin/mkfs.nilfs2', # 'formatparam': '{labelparam} {device}', @@ -130,46 +175,7 @@ class FileSystemManager(object): 'auto': False, 'compress': None, 'msdos': '82'}, - 'uefi': {'defaultopt': defaultOpt, - 'format': '/usr/sbin/mkfs.vfat', - 'formatparam': '{labelparam} -F 32 {device}', - 'gpt': 'EF00', - 'label': '-n {labelname}', - 'msdos': '0b', - 'ssd': [], - 'auto': False, - 'compress': None, - 'type': ['hdd']}, - 'vfat': {'defaultopt': defaultOpt, - 'format': '/usr/sbin/mkfs.vfat', - 'formatparam': '{labelparam} -F 32 {device}', - 'gpt': '0700', - 'label': '-n {labelname}', - 'msdos': '0b', - 'auto': False, - 'ssd': ['discard'], - 'compress': None, - 'type': ['flash']}, - 'ntfs': {'defaultopt': defaultOpt, - 'format': '/usr/sbin/mkfs.ntfs', - 'formatparam': '{labelparam} -FQ {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'msdos': '7', - 'auto': False, - 'ssd': [], - 'compress': None, - 'compatible': ['ntfs-3g']}, - 'ntfs-3g': {'defaultopt': defaultOpt, - 'format': '/usr/sbin/mkfs.ntfs', - 'formatparam': '{labelparam} -FQ {device}', - 'gpt': '8300', - 'label': '-L {labelname}', - 'ssd': [], - 'auto': False, - 'msdos': '7', - 'compress': None, - 'compatible': ['ntfs']}} + } default_param = {'defaultopt': defaultOpt, 'gpt': '8300', diff --git a/pym/install/install.py b/pym/install/install.py index a4a83c1..378d0b6 100644 --- a/pym/install/install.py +++ b/pym/install/install.py @@ -132,36 +132,56 @@ class Install(MethodsInterface): if partition_table == "dos": fdisk = process(fdisk_cmd, "-l", device_name) DEVICENUM, AFLAG = 0, 1 - change_active = map( - lambda x: x[DEVICENUM], - filter( - lambda x: (x[DEVICENUM] != partition_number and - x[AFLAG] == "*" or - x[DEVICENUM] == partition_number and - not x[AFLAG] == "*"), - list(map( - lambda x: [str(x[0]), x[1][1].strip()], - # enumerate partitions - enumerate(filter(None, map( - lambda x: x.split()[:2], - # drop string before information about partitions - dropwhile( - lambda x: not x.lstrip().startswith( - "Device"), - fdisk.readlines()))))))[1:])) + # change_active = map( + # lambda x: x[DEVICENUM], + # filter( + # lambda x: (x[DEVICENUM] != partition_number and + # x[AFLAG] == "*" or + # x[DEVICENUM] == partition_number and + # not x[AFLAG] == "*"), + # list(map( + # lambda x: [str(x[0]), x[1][1].strip()], + # # enumerate partitions + # enumerate(filter(None, map( + # lambda x: x.split()[:2], + # # drop string before information about partitions + # dropwhile( + # lambda x: not x.lstrip().startswith( + # "Device"), + # fdisk.readlines()))))))[1:])) + change_active = [x[DEVICENUM] for x + in [[str(y[0]), y[1][1].strip()] for y + in enumerate([z for z + in [o.split()[:2] for o + in dropwhile(lambda x: not x.lstrip().startswith("Device"),fdisk.readlines())] + if z])][1:] + if x[DEVICENUM] != partition_number and + x[AFLAG] == "*" or + x[DEVICENUM] == partition_number and + not x[AFLAG] == "*"] else: parted = process(parted_cmd, "-m", device_name, "print") DEVICENUM, FLAGS = 0, 6 - change_active = map( - lambda x: x[DEVICENUM], filter( - lambda x: (x[DEVICENUM] != partition_number and - boot_flag in x[FLAGS].strip(';').split(', ') or - x[DEVICENUM] == partition_number and - boot_flag not in - x[FLAGS].strip(';').split(', ')), - filter(lambda x: len(x) >= 7, - map(lambda x: x.split(':'), - parted.readlines()[2:])))) + # change_active = map( + # lambda x: x[DEVICENUM], filter( + # lambda x: (x[DEVICENUM] != partition_number and + # boot_flag in x[FLAGS].strip(';').split(', ') or + # x[DEVICENUM] == partition_number and + # boot_flag not in + # x[FLAGS].strip(';').split(', ')), + # filter(lambda x: len(x) >= 7, + # map(lambda x: x.split(':'), + # parted.readlines()[2:])))) + change_active = [x[DEVICENUM] for x + in [y for y + in [z.split(':') for z + in parted.readlines()[2:]] + if len(y) >= 7] + if x[DEVICENUM] != partition_number and + boot_flag in x[FLAGS].strip(';').split(', ') or + x[DEVICENUM] == partition_number and + boot_flag not in + x[FLAGS].strip(';').split(', ')] if not change_active: return True if partition_table == "dos": diff --git a/pym/install/migrate_users.py b/pym/install/migrate_users.py index 4796836..efced1e 100644 --- a/pym/install/migrate_users.py +++ b/pym/install/migrate_users.py @@ -480,9 +480,7 @@ class migrate(object): os.mkdir(homedir) os.chown(homedir, int(userdata[2]), int(userdata[3])) os.chmod(homedir, perms) - users = list( - set(map(lambda x: x[0], - addUsersList) + existsMigrateUsers) - {"root"}) + users = list(set([x[0] for x in addUsersList] + existsMigrateUsers) - {"root"}) try: map(createHome, filter(lambda x: x[0] in users, self.dataUsers)) except Exception as e: diff --git a/pym/install/variables/X11.py b/pym/install/variables/X11.py index 81f8cf3..bd7e18f 100644 --- a/pym/install/variables/X11.py +++ b/pym/install/variables/X11.py @@ -91,8 +91,7 @@ class ResolutionVariable(VideoVariable): "1600x900", "1600x1200", "2048x1152", "2560x1440", "2560x1600"] if self.fbres: - return list(map(lambda x: "%s-32" % x, - resolutions)) + return ["%s-32" % x for x in resolutions] else: return resolutions @@ -183,7 +182,7 @@ class VariableOsInstallX11VideoAvailable(VideoVariable): return [] def humanReadable(self): - return list(map(lambda x: self.driver_names.get(x, x), self.Get())) + return [self.driver_names.get(x, x) for x in self.Get()] class VariableOsX11KmsVideoDrv(ReadonlyVariable): @@ -219,9 +218,9 @@ class VariableOsInstallX11VideoDrv(VideoVariable): if self.Get('os_install_x11_server_set') == 'on': values = self.Get('os_install_x11_video_available') else: - values = self.nox_video_drivers() - return list(map(lambda x: (x, self.driver_names.get(x, x)), - (x for x in self.driver_names.keys() if x in values))) + values = self.nox_video_drivers() + return [(x, self.driver_names.get(x, x)) for x + in [y for y in self.driver_names.keys() if y in values]] def get(self): if self.Get('os_install_x11_server_set') == 'on': diff --git a/pym/install/variables/audio.py b/pym/install/variables/audio.py index 74013c9..cbc49be 100644 --- a/pym/install/variables/audio.py +++ b/pym/install/variables/audio.py @@ -88,10 +88,7 @@ class VariableOsAudioAvailable(Variable): with image as distr: try: distrPath = image.getDirectory() - return list(map(lambda x: x[0::2], - filter(lambda x: not x[1] or isPkgInstalled(x[1], - prefix=distrPath), - mapAudioConf))) + return [x[0::2] for x in mapAudioConf if not x[1] or isPkgInstalled(x[1], prefix=distrPath)] except DistributiveError as e: pass return sorted(map(lambda x: x[0::2], mapAudioConf[-1:]), diff --git a/pym/install/variables/autopartition.py b/pym/install/variables/autopartition.py index dcd2f06..fb42dc4 100644 --- a/pym/install/variables/autopartition.py +++ b/pym/install/variables/autopartition.py @@ -98,9 +98,7 @@ class VariableHrMemorySize(ReadonlyVariable): def get(self): reMemTotal = re.compile(r'^MemTotal:\s*(\d+)\s*kB$') - totalMemList = list(filter(lambda x: x, - map(reMemTotal.search, - readLinesFile('/proc/meminfo')))) + totalMemList = [x for x in map(reMemTotal.search, readLinesFile('/proc/meminfo')) if x] if totalMemList: size = int(totalMemList[0].group(1)) * Sizes.K return str(size) @@ -212,7 +210,7 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): self.label = _("Devices for install") def get(self): - choiceVal = list(map(lambda x: x[0], self.choice())) + choiceVal = [x[0] for x in self.choice()] devicesTypes = self.Select(['os_device_dev','os_device_type'], where='os_device_dev', _in=choiceVal) notFlashDevices = [x[0] for x in devicesTypes if x[1] != 'flash'] @@ -255,8 +253,9 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): def checkOnRaid(self, valuelist): disks = self.Select('os_disk_dev', where='os_disk_parent', _in=valuelist) - raids = list(filter(None, self.Select('os_disk_raid', - where='os_disk_dev', _in=disks))) + raids = [x for x + in self.Select('os_disk_raid', where='os_disk_dev', _in=disks) + if x] raidDisks = self.Select('os_disk_dev', where='os_disk_raid', _in=raids) raidDevices = self.Select('os_disk_parent', where='os_disk_dev', @@ -784,10 +783,10 @@ class VariableClAutopartitionDiskSize(DiskFilter, ReadonlyVariable): field = "disk_size" def get(self): - return list(map(str, super(VariableClAutopartitionDiskSize, self).get())) + return [str(x) for x in super(VariableClAutopartitionDiskSize, self).get()] def humanReadable(self): - return list(map(humanreadableSize, self.Get())) + return [humanreadableSize(x) for x in self.Get()] class VariableClAutopartitionDiskDataFull(ReadonlyTableVariable): @@ -876,10 +875,10 @@ class VariableClAutopartitionDiskSizeFull(ReadonlyVariable): def get(self): var_factory = self.Get('cl_autopartition_factory') - return list(map(str, var_factory.disk_size)) + return [str(x) for x in var_factory.disk_size] def humanReadable(self): - return list(map(humanreadableSize, self.Get())) + return [humanreadableSize(x) for x in self.Get()] class VariableClAutopartitionRaid(ReadonlyVariable): diff --git a/pym/install/variables/disk.py b/pym/install/variables/disk.py index a36a094..0307e22 100644 --- a/pym/install/variables/disk.py +++ b/pym/install/variables/disk.py @@ -50,8 +50,7 @@ class DeviceHelper(VariableInterface): def getBlockDevices(self): """Get interest devices from sys block path""" - return list(filter(self.rePassDevice.search, - device.udev.get_block_devices())) + return list(filter(self.rePassDevice.search, device.udev.get_block_devices())) def separateDevice(self, dev): """ @@ -59,8 +58,7 @@ class DeviceHelper(VariableInterface): Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1) """ - return list(map(lambda x: int(x) if x.isdigit() else x, - re.findall(r'\d+|\D+', dev))) + return [int(x) if x.isdigit() else x for x in re.findall(r'\d+|\D+', dev)] def mapUdevProperty(self, var, prop, default): """Get each element from var through udev [prop]""" @@ -180,8 +178,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable): if device.udev.is_device(device.udev.get_device_info(x)) or self.re_disk_raid.match(device.udev.get_device_type(path=x))) - return list(sorted((x for x in devnames), - key=self.separateDevice)) + return list(sorted((x for x in devnames), key=self.separateDevice)) class VariableOsDeviceFulltype(ReadonlyVariable): """ @@ -228,8 +225,7 @@ class VariableOsDeviceType(ReadonlyVariable): device.devfs.listdir(diskIdPath, fullpath=False))) else: self.usbdevices = [] - return list(map(self.getType, - self.Get('os_device_dev'))) + return list(map(self.getType, self.Get('os_device_dev'))) class VariableOsDeviceParent(ReadonlyVariable): @@ -313,8 +309,7 @@ class VariableOsDeviceMap(ReadonlyVariable): type = "list" def get(self): - return list(map(lambda x: str(x[0]), - enumerate(self.Get('os_device_dev')))) + return [str(x[0]) for x in enumerate(self.Get('os_device_dev'))] class VariableOsDeviceArraySet(ReadonlyVariable): @@ -334,9 +329,7 @@ class VariableOsDeviceArraySet(ReadonlyVariable): else: return "off" - return list(map(lambda x: isArray(*x), - zip(self.Get('os_device_dev'), - self.Get('os_device_name')))) + return [isArray(*x) for x in zip(self.Get('os_device_dev'), self.Get('os_device_name'))] class VariableOsDeviceSsdSet(ReadonlyVariable): @@ -361,9 +354,7 @@ class VariableOsDeviceSsdSet(ReadonlyVariable): else: return "off" - return list(map(lambda x: isSsd(*x), - zip(self.Get('os_device_dev'), - self.Get('os_device_name')))) + return [isSsd(*x) for x in zip(self.Get('os_device_dev'), self.Get('os_device_name'))] class VariableOsDeviceSyspath(ReadonlyVariable): @@ -403,10 +394,9 @@ class VariableOsDeviceVirtualSet(ReadonlyVariable): else: return "off" - return list(map(lambda x: isVirtual(*x), - zip(self.Get('os_device_dev'), - self.Get('os_device_name'), - self.Get('os_device_syspath')))) + return [isVirtual(*x) for x in zip(self.Get('os_device_dev'), + self.Get('os_device_name'), + self.Get('os_device_syspath'))] class VariableOsDeviceTable(ReadonlyVariable): @@ -444,8 +434,8 @@ class VariableOsDeviceTable(ReadonlyVariable): else: return getTable(dev) - return list(map(getByAutopartition, - self.Get('os_device_dev'))) + return list(map(getByAutopartition, self.Get('os_device_dev'))) + class VariableOsDeviceName(ReadonlyVariable): @@ -475,8 +465,7 @@ class VariableOsDeviceName(ReadonlyVariable): return "" def get(self): - return list(map(self.getName, - self.Get('os_device_dev'))) + return list(map(self.getName, self.Get('os_device_dev'))) class VariableOsDeviceSize(ReadonlyVariable): @@ -487,12 +476,10 @@ class VariableOsDeviceSize(ReadonlyVariable): def get(self): """Get device size""" - return list(map(lambda x: getPartitionSize(name=x, inBytes=True), - self.Get('os_device_dev'))) + return [getPartitionSize(name=x, inBytes=True) for x in self.Get('os_device_dev')] def humanReadable(self): - return list(map(humanreadableSize, - self.Get())) + return list(map(humanreadableSize, self.Get())) ############################################# @@ -536,8 +523,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable): return list(sorted((x for x in dev_names), key=self.separateDevice)) def humanReadable(self): - return list(map(self.getPerfectName, - self.Get())) + return list(map(self.getPerfectName, self.Get())) class VariableOsDiskMount(DeviceHelper, ReadonlyVariable): @@ -550,8 +536,7 @@ class VariableOsDiskMount(DeviceHelper, ReadonlyVariable): disk_hash = self.Get('os_disk_dev') fstab = FStab('/etc/fstab', devs=disk_hash) rootdev = self.Get('os_root_dev') - return list(map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "", - self.Get('os_disk_dev'))) + return ['/' if x == rootdev else fstab.getBy(eq=x) or "" for x in self.Get('os_disk_dev')] class VariableOsDiskContent(ReadonlyVariable): @@ -564,8 +549,7 @@ class VariableOsDiskContent(ReadonlyVariable): """ TODO: need to write """ - return list(map(lambda x: "", - self.Get('os_disk_dev'))) + return ["" for x in self.Get('os_disk_dev')] class VariableOsDiskFormat(ReadonlyVariable): """ @@ -593,8 +577,7 @@ class VariableOsDiskFormat(ReadonlyVariable): pass return fs - return list(map(getFormat, - self.Get('os_disk_dev'))) + return list(map(getFormat, self.Get('os_disk_dev'))) class VariableOsDiskType(ReadonlyVariable): @@ -608,8 +591,7 @@ class VariableOsDiskType(ReadonlyVariable): def get(self): """Get partition scheme""" - types = list(map(lambda x: (x, device.udev.get_device_type(name=x)), - self.Get('os_disk_dev'))) + types = [(x, device.udev.get_device_type(name=x)) for x in self.Get('os_disk_dev')] lvmUsedDisks = {} raidUsedDisks = {} @@ -642,9 +624,8 @@ class VariableOsDiskType(ReadonlyVariable): lvmUsedDisks[x].append(dev) else: lvmUsedDisks[x] = [dev] - return list(map(lambda x: x[1], - map(forMember, - types))) + + return [x[1] for x in map(forMember, types)] class VariableOsDiskRaid(ReadonlyVariable): @@ -672,8 +653,7 @@ class VariableOsDiskLvm(DeviceHelper, ReadonlyVariable): def get(self): """Get each element from var through udev [prop]""" - return list(map(self.getLvmName, - self.Get('os_disk_dev'))) + return list(map(self.getLvmName, self.Get('os_disk_dev'))) class VariableOsDiskUuid(DeviceHelper, ReadonlyVariable): @@ -723,10 +703,9 @@ class VariableOsDiskId(DeviceHelper, ReadonlyVariable): '21686148-6449-6e6f-744e-656564454649': 'EF02', 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b': 'EF00', '0fc63daf-8483-4772-8e79-3d69d8477de4': '8300'} - return list(map(lambda x: mapTypeUUID.get(x, x), - map(lambda x: x.rpartition("x")[2], - self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE', - '')))) + return [mapTypeUUID.get(x, x) for x + in [y.rpartition("x")[2] for y + in self.mapUdevProperty('os_disk_dev', 'ID_PART_ENTRY_TYPE','')]] class VariableOsDiskGrub(ReadonlyVariable): @@ -786,12 +765,10 @@ class VariableOsDiskSize(ReadonlyVariable): def get(self): """Get disk size""" - return list(map(lambda x: getPartitionSize(name=x, inBytes=True), - self.Get('os_disk_dev'))) + return [getPartitionSize(name=x, inBytes=True) for x in self.Get('os_disk_dev')] def humanReadable(self): - return list(map(humanreadableSize, - self.Get())) + return list(map(humanreadableSize, self.Get())) class VariableOsDiskName(DeviceHelper, ReadonlyVariable): @@ -817,8 +794,7 @@ class VariableOsDiskOptions(ReadonlyVariable): def getFormat(dev): return fstab.getBy(what=fstab.OPTS, eq=dev) - return list(map(getFormat, - self.Get('os_disk_dev'))) + return list(map(getFormat, self.Get('os_disk_dev'))) ################################################ @@ -1045,8 +1021,8 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable): return list(map(normpath, value)) def choice(self): - return list(map(lambda x: (x, self.getPerfectName(x) or x), - self.fixOsDiskDev(self.availDevs(choice=True)))) + [("", "")] + return [(x, self.getPerfectName(x) or x) for x + in self.fixOsDiskDev(self.availDevs(choice=True))] + [("", "")] def fixOsDiskDev(self, sourcelist=None): """ @@ -1085,8 +1061,7 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable): # get original /dev names cnDisks = (device.udev.get_device_info(name=x).get('DEVNAME', x) for x in disks) - wrongDevices = list(set(cnDisks) - - set(self.fixOsDiskDev())) + wrongDevices = list(set(cnDisks) - set(self.fixOsDiskDev())) if wrongDevices: raise VariableError(_("Wrong device '%s'") % wrongDevices[0]) wrongSource = filter(lambda x: x and not x.startswith('/'), value) @@ -1096,8 +1071,7 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable): ########################## # detect duplicate devices ########################## - dupDevices = list(set(filter(lambda x: disks.count(x) > 1, - disks))) + dupDevices = [x for x in disks if disks.count(x) > 1] if dupDevices: raise VariableError( _("Device '%s' is used more than once") % dupDevices[0]) @@ -1141,12 +1115,10 @@ class VariableOsLocationDest(LocationHelper, Variable): return "" return mount - return list(map(installMountPoint, - filter(lambda x: x[0] in source, - list(zip(self.Get('os_disk_dev'), - self.Get('os_disk_mount'))) + \ - list(zip(self.Get('os_bind_path'), - self.Get('os_bind_mountpoint')))))) + return [installMountPoint(x) for x + in list(zip(self.Get('os_disk_dev'),self.Get('os_disk_mount'))) + \ + list(zip(self.Get('os_bind_path'),self.Get('os_bind_mountpoint'))) + if x[0] in source] def set(self, value): """Add abilitiy not specify root""" @@ -1157,7 +1129,7 @@ class VariableOsLocationDest(LocationHelper, Variable): return val value = map(normpath, value) - return list(map(lambda x: x or "/", value)) + return [x or "/" for x in value] def choice(self): if self.Get('cl_install_type') == 'flash': @@ -1189,15 +1161,13 @@ class VariableOsLocationDest(LocationHelper, Variable): ################################ if not source: return - if not list(filter(lambda x: x == "/", value)): + if not [x for x in value if x == "/"]: raise VariableError(_("To install the system, you need to " "specify the root device")) ################################ - disks = list(filter(lambda x: x[0].startswith('/dev/') and x[1], - zip(source, value))) - disksDevs = list(map(lambda x: x[0], disks)) - binds = list(filter(lambda x: not x[0].startswith('/dev/') and x[1], - zip(source, value))) + disks = [x for x in zip(source, value) if x[0].startswith('/dev/') and x[1]] + disksDevs = [x[0] for x in disks] + binds = [x for x in zip(source, value) if not x[0].startswith('/dev/') and x[1]] ########################## # detect efi specifing ########################## @@ -1213,9 +1183,7 @@ class VariableOsLocationDest(LocationHelper, Variable): ########################## # detect duplicate mps ########################## - dupMP = list(set(filter(lambda x: value.count(x) > 1, - filter(lambda x: x and x != "swap", - value)))) + dupMP = list(set([x for x in [y for y in value if y and y != "swap"] if value.count(x) > 1])) if dupMP: raise VariableError( _("Mount point '%s' is used more than once") % dupMP[0]) @@ -1271,10 +1239,9 @@ class VariableOsLocationDest(LocationHelper, Variable): DEVICE, MP = 0, 1 srcMountPoints = map(lambda x: x[DEVICE], binds) destMountPoints = map(lambda x: x[MP], binds) - wrongBind = list(filter(lambda x: x in destMountPoints, srcMountPoints)) + wrongBind = [x for x in srcMountPoints if x in destMountPoints] if wrongBind: - incompBind = list(filter(lambda x: x[1] == wrongBind[0], - zip(srcMountPoints, destMountPoints))) + incompBind = [x for x in zip(srcMountPoints, destMountPoints) if x[1] == wrongBind[0]] raise VariableError( _("Source directory %(src)s is already used " "for binding '%(bindSrc)s' to '%(bindDst)s'") \ @@ -1298,8 +1265,7 @@ class VariableOsLocationDest(LocationHelper, Variable): installTypes = zip(self.Get('os_install_disk_dev'), self.Get('os_install_disk_type')) for checkType in ("raid", "lvm"): - memberData = list(filter(lambda x: checkType + "member" in x[1], - installTypes)) + memberData = [x for x in installTypes if checkType + "member" in x[1]] if memberData: raise VariableError( _("Unable to use {part} partition used by active " @@ -1317,13 +1283,12 @@ class VariableOsLocationFormat(LocationHelper, Variable): def get(self): if self.Get('cl_autopartition_set') == "on": return self.Get('cl_autopartition_disk_format') + \ - list(map(lambda x: "", self.Get('cl_autopartition_bind_path'))) + ["" for x in self.Get('cl_autopartition_bind_path')] else: mount = self.Get("os_location_dest") source = self.Get("os_location_source") value = [""] * len(source) - return list(map(self.defaultFormat(), - zip(source, mount, value))) + return list(map(self.defaultFormat(), zip(source, mount, value))) def choice(self): if self.Get('cl_install_type') == "flash": @@ -1384,8 +1349,7 @@ class VariableOsLocationFormat(LocationHelper, Variable): value = map(lambda x: "vfat" if x == "uefi" else x, value) mount = self.Get("os_location_dest") source = self.Get("os_location_source") - return list(map(self.defaultFormat(), - zip(source, mount, value))) + return list(map(self.defaultFormat(), zip(source, mount, value))) def check(self, value): osInstallRootType = self.Get('os_install_root_type') @@ -1423,17 +1387,14 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): def get(self): if self.Get('cl_autopartition_set') == "on": - return list(map(lambda x: "on", - self.Get('cl_autopartition_disk_format'))) + \ - list(map(lambda x: "", - self.Get('cl_autopartition_bind_path'))) + return ["on" for x in self.Get('cl_autopartition_disk_format')] + \ + ["" for x in self.Get('cl_autopartition_bind_path')] else: mount = self.Get("os_location_dest") source = self.Get("os_location_source") fs = self.Get("os_location_format") value = [""] * len(source) - return list(map(self.defaultPerformFormat(), - zip(source, mount, fs, value))) + return list(map(self.defaultPerformFormat(), zip(source, mount, fs, value))) fixNtfs = lambda self, x: {'ntfs-3g': 'ntfs'}.get(x, x) @@ -1531,11 +1492,9 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): self.Get('os_location_dest'), self.Get('os_location_format'), value) - return list(map(self.defaultPerformFormat(), - map(lambda x: [x[DEV], x[MP], x[FS], ""] \ - if x[FORMAT] == "off" and not x[DEV].startswith("/dev/") - else x, - info))) + return [self.defaultPerformFormat()(x) for x + in [[y[DEV], y[MP], y[FS], ""] + if y[FORMAT] == "off" and not y[DEV].startswith("/dev/") else y for y in info]] class VariableOsLocationSize(LocationHelper, SourceReadonlyVariable): @@ -1678,8 +1637,7 @@ class VariableOsInstallDiskDev(ReadonlyVariable, DeviceHelper): self.Get('os_install_disk_dev_base')) def humanReadable(self): - return list(map(lambda x: self.getPerfectName(x, defaultValue=x), - self.Get())) + return [self.getPerfectName(x, defaultValue=x) for x in self.Get()] class VariableOsInstallDiskUuid(ReadonlyVariable): @@ -1691,7 +1649,7 @@ class VariableOsInstallDiskUuid(ReadonlyVariable): def get(self): diskDev = self.Get('os_install_disk_dev') hashUUID = getUUIDDict(revers=True) - return list(map(lambda x: hashUUID.get(x, "")[5:], diskDev)) + return [hashUUID.get(x, "")[5:] for x in diskDev] class VariableOsInstallDiskPartuuid(ReadonlyVariable): """ @@ -1756,9 +1714,8 @@ class VariableOsInstallDiskUse(ReadonlyVariable): def get(self): """Get real id (by cl_uuid_set) device""" if self.Get('cl_uuid_set') == "on": - return list(map(lambda x: "UUID=%s" % x[0] if x[0] else x[1], - zip(self.Get('os_install_disk_uuid'), - self.Get('os_install_disk_dev')))) + return ["UUID=%s" % x[0] if x[0] else x[1] for x + in zip(self.Get('os_install_disk_uuid'), self.Get('os_install_disk_dev'))] else: return self.Get('os_install_disk_dev') @@ -1820,11 +1777,11 @@ class VariableOsInstallDiskPerformFormat(ReadonlyVariable): type = "bool-list" def get(self): - _format = list(map(lambda x: x[2], - filter(lambda x: x[0].startswith('/dev/') and x[1], - zip(self.Get('os_location_source'), - self.Get('os_location_dest'), - self.Get('os_location_perform_format'))))) + _format = [x[2] for x + in zip(self.Get('os_location_source'), + self.Get('os_location_dest'), + self.Get('os_location_perform_format')) + if x[0].startswith('/dev/') and x[1]] if self.GetBool('cl_autopartition_set'): efiformat = ['on' for x in self.Get('os_install_uefi')] res = efiformat + _format @@ -1880,9 +1837,7 @@ class VariableOsInstallDiskName(Variable): else: return diskLabel.get(dev, '') - return list(map(changeLabel, - self.ZipVars('os_install_disk_dev', - 'os_install_disk_mount'))) + return list(map(changeLabel, self.ZipVars('os_install_disk_dev','os_install_disk_mount'))) class VariableOsInstallDiskSize(SourceReadonlyVariable): @@ -2118,7 +2073,7 @@ class VariableOsInstallUefi(LocationHelper, Variable): return self.select('os_device_efi', os_device_dev=efidev, limit=1) or efidev return efidev - return list(filter(lambda x: x != "off", map(transform, value))) + return [x for x in map(transform, value) if x != "off"] def choice(self): deviceParentMap = self.ZipVars('os_device_dev', @@ -2233,7 +2188,7 @@ class VariableOsInstallMbr(LocationHelper, Variable): def set(self, value): # support off value - return list(filter(lambda x: x != "off", value)) + return [x for x in value if x != "off"] def check(self, value): if self.GetBool('cl_autopartition_set'): diff --git a/pym/install/variables/distr.py b/pym/install/variables/distr.py index f936821..fa1bbc9 100644 --- a/pym/install/variables/distr.py +++ b/pym/install/variables/distr.py @@ -96,8 +96,7 @@ class DistroRepository(Linux): distros = filter(lambda x: x, map(self.reDistName.search, self._getAvailableDistributives(dirs))) - 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): if buf: reOp = re.compile(r"^(!=|=|==|<=|>=|>|<)?(\d+.*)$") @@ -161,18 +160,15 @@ class DistroRepository(Linux): return [pathname] else: # discard inner directories - return list(filter(lambda x: not path.isdir(path.join(pathname, x)), - listDirectory(pathname))) + return [x for x in listDirectory(pathname) if not path.isdir(path.join(pathname, x))] # get lists files in directories allFiles = map(lambda x: map(lambda y: path.join(x, y), listdistr(x)), dirs) # filter distributives - return list(filter(distfilter, - # join files lists to one list - reduce(lambda x, y: x + y, - allFiles, []))) + # join files lists to one list + return [x for x in reduce(lambda x, y: x + y, allFiles, []) if distfilter(x)] def extcomparator(self, *exts): """Compare extensions""" @@ -210,12 +206,10 @@ class DistroRepository(Linux): availDistrs = self._getAvailableDistributives(dirs, system, shortname, march, version, build) - availDistrs = list(filter(lambda x: x[1] and "ext" in x[1] and - not x[1]["ext"] in discardType, - map(lambda x: (x, self._getDistrInfo(x)), - availDistrs))) - return list(map(lambda x: x[0], - sorted(availDistrs, self.sortdistrfunc, reverse=True))) + availDistrs = [x for x + in [(y, self._getDistrInfo(y)) for y in availDistrs] + if x[1] and "ext" in x[1] and not x[1]["ext"] in discardType] + return [x[0] for x in sorted(availDistrs, self.sortdistrfunc, reverse=True)] def getBestDistributive(self, dirs, system=None, shortname=None, march=None, version=None, build=None, discardType=()): @@ -237,7 +231,7 @@ class DistroRepository(Linux): path.join(y, x)), listDirectory(y)), existsdirs, []) - listimgs = list(filter(lambda x: x, listimgs)) + listimgs = [x for x in listimgs if x] if listimgs: return max(listimgs, key=keyfunc).group() return "" @@ -500,21 +494,17 @@ class VariableClImagePath(ReadonlyVariable): livedistr = ['/run/initramfs/squashfs', '/run/initramfs/live', '/mnt/cdrom'] - livedistr = list(filter(listDirectory, - livedistr))[:1] + livedistr = list(filter(listDirectory, livedistr))[:1] else: livedistr = [] # search all partition for source installation distributive rootDev = self.Get('os_install_root_dev') - livedistr += \ - list(map(lambda x: x[0], - filter(lambda x: " live" in x[1] and x[0] != rootDev, - zip(self.Get('os_disk_dev'), - self.Get('os_disk_content'))))) + livedistr = [x[0] for x + in zip(self.Get('os_disk_dev'), self.Get('os_disk_content')) + if " live" in x[1] and x[0] != rootDev] # add to standard path - return list(filter(path.exists, - ['/var/calculate/remote/linux', - '/var/calculate/linux'] + livedistr)) + return list(filter(path.exists, ['/var/calculate/remote/linux', + '/var/calculate/linux'] + livedistr)) class VariableClSource(ReadonlyVariable): diff --git a/pym/install/variables/kernel.py b/pym/install/variables/kernel.py index b36be7a..de9bb1e 100644 --- a/pym/install/variables/kernel.py +++ b/pym/install/variables/kernel.py @@ -224,9 +224,9 @@ class VariableOsInstallKernelScheduleData(ReadonlyTableVariable): 'CONFIG_IOSCHED_NOOP=y': 'noop', 'CONFIG_IOSCHED_CFQ=y': 'cfq', 'CONFIG_IOSCHED_DEADLINE=y': 'deadline'} - installed = list(map(schedulers.get, - filter(lambda x: x in schedulers, - self.Get('os_install_kernel_config')))) or ['cfq'] + installed = [schedulers.get(x) for x + in self.Get('os_install_kernel_config') + if x in schedulers] or ['cfq'] return [[x, "on" if x in installed else "off"] for x in sorted(schedulers.values())] @@ -341,10 +341,10 @@ class KernelHelper(VariableInterface): filesWithType = map(lambda x: (x, ftype(x)), filter(path.exists, filelist)) - return list(filter(lambda x: x[1] and descr in x[1], filesWithType)) + return [x for x in filesWithType if x[1] and descr in x[1]] def getInitrdFiles(self, pathname): - filelist = list(map(lambda x: path.join(pathname, x), os.listdir(pathname))) + filelist = [path.join(pathname, x) for x in os.listdir(pathname)] return [x for x in filelist if path.exists(x) and InitrdFile.is_cpio(x)] def getInitrd(self, arch, shortname, chroot, kernel, suffix="", @@ -372,14 +372,12 @@ class KernelHelper(VariableInterface): bootdir = path.join(chroot, 'boot') initramfsFiles = self.getInitrdFiles(bootdir) - initramfsWithVer = \ - list(filter(lambda x: (kernelVersion in x[1] or - origKernelVer in x[1]) and \ - x[0].endswith(suffix) and \ - ( - not notsuffix or not x[0].endswith(notsuffix)), - map(lambda x: (x, initrd_version_by_name(x)), - initramfsFiles))) + initramfsWithVer = [x for x + in [(y, initrd_version_by_name(y)) for y in initramfsFiles] + if (kernelVersion in x[1] or + origKernelVer in x[1]) and + x[0].endswith(suffix) and + (not notsuffix or not x[0].endswith(notsuffix))] if initramfsWithVer: return path.split(min(initramfsWithVer, key=itemgetter(0))[0])[-1] @@ -397,18 +395,28 @@ class VariableOsInstallKernel(ReadonlyVariable, KernelHelper): validKernel = listDirectory(modulesdir) kernelFiles = self.getFilesByType(bootdir, "Linux kernel") installMarch = self.Get('os_install_arch_machine') - kernelsWithVer = \ - list(map(lambda x: ( - x[0], (getTupleVersion("".join(x[1].groups()[0:3:2])), - path.getmtime(x[0]))), - # convert version to tuple( versionTuple, mtime) - # version detect, for this version lib contains moudules - # kernel arch equal install arch - filter(lambda x: x[1] and x[1].group() in validKernel and - installMarch in x[0].rpartition('/')[2], - # (filename,version) - map(lambda x: (x[0], self.reFindVer.search(x[1])), - kernelFiles)))) + # kernelsWithVer = \ + # list(map(lambda x: ( + # x[0], (getTupleVersion("".join(x[1].groups()[0:3:2])), + # path.getmtime(x[0]))), + # # convert version to tuple( versionTuple, mtime) + # # version detect, for this version lib contains moudules + # # kernel arch equal install arch + # filter(lambda x: x[1] and x[1].group() in validKernel and + # installMarch in x[0].rpartition('/')[2], + # # (filename,version) + # map(lambda x: (x[0], self.reFindVer.search(x[1])), + # kernelFiles)))) + kernelsWithVer = [(x[0], + (getTupleVersion("".join(x[1].groups()[0:3:2])), + path.getmtime(x[0]))) for x + # convert version to tuple( versionTuple, mtime) + # version detect, for this version lib contains moudules + # kernel arch equal install arch + in [y for y + # (filename,version) + in [(z[0], self.reFindVer.search(z[1])) for z in kernelFiles] + if y[1] and y[1].group() in validKernel and installMarch in y[0].rpartition('/')[2]]] if kernelsWithVer: return path.split(max(kernelsWithVer, key=itemgetter(1))[0])[-1] else: @@ -469,9 +477,8 @@ class VariableOsInstallKernelCpufreq(ReadonlyVariable): def get(self): """Get cpufreq (and other from modules_3= param) from conf.d/modules""" - cpufreqmods = list(map(lambda x: x.partition('=')[2].strip("\n '\""), - filter(lambda x: x.startswith('modules_3'), - readLinesFile('/etc/conf.d/modules')))) + cpufreqmods = [x.partition('=')[2].strip("\n '\"") for x + in readLinesFile('/etc/conf.d/modules') if x.startswith('modules_3')] if cpufreqmods: return cpufreqmods[0] else: diff --git a/pym/install/variables/locale.py b/pym/install/variables/locale.py index 9387960..3d3020c 100644 --- a/pym/install/variables/locale.py +++ b/pym/install/variables/locale.py @@ -53,9 +53,8 @@ class VariableOsInstallLinguas(LocaleVariable): def get(self): def get_linguas(lines): - linguas = list(map(lambda x: x.strip().rpartition('=')[-1].strip('"\''), - filter(lambda x: x.startswith("LINGUAS="), - lines))) + linguas = [x.strip().rpartition('=')[-1].strip('"\'') for x + in lines if x.startswith("LINGUAS=")] return linguas[-1] if linguas else "" makeconf = '/etc/make.conf' @@ -337,11 +336,9 @@ class VariableOsInstallClockTimezone(LocaleVariable): try: lang = self.Get(self.locale_varname).split('_')[1] - nativeTZ = list(map(lambda x: x.encode('utf-8'), - country_timezones[lang])) + nativeTZ = [x.encode('utf-8') for x in country_timezones[lang]] source = nativeTZ + ["---"] + \ - sorted(filter(lambda x: not x in nativeTZ, source), - key=sortkey) + sorted([x for x in source if not x in nativeTZ], key=sortkey) except (KeyError, IndexError) as e: pass return list(self.generateComments(source)) diff --git a/pym/install/variables/net.py b/pym/install/variables/net.py index e447d0b..37e4100 100644 --- a/pym/install/variables/net.py +++ b/pym/install/variables/net.py @@ -310,11 +310,9 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable): return "" pciEthernet = lspci(shortInfo=True) - return list(map(lambda x: "{vendor} {name}".format(**x), - map(lambda x: pciEthernet.get(getPci(x), - {'vendor': _("Unknown"), - 'name': _("vendor")}), - self.Get('os_install_net_interfaces')))) + return ["{vendor} {name}".format(**x) for x + in [pciEthernet.get(getPci(y), {'vendor': _("Unknown"), 'name': _("vendor")}) for y + in self.Get('os_install_net_interfaces')]] class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable): @@ -349,8 +347,7 @@ class VariableOsInstallNetMac(NetHelper, ReadonlyVariable): self.label = _("MAC") def get(self): - return list(map(lambda x: getMac(x).lower(), - self.Get('os_install_net_interfaces'))) + return [getMac(x).lower() for x in self.Get('os_install_net_interfaces')] class VariableOsInstallNetStatus(NetHelper, Variable): @@ -363,8 +360,7 @@ class VariableOsInstallNetStatus(NetHelper, Variable): self.label = _("IP address") def get(self): - return list(map(self.getDefaultValue, - self.Get('os_install_net_interfaces'))) + return list(map(self.getDefaultValue, self.Get('os_install_net_interfaces'))) def getDefaultValue(self, iface): def statusValue(ipaddr, dhcp): @@ -389,9 +385,8 @@ class VariableOsInstallNetStatus(NetHelper, Variable): def set(self, value): value = map(lambda x: x.lower() if x else x, value) ifaces = self.Get('os_install_net_interfaces') - return list(map(lambda x: self.getDefaultValue(x[1]) \ - if x[0] == "auto" else x[0], - zip(value, ifaces))) + return [self.getDefaultValue(x[1]) if x[0] == "auto" else x[0] for x + in zip(value, ifaces)] def check(self, value): for status in value: @@ -415,10 +410,10 @@ class VariableOsInstallNetIp(NetHelper, ReadonlyVariable): self.label = _("IP address") def get(self): - return list(map(lambda x: "" if x[1].lower() == "off" else - getIp(x[0]) if x[1].lower() == "dhcp" else x[1], - zip(self.Get('os_install_net_interfaces'), - self.Get('os_install_net_status')))) + return ["" if x[1].lower() == "off" else + getIp(x[0]) if x[1].lower() == "dhcp" else x[1] for x + in zip(self.Get('os_install_net_interfaces'), + self.Get('os_install_net_status'))] # def check(self,value): # dhcps = self.Get('os_install_net_dhcp_set') @@ -439,9 +434,9 @@ class VariableOsInstallNetNetwork(NetHelper, ReadonlyVariable): self.label = _("Network") def get(self): - return list(map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "", - zip(self.Get('os_install_net_ip'), - self.Get('os_install_net_mask')))) + return [getIpNet(x[0], x[1]) if x[0] and x[1] else "" for x + in zip(self.Get('os_install_net_ip'), + self.Get('os_install_net_mask'))] class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable): @@ -457,8 +452,7 @@ class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable): """ Get CIDR of ip,net (Example: 24) """ - return list(map(lambda x: maskToCidr(x) if x else '', - self.Get('os_install_net_mask'))) + return [maskToCidr(x) if x else '' for x in self.Get('os_install_net_mask')] class VariableOsInstallNetMask(NetHelper, Variable): @@ -471,8 +465,8 @@ class VariableOsInstallNetMask(NetHelper, Variable): self.label = _("Mask") def get(self): - return list(map(lambda x: cidrToMask(getMask(x)), - self.Get('os_install_net_interfaces'))) + return [cidrToMask(getMask(x)) for x + in self.Get('os_install_net_interfaces')] def set(self, value): """ @@ -490,9 +484,8 @@ class VariableOsInstallNetMask(NetHelper, Variable): def check(self, value): dhcps = self.Get('os_install_net_status') - wrongMask = list(filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \ - not checkMask(x[0]), - zip(value, dhcps))) + wrongMask = [x for x in zip(value, dhcps) + if (x[0] or not x[1] in ("off", "dhcp")) and not checkMask(x[0])] if wrongMask: raise VariableError(_("Wrong mask %s") % wrongMask[0][0]) @@ -514,8 +507,8 @@ class VariableOsInstallNetDhcpSet(NetHelper, Variable): self.label = _("DHCP") def get(self): - return list(map(lambda x: "on" if x == "dhcp" else "off", - self.Get('os_install_net_status'))) + return ["on" if x == "dhcp" else "off" for x + in self.Get('os_install_net_status')] class VariableOsInstallNetRouteData(NetHelper, TableVariable): @@ -544,19 +537,18 @@ class VariableOsInstallNetRouteData(NetHelper, TableVariable): interfaces = self.Get('os_install_net_interfaces') interfaces_status = self.Get('os_install_net_status') interfaces_network = self.Get('os_install_net_network') - staticInterface = \ - list(map(itemgetter(0, 2), - filter(lambda x: not x[1] in ("off", "dhcp"), - zip(interfaces, interfaces_status, interfaces_network)))) + staticInterface = [itemgetter(0, 2)(x) for x + in zip(interfaces, interfaces_status, interfaces_network) + if not x[1] in ("off", "dhcp")] route_data = [] if staticInterface: staticInterface, skipNet = zip(*staticInterface) - return list(map(lambda x: [x[0], - x[1].get('via', ''), - x[1].get('dev', ''), - x[1].get('src', '')], - filter(lambda x: not x[0] in skipNet, - ip.getRouteTable(staticInterface)))) or [[]] + return [[x[0], + x[1].get('via', ''), + x[1].get('dev', ''), + x[1].get('src', '')] for x + in ip.getRouteTable(staticInterface) + if not x[0] in skipNet] or [[]] return [[]] def getHumanReadableAuto(self): @@ -602,8 +594,7 @@ class VariableOsInstallNetRouteNetwork(NetHelper, FieldValue, Variable): filter("default".__ne__, value)): raise VariableError(_("Wrong network %s") % wrongnet) - dupNetwork = list(set(filter(lambda x: value.count(x) > 1, - value))) + dupNetwork = list(set([x for x in value if value.count(x) > 1])) if dupNetwork: raise VariableError( _("Network '%s' is used more than once") % dupNetwork[0]) @@ -632,13 +623,8 @@ class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable): for wrongip in filterfalse(ip.checkIp, value): raise VariableError(_("Wrong gateway IP %s") % wrongip) - - wrongGws = list(map(lambda x: x[GW], - filter(lambda x: not ip.isIpInNet(x[GW], - *(set(nets) - set( - x[NET]))), - filter(lambda x: x[GW], - netsGw)))) + wrongGws = [x[GW] for x in [y for y in netsGw if y[GW]] + if not ip.isIpInNet(x[GW], *(set(nets) - set(x[NET])))] if wrongGws: raise VariableError(_("Gateways %s are unreachable") % (",".join(wrongGws))) @@ -678,8 +664,7 @@ class VariableOsInstallNetRouteSrc(NetHelper, FieldValue, Variable): filter(None, value)): raise VariableError(_("Wrong source IP %s") % wrongip) ipAddrs = self.Get('os_install_net_ip') - wrongIps = list(filter(lambda x: x and not x in ipAddrs, - value)) + wrongIps = [x for x in value if x and not x in ipAddrs] if wrongIps: raise VariableError( _("Wrong IP address %s in the specified source IP") % @@ -697,14 +682,13 @@ class VariableOsInstallNetRoute(NetHelper, ReadonlyVariable): self.Get('os_install_net_route_dev'), self.Get('os_install_net_route_src')) DEV, IP, CIDR, NET = 0, 1, 2, 1 - return list(map(lambda x: performFunc(x[DEV], x[NET], routeMatrix), - # union ip and mask to ip/net - map(lambda x: (x[DEV], ip.getIpNet(x[IP], cidr=x[CIDR])) \ - if x[IP] and x[CIDR] else (x[DEV], ""), - # filter(lambda x:x[IP] and x[CIDR], - zip(self.Get('os_install_net_interfaces'), + return [performFunc(x[DEV], x[NET], routeMatrix) for x + # ip and mask to ip/net + in [(y[DEV], ip.getIpNet(y[IP], cidr=y[CIDR])) + if y[IP] and y[CIDR] else (y[DEV], "") for y + in zip(self.Get('os_install_net_interfaces'), self.Get('os_install_net_ip'), - self.Get('os_install_net_cidr'))))) + self.Get('os_install_net_cidr'))]] def get(self): """Route info for conf.d/net""" @@ -757,10 +741,8 @@ class VariableOsInstallNetNmroute(VariableOsInstallNetRoute): def getRouteForInterfaceNM(interface, net, routeMatrix): NET, GW, DEV, SRC = 0, 1, 2, 3 - defaultGw = list(map(lambda x: "%s;" % x[GW], - filter(lambda x: interface == x[DEV] and \ - x[NET] == "default", - routeMatrix))) + defaultGw = ["%s;" % x[GW] for x in routeMatrix + if interface == x[DEV] and x[NET] == "default"] return "{0}\n".format(defaultGw[0] if defaultGw else "") + \ "\n".join( # build string for route from net,gateway,dev and src @@ -799,10 +781,8 @@ class VariableOsInstallNetConfAvailable(NetHelper, Variable): with image as distr: try: distrPath = image.getDirectory() - return list(map(itemgetter(0, 2), - filter(lambda x: not x[1] or isPkgInstalled(x[1], - prefix=distrPath), - mapNetConf))) + return [itemgetter(0, 2)(x) for x in mapNetConf + if not x[1] or isPkgInstalled(x[1], prefix=distrPath)] except DistributiveError as e: pass return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1)) @@ -822,10 +802,9 @@ class VariableOsInstallNetConf(NetHelper, Variable): def get(self): """Net setup (networkmanager or openrc)""" - if list(filter(lambda x: x.lower() == "networkmanager", - listDirectory('/etc/runlevels/boot') + - listDirectory('/etc/runlevels/default'))) \ - or self.Get('os_root_type') == "livecd": + if [x for x in listDirectory('/etc/runlevels/boot') + + listDirectory('/etc/runlevels/default') + if x.lower() == "networkmanager"] or self.Get('os_root_type') == "livecd": nm = "networkmanager" else: nm = "" diff --git a/pym/install/variables/system.py b/pym/install/variables/system.py index 8eb9b57..ced9489 100644 --- a/pym/install/variables/system.py +++ b/pym/install/variables/system.py @@ -194,10 +194,9 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable): содержит пустую строку """ def get(self): - rootPasswd = list(map(lambda x: x[1], - filter("root".__eq__, - map(lambda x: x.split(':')[0:2], - readLinesFile('/etc/shadow'))))) + rootPasswd = [x[1] for x + in [y.split(':')[0:2] for y in readLinesFile('/etc/shadow')] + if "root".__eq__(x)] if rootPasswd: rootPasswd = rootPasswd[0] else: @@ -419,7 +418,7 @@ class VariableClMigrateAdmin(UserHelper, Variable): for x in self.Get('cl_migrate_user')] def set(self, value): - return list(map(lambda x: x if x else self.default_value, value)) + return [x if x else self.default_value for x in value] class VariableOsAvailableGroups(ReadonlyVariable): @@ -476,8 +475,7 @@ class VariableClMigrateUserGroups(UserHelper, Variable): yield value def set(self, value): - value = list(map(lambda x: sorted(list(set(self.process_groups(x)))), - value)) + value = [sorted(list(set(self.process_groups(x)))) for x in value] return value def getPrimaryGroup(self, username): @@ -491,11 +489,9 @@ class VariableClMigrateUserGroups(UserHelper, Variable): User groups """ passwdList = getPasswdUsers() - return list(map(lambda x: sorted(self.getPrimaryGroup(x) + - (getUserGroups(x) - if x in passwdList else - self.getDefaultGroups())), - self.Get('cl_migrate_user'))) + return [sorted(self.getPrimaryGroup(x) + (getUserGroups(x) + if x in passwdList else self.getDefaultGroups())) for x + in self.Get('cl_migrate_user')] def choice(self): """ @@ -525,15 +521,13 @@ class VariableClMigrateUserPwd(UserHelper, Variable): if migrateusers: lenData = 9 with open(fileName) as f: - shadowData = list(filter(lambda x: len(x) == lenData, - map(lambda x: x.rstrip().split(":"), f))) - shadowData = list(filter(lambda x: x[0] in migrateusers, shadowData)) - shadowData = list(map(lambda x: (x[0], x[1]), shadowData)) - shadowUsers = list(map(lambda x: x[0], shadowData)) + shadowData = [x for x in [y.rstrip().split(":") for y in f] if len(x) == lenData] + shadowData = [x for x in shadowData if x[0] in migrateusers] + shadowData = [(x[0], x[1]) for x in shadowData] + shadowUsers = [x[0] for x in shadowData] for userName in migrateusers: if userName in shadowUsers: - userData = list(filter(lambda x: x[0] == userName, - shadowData)) + userData = [x for x in shadowData if x[0] == userName] hashPwd = userData[0][1] if (sha256_crypt.identify(hashPwd) and sha256_crypt.verify("guest", hashPwd)): @@ -559,8 +553,7 @@ class VariableClMigrateUserPwd(UserHelper, Variable): """ shadow_hash = get_shadow_hash() - return list(map(lambda x: x if shadow_hash.identify(x) or not x else \ - shadow_hash.hash(x), value)) + return [x if shadow_hash.identify(x) or not x else shadow_hash.hash(x) for x in value] class VariableClAutologin(UserHelper, Variable): @@ -587,8 +580,8 @@ class VariableClAutologin(UserHelper, Variable): if (not cmdDomainSet and self.Get('os_install_root_type') == "livecd") or \ self.Get('os_install_linux_shortname') == "CMC": - nonRootUsers = list(filter(lambda x: x != "root", - self.Get('cl_migrate_user'))) + + nonRootUsers = [x for x in self.Get('cl_migrate_user') if x != "root"] if nonRootUsers: return nonRootUsers[0] else: @@ -716,14 +709,10 @@ class VariableOsNvidiaMask(ReadonlyVariable): category = "0300" vendor = "10de:" lsPciProg = getProgPath("/usr/sbin/lspci") - nvidiacards = list(filter(lambda x: " %s: " % category in x, - process(lsPciProg, "-d", vendor, "-n"))) - cardsid = \ - list(map(lambda x: x.groups()[0], - filter(lambda x: x, - map(lambda x: re.search( - r"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x), - nvidiacards)))) + nvidiacards = [x for x in process(lsPciProg, "-d", vendor, "-n") + if " %s: " % category in x] + cardsid = [x.groups()[0] for x + in [re.search(r"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", y) for y in nvidiacards] if x] if not cardsid: return set() return set(cardsid) @@ -838,9 +827,10 @@ class VariableOsGrub2Path(Variable): return grubInstall # find grub-install and check, that this is grub2-install (ver 1.99) grubInstall = getProgPath('/usr/sbin/grub-install', prefix=chroot_path) - if grubInstall and list(filter(lambda x: "1.99" in x or "2." in x, - process(chroot_cmd, chroot_path, - grubInstall, '--version'))): + + if grubInstall and [x for x + in process(chroot_cmd, chroot_path, grubInstall, '--version') + if "1.99" in x or "2." in x]: return grubInstall return ""