From b1a5dc6e641a4ee0010eddd7a9e9fbb4ad32eb0c Mon Sep 17 00:00:00 2001 From: idziubenko Date: Wed, 14 Jul 2021 11:07:31 +0300 Subject: [PATCH] Py3 changes --- .gitignore | 6 + pym/install/distr.py | 42 +++--- pym/install/variables/X11.py | 12 +- pym/install/variables/audio.py | 10 +- pym/install/variables/autopartition.py | 56 ++++--- pym/install/variables/disk.py | 194 ++++++++++++------------- pym/install/variables/distr.py | 64 ++++---- pym/install/variables/kernel.py | 36 ++--- pym/install/variables/locale.py | 16 +- pym/install/variables/net.py | 96 ++++++------ pym/install/variables/system.py | 60 ++++---- 11 files changed, 305 insertions(+), 287 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35ea017 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +revert_changes_to_vmachine +push_to_vmachine* +.vscode +*.pyc +*.pyo +*.bak \ No newline at end of file diff --git a/pym/install/distr.py b/pym/install/distr.py index 2e1fd53..3ac4d11 100644 --- a/pym/install/distr.py +++ b/pym/install/distr.py @@ -374,9 +374,9 @@ class Distributive(object): joinFrom = partial(path.join, fromdir) params = [cpCmd, "-x"] + \ (["--no-preserve=mode,ownership"] if noperm else ["-a"]) + \ - map(joinFrom, - ifilterfalse(byfile or operator.not_, - listDirectory(fromdir))) + \ + list(map(joinFrom, + filterfalse(byfile or operator.not_, + listDirectory(fromdir)))) + \ [todir] cpProcess = cpProcessProgress(*params, maxfiles=filesnum, stderr=STDOUT) @@ -386,8 +386,8 @@ class Distributive(object): errmes = cpProcess.read() # copy by one file if byfile: - percFiles = filter(byfile, - listDirectory(fromdir)) + percFiles = list(filter(byfile, + listDirectory(fromdir))) if len(percFiles) > 1: maxPercOnFile = 100 / len(percFiles) recountPerc = \ @@ -441,9 +441,9 @@ class Distributive(object): def _getLastLive(self, directory): """Get last live squashfs image from directory""" - squashfiles = filter(lambda x: x, + squashfiles = list(filter(lambda x: x, map(self.reLive.search, - listDirectory(directory))) + listDirectory(directory)))) if squashfiles: return max(squashfiles, key=self._getSquashNum).group() return None @@ -822,27 +822,27 @@ class MultiPartitions: def getSystemId(self): """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): """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): """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): """Get list filesystems ["reiserfs",...]""" - return map(lambda x: x.fileSystem, self.listPartitions) + return list(map(lambda x: x.fileSystem, self.listPartitions)) def getPartitions(self): """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): """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): @@ -1084,8 +1084,8 @@ class PartitionDistributive(Distributive): def postinstallMountBind(self): """Mount bind mount point and create mount dirs""" if self.multipartition and self.DirectoryObject: - mulipartDataBind = filter(lambda x: x[2] == "bind", - self.getMultipartData()) + mulipartDataBind = list(filter(lambda x: x[2] == "bind", + self.getMultipartData())) dirObj = self.DirectoryObject mdirectory = dirObj.directory for srcDir, destDir, fileSystem, isFormat, partTable \ @@ -1166,10 +1166,10 @@ class PartitionDistributive(Distributive): self.multipartition.getMountPoints() + \ ["/"]) # 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( lambda x: x[NEEDFORMAT] and x[FS] != "bind", - dataPartitions)) + dataPartitions))) # if has separate /boot partition bootmp = ["/boot", "/"] purpose_map = {"/boot": "boot", @@ -1194,9 +1194,9 @@ class PartitionDistributive(Distributive): self.formatPartition(dev, format=fileSystem, purpose=purpose_map.get(mp, None)) # change system id for partitions - changeidPartitions = map(lambda x: (x[NEWID], x[DEV], x[PARTTABLE]), + changeidPartitions = list(map(lambda x: (x[NEWID], x[DEV], x[PARTTABLE]), filter(lambda x: x[NEWID], - dataPartitions)) + dataPartitions))) for systemid, dev, partTable in changeidPartitions: self.changeSystemID(dev, systemid, partTable) return True @@ -1495,7 +1495,7 @@ class ContainerDistributive(ArchiveDistributive): if self.exclude: exclude_list = list(calculate_exclude( directory, exclude=self.exclude, include=self.include)) - params += map(lambda x: "--exclude=./%s" % x, exclude_list) + params += list(map(lambda x: "--exclude=./%s" % x, exclude_list)) params += ["."] #debug_file = "/var/calculate/tmp/rootfs.tar.xz" @@ -1880,7 +1880,7 @@ class FlashDistributive(PartitionDistributive): clear_match = re.compile( r"^(boot|efi|isolinux|syslinux|id.*\.uefi|" "ldlinux.c32|ldlinux.sys|livecd|livecd.squashfs)$") - for fn in filter(clear_match.match, listDirectory(dn)): + for fn in list(filter(clear_match.match, listDirectory(dn))): full_path = path.join(dn, fn) try: if path.isdir(full_path): diff --git a/pym/install/variables/X11.py b/pym/install/variables/X11.py index 467b7a9..81f8cf3 100644 --- a/pym/install/variables/X11.py +++ b/pym/install/variables/X11.py @@ -91,8 +91,8 @@ class ResolutionVariable(VideoVariable): "1600x900", "1600x1200", "2048x1152", "2560x1440", "2560x1600"] if self.fbres: - return map(lambda x: "%s-32" % x, - resolutions) + return list(map(lambda x: "%s-32" % x, + resolutions)) else: return resolutions @@ -100,7 +100,7 @@ class ResolutionVariable(VideoVariable): """ 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( _("Wrong resolution {resolution} {example}").format( resolution=value, @@ -183,7 +183,7 @@ class VariableOsInstallX11VideoAvailable(VideoVariable): return [] 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): @@ -220,8 +220,8 @@ class VariableOsInstallX11VideoDrv(VideoVariable): values = self.Get('os_install_x11_video_available') else: values = self.nox_video_drivers() - return map(lambda x: (x, self.driver_names.get(x, x)), - (x for x in self.driver_names.keys() if x in values)) + return list(map(lambda x: (x, self.driver_names.get(x, x)), + (x for x in self.driver_names.keys() if x 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 4305b1f..74013c9 100644 --- a/pym/install/variables/audio.py +++ b/pym/install/variables/audio.py @@ -88,10 +88,10 @@ class VariableOsAudioAvailable(Variable): with image as distr: try: 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], prefix=distrPath), - mapAudioConf)) + mapAudioConf))) except DistributiveError as e: pass return sorted(map(lambda x: x[0::2], mapAudioConf[-1:]), @@ -134,7 +134,7 @@ class VariableOsAudioData(ReadonlyTableVariable): def get(self, hr=HumanReadable.No): # /proc/asound/card*/pcm*p/info 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) if cards: return list(self.generate_cards(cards)) @@ -211,12 +211,12 @@ class VariableOsAudioHw(Variable): def get_deprecated(self): 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) if entry and entry.groups()[0] in self.Get('os_audio_id'): return "%s,0" % entry.groups()[0] 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) if entry: entry = "%s,%s" % entry.groups() diff --git a/pym/install/variables/autopartition.py b/pym/install/variables/autopartition.py index fac2d62..dcd2f06 100644 --- a/pym/install/variables/autopartition.py +++ b/pym/install/variables/autopartition.py @@ -43,16 +43,16 @@ class SizeHelper(VariableInterface): def set(self, value): # convert table from value to MB - sizeMap = {'kB': Sizes.kB, - 'K': Sizes.K, - 'M': Sizes.M, - 'Mb': Sizes.Mb, - 'G': Sizes.G, - 'Gb': Sizes.Gb, - 'T': Sizes.T, - 'Tb': Sizes.Tb} + sizeMap = {r'kB': Sizes.kB, + r'K': Sizes.K, + r'M': Sizes.M, + r'Mb': Sizes.Mb, + r'G': Sizes.G, + r'Gb': Sizes.Gb, + r'T': Sizes.T, + r'Tb': Sizes.Tb} 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) if not res: return "0" @@ -98,9 +98,9 @@ class VariableHrMemorySize(ReadonlyVariable): def get(self): reMemTotal = re.compile(r'^MemTotal:\s*(\d+)\s*kB$') - totalMemList = filter(lambda x: x, + totalMemList = list(filter(lambda x: x, map(reMemTotal.search, - readLinesFile('/proc/meminfo'))) + readLinesFile('/proc/meminfo')))) if totalMemList: size = int(totalMemList[0].group(1)) * Sizes.K return str(size) @@ -149,7 +149,7 @@ class VariableClAutopartitionDeviceData(ReadonlyTableVariable): 'cl_autopartition_device_size', '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 generator(): @@ -212,7 +212,7 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): self.label = _("Devices for install") 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'], where='os_device_dev', _in=choiceVal) notFlashDevices = [x[0] for x in devicesTypes if x[1] != 'flash'] @@ -255,8 +255,8 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): def checkOnRaid(self, valuelist): disks = self.Select('os_disk_dev', where='os_disk_parent', _in=valuelist) - raids = filter(None, self.Select('os_disk_raid', - where='os_disk_dev', _in=disks)) + raids = list(filter(None, self.Select('os_disk_raid', + where='os_disk_dev', _in=disks))) raidDisks = self.Select('os_disk_dev', where='os_disk_raid', _in=raids) raidDevices = self.Select('os_disk_parent', where='os_disk_dev', @@ -288,7 +288,7 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): """ Проверить схемы RAID, чтобы исключить базирование их на lvm """ - typecheck = re.compile("lvm.*raid") + typecheck = re.compile(r"lvm.*raid") for dev, fulltype in self.ZipVars("os_device_dev", "os_device_fulltype"): if dev in valuelist: @@ -689,17 +689,29 @@ class VariableClAutopartitionLvmVgname(Variable): """ def get(self): + # def generateName(startName): + # yield startName + # for i in count(20): + # yield "%s%d" % (startName, i) + + # instead this just so there won't be an infinite loop def generateName(startName): yield startName - for i in count(20): + for i in range(20, 1000): yield "%s%d" % (startName, i) - + + for name in generateName("calculate"): + disks = self.Select('os_lvm_pvname', where='os_lvm_vgname', eq=name) devices = self.Select('os_disk_parent', where='os_disk_dev', _in=disks) + if set(devices) <= set(self.Get('cl_autopartition_device')): return name + + #TODO should replace this + raise Exception class VariableClAutopartitionDiskData(ReadonlyTableVariable): @@ -772,10 +784,10 @@ class VariableClAutopartitionDiskSize(DiskFilter, ReadonlyVariable): field = "disk_size" def get(self): - return map(str, super(VariableClAutopartitionDiskSize, self).get()) + return list(map(str, super(VariableClAutopartitionDiskSize, self).get())) def humanReadable(self): - return map(humanreadableSize, self.Get()) + return list(map(humanreadableSize, self.Get())) class VariableClAutopartitionDiskDataFull(ReadonlyTableVariable): @@ -864,10 +876,10 @@ class VariableClAutopartitionDiskSizeFull(ReadonlyVariable): def get(self): 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): - return map(humanreadableSize, self.Get()) + return list(map(humanreadableSize, self.Get())) class VariableClAutopartitionRaid(ReadonlyVariable): diff --git a/pym/install/variables/disk.py b/pym/install/variables/disk.py index b7efc00..0ca7cbf 100644 --- a/pym/install/variables/disk.py +++ b/pym/install/variables/disk.py @@ -45,13 +45,13 @@ setLocalTranslate('cl_install3', sys.modules[__name__]) class DeviceHelper(VariableInterface): - rePassDevice = re.compile("^/block/(?!%s)" % "|".join(['sr', 'fd', - 'ram', 'loop'])) + rePassDevice = re.compile(r"^/block/(?!%s)" % r"|".join([r'sr', r'fd', + r'ram', r'loop'])) def getBlockDevices(self): """Get interest devices from sys block path""" - return 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 +59,8 @@ class DeviceHelper(VariableInterface): Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1) """ - return map(lambda x: int(x) if x.isdigit() else x, - re.findall('\d+|\D+', dev)) + return list(map(lambda x: int(x) if x.isdigit() else x, + re.findall(r'\d+|\D+', dev))) def mapUdevProperty(self, var, prop, default): """Get each element from var through udev [prop]""" @@ -164,7 +164,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable): Disk devices """ 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): pass @@ -228,8 +228,8 @@ class VariableOsDeviceType(ReadonlyVariable): device.devfs.listdir(diskIdPath, fullpath=False))) else: self.usbdevices = [] - return map(self.getType, - self.Get('os_device_dev')) + return list(map(self.getType, + self.Get('os_device_dev'))) class VariableOsDeviceParent(ReadonlyVariable): @@ -313,8 +313,8 @@ class VariableOsDeviceMap(ReadonlyVariable): type = "list" def get(self): - return map(lambda x: str(x[0]), - enumerate(self.Get('os_device_dev'))) + return list(map(lambda x: str(x[0]), + enumerate(self.Get('os_device_dev')))) class VariableOsDeviceArraySet(ReadonlyVariable): @@ -334,9 +334,9 @@ class VariableOsDeviceArraySet(ReadonlyVariable): else: return "off" - return map(lambda x: isArray(*x), + return list(map(lambda x: isArray(*x), zip(self.Get('os_device_dev'), - self.Get('os_device_name'))) + self.Get('os_device_name')))) class VariableOsDeviceSsdSet(ReadonlyVariable): @@ -361,9 +361,9 @@ class VariableOsDeviceSsdSet(ReadonlyVariable): else: return "off" - return map(lambda x: isSsd(*x), + return list(map(lambda x: isSsd(*x), zip(self.Get('os_device_dev'), - self.Get('os_device_name'))) + self.Get('os_device_name')))) class VariableOsDeviceSyspath(ReadonlyVariable): @@ -403,10 +403,10 @@ class VariableOsDeviceVirtualSet(ReadonlyVariable): else: return "off" - return map(lambda x: isVirtual(*x), + return list(map(lambda x: isVirtual(*x), zip(self.Get('os_device_dev'), self.Get('os_device_name'), - self.Get('os_device_syspath'))) + self.Get('os_device_syspath')))) class VariableOsDeviceTable(ReadonlyVariable): @@ -444,8 +444,8 @@ class VariableOsDeviceTable(ReadonlyVariable): else: return getTable(dev) - return map(getByAutopartition, - self.Get('os_device_dev')) + return list(map(getByAutopartition, + self.Get('os_device_dev'))) class VariableOsDeviceName(ReadonlyVariable): @@ -475,8 +475,8 @@ class VariableOsDeviceName(ReadonlyVariable): return "" def get(self): - return map(self.getName, - self.Get('os_device_dev')) + return list(map(self.getName, + self.Get('os_device_dev'))) class VariableOsDeviceSize(ReadonlyVariable): @@ -487,12 +487,12 @@ class VariableOsDeviceSize(ReadonlyVariable): def get(self): """Get device size""" - return map(lambda x: getPartitionSize(name=x, inBytes=True), - self.Get('os_device_dev')) + return list(map(lambda x: getPartitionSize(name=x, inBytes=True), + self.Get('os_device_dev'))) def humanReadable(self): - return map(humanreadableSize, - self.Get()) + return list(map(humanreadableSize, + self.Get())) ############################################# @@ -526,7 +526,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable): def get(self): # получить блочные утсройства, в списке устройства с таблицей раздела # разделены '/' - re_parent = re.compile("^/block/[^/]+") + re_parent = re.compile(r"^/block/[^/]+") disks = self.getBlockDevices() parents = {re_parent.search(x).group() 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)) def humanReadable(self): - return map(self.getPerfectName, - self.Get()) + return list(map(self.getPerfectName, + self.Get())) class VariableOsDiskMount(DeviceHelper, ReadonlyVariable): @@ -550,8 +550,8 @@ class VariableOsDiskMount(DeviceHelper, ReadonlyVariable): disk_hash = self.Get('os_disk_dev') fstab = FStab('/etc/fstab', devs=disk_hash) rootdev = self.Get('os_root_dev') - return map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "", - self.Get('os_disk_dev')) + return list(map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "", + self.Get('os_disk_dev'))) class VariableOsDiskContent(ReadonlyVariable): @@ -564,8 +564,8 @@ class VariableOsDiskContent(ReadonlyVariable): """ TODO: need to write """ - return map(lambda x: "", - self.Get('os_disk_dev')) + return list(map(lambda x: "", + self.Get('os_disk_dev'))) class VariableOsDiskFormat(ReadonlyVariable): """ @@ -593,8 +593,8 @@ class VariableOsDiskFormat(ReadonlyVariable): pass return fs - return map(getFormat, - self.Get('os_disk_dev')) + return list(map(getFormat, + self.Get('os_disk_dev'))) class VariableOsDiskType(ReadonlyVariable): @@ -602,8 +602,8 @@ class VariableOsDiskType(ReadonlyVariable): List type (lvm,raid,partition,disk) """ type = "list" - re_raid = re.compile("-raid\d+$") - re_raid_partition = re.compile("-raid\d+-partition$") + re_raid = re.compile(r"-raid\d+$") + re_raid_partition = re.compile(r"-raid\d+-partition$") def get(self): """Get partition scheme""" @@ -642,9 +642,9 @@ class VariableOsDiskType(ReadonlyVariable): lvmUsedDisks[x].append(dev) else: lvmUsedDisks[x] = [dev] - return map(lambda x: x[1], + return list(map(lambda x: x[1], map(forMember, - types)) + types))) class VariableOsDiskRaid(ReadonlyVariable): @@ -672,8 +672,8 @@ class VariableOsDiskLvm(DeviceHelper, ReadonlyVariable): def get(self): """Get each element from var through udev [prop]""" - return map(self.getLvmName, - self.Get('os_disk_dev')) + return list(map(self.getLvmName, + self.Get('os_disk_dev'))) class VariableOsDiskUuid(DeviceHelper, ReadonlyVariable): @@ -723,10 +723,10 @@ class VariableOsDiskId(DeviceHelper, ReadonlyVariable): '21686148-6449-6e6f-744e-656564454649': 'EF02', 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b': 'EF00', '0fc63daf-8483-4772-8e79-3d69d8477de4': '8300'} - return map(lambda x: mapTypeUUID.get(x, x), + 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', - ''))) + '')))) class VariableOsDiskGrub(ReadonlyVariable): @@ -753,10 +753,10 @@ class VariableOsDiskGrub(ReadonlyVariable): else: return "" - return map(getGrubMap, + return list(map(getGrubMap, zip(self.Get('os_disk_dev'), self.Get('os_disk_type'), - self.Get('os_disk_parent'))) + self.Get('os_disk_parent')))) class VariableOsDiskPart(ReadonlyVariable): @@ -786,12 +786,12 @@ class VariableOsDiskSize(ReadonlyVariable): def get(self): """Get disk size""" - return map(lambda x: getPartitionSize(name=x, inBytes=True), - self.Get('os_disk_dev')) + return list(map(lambda x: getPartitionSize(name=x, inBytes=True), + self.Get('os_disk_dev'))) def humanReadable(self): - return map(humanreadableSize, - self.Get()) + return list(map(humanreadableSize, + self.Get())) class VariableOsDiskName(DeviceHelper, ReadonlyVariable): @@ -817,8 +817,8 @@ class VariableOsDiskOptions(ReadonlyVariable): def getFormat(dev): return fstab.getBy(what=fstab.OPTS, eq=dev) - return map(getFormat, - self.Get('os_disk_dev')) + return list(map(getFormat, + self.Get('os_disk_dev'))) ################################################ @@ -1042,11 +1042,11 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable): return path.normpath(val) return val - return map(normpath, value) + return list(map(normpath, value)) def choice(self): - return map(lambda x: (x, self.getPerfectName(x) or x), - self.fixOsDiskDev(self.availDevs(choice=True))) + [("", "")] + return list(map(lambda x: (x, self.getPerfectName(x) or x), + self.fixOsDiskDev(self.availDevs(choice=True)))) + [("", "")] def fixOsDiskDev(self, sourcelist=None): """ @@ -1141,12 +1141,12 @@ class VariableOsLocationDest(LocationHelper, Variable): return "" return mount - return map(installMountPoint, + return list(map(installMountPoint, filter(lambda x: x[0] in source, - zip(self.Get('os_disk_dev'), - self.Get('os_disk_mount')) + \ - zip(self.Get('os_bind_path'), - self.Get('os_bind_mountpoint')))) + list(zip(self.Get('os_disk_dev'), + self.Get('os_disk_mount'))) + \ + list(zip(self.Get('os_bind_path'), + self.Get('os_bind_mountpoint')))))) def set(self, value): """Add abilitiy not specify root""" @@ -1157,7 +1157,7 @@ class VariableOsLocationDest(LocationHelper, Variable): return val value = map(normpath, value) - return map(lambda x: x or "/", value) + return list(map(lambda x: x or "/", value)) def choice(self): if self.Get('cl_install_type') == 'flash': @@ -1179,7 +1179,7 @@ class VariableOsLocationDest(LocationHelper, Variable): not "/usr" in value: for mp, size in filter(lambda x: x[0] == '/' and x[1].isdigit() and \ int(x[1]) < minroot, - izip(value, + zip(value, self.Get("os_location_size"))): raise VariableError( _("The root partition should be at least %s") % "7 Gb") @@ -1189,19 +1189,19 @@ class VariableOsLocationDest(LocationHelper, Variable): ################################ if not source: 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 " "specify the root device")) ################################ - disks = filter(lambda x: x[0].startswith('/dev/') and x[1], - zip(source, value)) - disksDevs = map(lambda x: x[0], disks) - binds = filter(lambda x: not x[0].startswith('/dev/') and x[1], - zip(source, value)) + disks = 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))) ########################## # 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 self.Get('cl_client_type') == 'gui': raise VariableError( @@ -1271,10 +1271,10 @@ class VariableOsLocationDest(LocationHelper, Variable): DEVICE, MP = 0, 1 srcMountPoints = map(lambda x: x[DEVICE], binds) destMountPoints = map(lambda x: x[MP], binds) - wrongBind = filter(lambda x: x in destMountPoints, srcMountPoints) + wrongBind = list(filter(lambda x: x in destMountPoints, srcMountPoints)) if wrongBind: - incompBind = filter(lambda x: x[1] == wrongBind[0], - zip(srcMountPoints, destMountPoints)) + incompBind = list(filter(lambda x: x[1] == wrongBind[0], + zip(srcMountPoints, destMountPoints))) raise VariableError( _("Source directory %(src)s is already used " "for binding '%(bindSrc)s' to '%(bindDst)s'") \ @@ -1298,8 +1298,8 @@ class VariableOsLocationDest(LocationHelper, Variable): installTypes = zip(self.Get('os_install_disk_dev'), self.Get('os_install_disk_type')) for checkType in ("raid", "lvm"): - memberData = filter(lambda x: checkType + "member" in x[1], - installTypes) + memberData = list(filter(lambda x: checkType + "member" in x[1], + installTypes)) if memberData: raise VariableError( _("Unable to use {part} partition used by active " @@ -1317,13 +1317,13 @@ class VariableOsLocationFormat(LocationHelper, Variable): def get(self): if self.Get('cl_autopartition_set') == "on": return self.Get('cl_autopartition_disk_format') + \ - map(lambda x: "", self.Get('cl_autopartition_bind_path')) + list(map(lambda x: "", self.Get('cl_autopartition_bind_path'))) else: mount = self.Get("os_location_dest") source = self.Get("os_location_source") value = [""] * len(source) - return map(self.defaultFormat(), - zip(source, mount, value)) + return list(map(self.defaultFormat(), + zip(source, mount, value))) def choice(self): 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) mount = self.Get("os_location_dest") source = self.Get("os_location_source") - return 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 +1423,17 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): def get(self): if self.Get('cl_autopartition_set') == "on": - return map(lambda x: "on", - self.Get('cl_autopartition_disk_format')) + \ - map(lambda x: "", - self.Get('cl_autopartition_bind_path')) + return list(map(lambda x: "on", + self.Get('cl_autopartition_disk_format'))) + \ + list(map(lambda x: "", + self.Get('cl_autopartition_bind_path'))) else: mount = self.Get("os_location_dest") source = self.Get("os_location_source") fs = self.Get("os_location_format") value = [""] * len(source) - return map(self.defaultPerformFormat(), - zip(source, mount, fs, value)) + return list(map(self.defaultPerformFormat(), + zip(source, mount, fs, value))) 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_format'), value) - return map(self.defaultPerformFormat(), + 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)) + info))) class VariableOsLocationSize(LocationHelper, SourceReadonlyVariable): @@ -1678,8 +1678,8 @@ class VariableOsInstallDiskDev(ReadonlyVariable, DeviceHelper): self.Get('os_install_disk_dev_base')) def humanReadable(self): - return map(lambda x: self.getPerfectName(x, defaultValue=x), - self.Get()) + return list(map(lambda x: self.getPerfectName(x, defaultValue=x), + self.Get())) class VariableOsInstallDiskUuid(ReadonlyVariable): @@ -1691,7 +1691,7 @@ class VariableOsInstallDiskUuid(ReadonlyVariable): def get(self): diskDev = self.Get('os_install_disk_dev') hashUUID = getUUIDDict(revers=True) - return map(lambda x: hashUUID.get(x, "")[5:], diskDev) + return list(map(lambda x: hashUUID.get(x, "")[5:], diskDev)) class VariableOsInstallDiskPartuuid(ReadonlyVariable): """ @@ -1756,9 +1756,9 @@ class VariableOsInstallDiskUse(ReadonlyVariable): def get(self): """Get real id (by cl_uuid_set) device""" if self.Get('cl_uuid_set') == "on": - return map(lambda x: "UUID=%s" % x[0] if x[0] else x[1], + 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'))) + self.Get('os_install_disk_dev')))) else: return self.Get('os_install_disk_dev') @@ -1820,11 +1820,11 @@ class VariableOsInstallDiskPerformFormat(ReadonlyVariable): type = "bool-list" 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], zip(self.Get('os_location_source'), self.Get('os_location_dest'), - self.Get('os_location_perform_format')))) + self.Get('os_location_perform_format'))))) if self.GetBool('cl_autopartition_set'): efiformat = ['on' for x in self.Get('os_install_uefi')] res = efiformat + _format @@ -1880,9 +1880,9 @@ class VariableOsInstallDiskName(Variable): else: return diskLabel.get(dev, '') - return map(changeLabel, + return list(map(changeLabel, self.ZipVars('os_install_disk_dev', - 'os_install_disk_mount')) + 'os_install_disk_mount'))) class VariableOsInstallDiskSize(SourceReadonlyVariable): @@ -2058,7 +2058,7 @@ class VariableOsInstallUefi(LocationHelper, Variable): opt = ["--uefi"] metavalue = "EFI" - re_not0_raid = re.compile("-raid[1-9]") + re_not0_raid = re.compile(r"-raid[1-9]") def init(self): self.label = _("UEFI boot") @@ -2118,7 +2118,7 @@ class VariableOsInstallUefi(LocationHelper, Variable): return self.select('os_device_efi', os_device_dev=efidev, limit=1) or efidev return efidev - return filter(lambda x: x != "off", map(transform, value)) + return list(filter(lambda x: x != "off", map(transform, value))) def choice(self): deviceParentMap = self.ZipVars('os_device_dev', @@ -2233,7 +2233,7 @@ class VariableOsInstallMbr(LocationHelper, Variable): def set(self, value): # support off value - return filter(lambda x: x != "off", value) + return list(filter(lambda x: x != "off", value)) 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 1e7e5dc..f936821 100644 --- a/pym/install/variables/distr.py +++ b/pym/install/variables/distr.py @@ -42,21 +42,21 @@ setLocalTranslate('cl_install3', sys.modules[__name__]) class DistroRepository(Linux): 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%(name)s) -(?P%(ver)s) (?:-(?P%(ser)s))? -(?P%(march)s) .(?P%(ext)s)$""" % - {'name': "[a-z0-9]+", - 'ver': r"(\d+\.)*\d+", - 'ser': r"\d+", - 'march': "|".join(marches), - 'ext': "|".join(extensiton) + {r'name': r"[a-z0-9]+", + r'ver': r"(\d+\.)*\d+", + r'ser': r"\d+", + r'march': r"|".join(marches), + r'ext': r"|".join(extensiton) }, re.X) def _getDistrInfo(self, filename): @@ -71,9 +71,9 @@ class DistroRepository(Linux): distdic = match.groupdict() distdic["os_linux_build"] = "" if "os_linux_ver" in distdic: - if re.match("^\d{8}$", distdic["os_linux_ver"]): - distdic["os_linux_build"] = distdic["os_linux_ver"] - distdic["os_linux_ver"] = "" + if re.match(r"^\d{8}$", distdic["os_linux_ver"]): + distdic[r"os_linux_build"] = distdic["os_linux_ver"] + distdic[r"os_linux_ver"] = "" return distdic def getImage(self, scratch, rootType, imagePath, march=None, @@ -100,7 +100,7 @@ class DistroRepository(Linux): def opcompareByString(self, buf): if buf: - reOp = re.compile("^(!=|=|==|<=|>=|>|<)?(\d+.*)$") + reOp = re.compile(r"^(!=|=|==|<=|>=|>|<)?(\d+.*)$") res = reOp.search(buf) if res: return ({'!=': operator.ne, @@ -161,18 +161,18 @@ class DistroRepository(Linux): return [pathname] else: # discard inner directories - return filter(lambda x: not path.isdir(path.join(pathname, x)), - listDirectory(pathname)) + return list(filter(lambda x: not path.isdir(path.join(pathname, x)), + listDirectory(pathname))) # get lists files in directories allFiles = map(lambda x: map(lambda y: path.join(x, y), listdistr(x)), dirs) # filter distributives - return filter(distfilter, + return list(filter(distfilter, # join files lists to one list reduce(lambda x, y: x + y, - allFiles, [])) + allFiles, []))) def extcomparator(self, *exts): """Compare extensions""" @@ -210,12 +210,12 @@ class DistroRepository(Linux): availDistrs = self._getAvailableDistributives(dirs, system, shortname, march, version, 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, map(lambda x: (x, self._getDistrInfo(x)), - availDistrs)) - return map(lambda x: x[0], - sorted(availDistrs, self.sortdistrfunc, reverse=True)) + availDistrs))) + return list(map(lambda x: x[0], + sorted(availDistrs, self.sortdistrfunc, reverse=True))) def getBestDistributive(self, dirs, system=None, shortname=None, march=None, version=None, build=None, discardType=()): @@ -237,7 +237,7 @@ class DistroRepository(Linux): path.join(y, x)), listDirectory(y)), existsdirs, []) - listimgs = filter(lambda x: x, listimgs) + listimgs = list(filter(lambda x: x, listimgs)) if listimgs: return max(listimgs, key=keyfunc).group() return "" @@ -245,15 +245,15 @@ class DistroRepository(Linux): def getBestStage(self, dirs, march=None, hardened=None): """Get latest stage by march""" if march: - march = {'x86_64': 'amd64'}.get(march, march) + march = {r'x86_64': r'amd64'}.get(march, march) else: - march = "[^-]+" + march = r"[^-]+" if hardened is None: - hardened = "(?:-hardened)?" + hardened = r"(?:-hardened)?" elif hardened is True: - hardened = "-hardened" + hardened = r"-hardened" elif hardened is False: - hardened = "" + hardened = r"" reStage = re.compile(r'^.*/stage3-%s%s-(\d+)\.tar\.bz2$' % (march, hardened), re.S) return self._findLatestFile(dirs, reStage, lambda x: x.groups()[0]) @@ -500,21 +500,21 @@ class VariableClImagePath(ReadonlyVariable): livedistr = ['/run/initramfs/squashfs', '/run/initramfs/live', '/mnt/cdrom'] - livedistr = 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 += \ - map(lambda x: x[0], + 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')))) + self.Get('os_disk_content'))))) # add to standard path - return filter(path.exists, + return list(filter(path.exists, ['/var/calculate/remote/linux', - '/var/calculate/linux'] + livedistr) + '/var/calculate/linux'] + livedistr)) class VariableClSource(ReadonlyVariable): diff --git a/pym/install/variables/kernel.py b/pym/install/variables/kernel.py index 4f7ab6f..b36be7a 100644 --- a/pym/install/variables/kernel.py +++ b/pym/install/variables/kernel.py @@ -142,10 +142,10 @@ class VariableOsInstallKernelConfig(ReadonlyVariable): makefile_path = path.join(distr_path, kernel_src, "Makefile") # get version from Makefile - re_makefile = re.compile("^VERSION = (\S+)\n" - "PATCHLEVEL = (\S+)\n" - "SUBLEVEL = (\S+)\n" - "EXTRAVERSION = (\S*)\n", re.M) + re_makefile = re.compile(r"^VERSION = (\S+)\n" + r"PATCHLEVEL = (\S+)\n" + r"SUBLEVEL = (\S+)\n" + r"EXTRAVERSION = (\S*)\n", re.M) if path.exists(makefile_path): with open(makefile_path) as f: match = re_makefile.search(f.read(200)) @@ -224,9 +224,9 @@ class VariableOsInstallKernelScheduleData(ReadonlyTableVariable): 'CONFIG_IOSCHED_NOOP=y': 'noop', 'CONFIG_IOSCHED_CFQ=y': 'cfq', 'CONFIG_IOSCHED_DEADLINE=y': 'deadline'} - installed = map(schedulers.get, + installed = list(map(schedulers.get, 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"] for x in sorted(schedulers.values())] @@ -332,7 +332,7 @@ class KernelHelper(VariableInterface): Helper for kernel variables """ reFindVer = re.compile( - "(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)") + r"(?<=version )(\d+\.?\d*\.?\d*\.?\d*)([^\d* ])*(\d*)") def getFilesByType(self, pathname, descr): """Get files from "pathname" has "descr" in descriptions""" @@ -341,16 +341,16 @@ class KernelHelper(VariableInterface): filesWithType = map(lambda x: (x, ftype(x)), filter(path.exists, 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): - 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)] def getInitrd(self, arch, shortname, chroot, kernel, suffix="", notsuffix=""): """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): resInitrdVer = reInitrdVer.search(filename) @@ -373,13 +373,13 @@ class KernelHelper(VariableInterface): bootdir = path.join(chroot, 'boot') initramfsFiles = self.getInitrdFiles(bootdir) initramfsWithVer = \ - filter(lambda x: (kernelVersion in x[1] or + 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)) + initramfsFiles))) if initramfsWithVer: return path.split(min(initramfsWithVer, key=itemgetter(0))[0])[-1] @@ -398,17 +398,17 @@ class VariableOsInstallKernel(ReadonlyVariable, KernelHelper): kernelFiles = self.getFilesByType(bootdir, "Linux kernel") installMarch = self.Get('os_install_arch_machine') kernelsWithVer = \ - map(lambda x: ( + 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 - 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], # (filename,version) - imap(lambda x: (x[0], self.reFindVer.search(x[1])), - kernelFiles))) + map(lambda x: (x[0], self.reFindVer.search(x[1])), + kernelFiles)))) if kernelsWithVer: return path.split(max(kernelsWithVer, key=itemgetter(1))[0])[-1] else: @@ -469,9 +469,9 @@ class VariableOsInstallKernelCpufreq(ReadonlyVariable): def get(self): """Get cpufreq (and other from modules_3= param) from conf.d/modules""" - cpufreqmods = map(lambda x: x.partition('=')[2].strip("\n '\""), + cpufreqmods = list(map(lambda x: x.partition('=')[2].strip("\n '\""), filter(lambda x: x.startswith('modules_3'), - readLinesFile('/etc/conf.d/modules'))) + readLinesFile('/etc/conf.d/modules')))) if cpufreqmods: return cpufreqmods[0] else: diff --git a/pym/install/variables/locale.py b/pym/install/variables/locale.py index 08b654e..9387960 100644 --- a/pym/install/variables/locale.py +++ b/pym/install/variables/locale.py @@ -53,9 +53,9 @@ class VariableOsInstallLinguas(LocaleVariable): def get(self): 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="), - lines)) + lines))) return linguas[-1] if linguas else "" makeconf = '/etc/make.conf' @@ -137,8 +137,8 @@ class VariableOsInstallLocaleLang(LocaleVariable): return self.Get('os_locale_lang') def choice(self): - return zip(self.Get('os_lang'), - map(str, self.Get('os_lang', humanreadable=True))) + return list(zip(self.Get('os_lang'), + map(str, self.Get('os_lang', humanreadable=True)))) class VariableOsInstallLocaleKeyboardLayout(LocaleVariable): @@ -164,8 +164,8 @@ class VariableOsInstallLocaleKeyboardLayout(LocaleVariable): return self.Get('os_locale_keyboard_layout') def choice(self): - return zip(self.Get('os_keyboard_layout'), - map(str, self.Get('os_keyboard_layout', humanreadable=True))) + return list(zip(self.Get('os_keyboard_layout'), + map(str, self.Get('os_keyboard_layout', humanreadable=True)))) class VariableOsInstallLocaleLanguage(LocaleVariable): @@ -337,8 +337,8 @@ class VariableOsInstallClockTimezone(LocaleVariable): try: lang = self.Get(self.locale_varname).split('_')[1] - nativeTZ = map(lambda x: x.encode('utf-8'), - country_timezones[lang]) + nativeTZ = list(map(lambda x: x.encode('utf-8'), + country_timezones[lang])) source = nativeTZ + ["---"] + \ sorted(filter(lambda x: not x in nativeTZ, source), key=sortkey) diff --git a/pym/install/variables/net.py b/pym/install/variables/net.py index a310c9d..e447d0b 100644 --- a/pym/install/variables/net.py +++ b/pym/install/variables/net.py @@ -310,11 +310,11 @@ class VariableOsInstallNetName(NetHelper, ReadonlyVariable): return "" 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), {'vendor': _("Unknown"), 'name': _("vendor")}), - self.Get('os_install_net_interfaces'))) + self.Get('os_install_net_interfaces')))) class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable): @@ -336,7 +336,7 @@ class VariableOsInstallNetMacType(NetHelper, ReadonlyVariable): return "local" 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): @@ -349,8 +349,8 @@ class VariableOsInstallNetMac(NetHelper, ReadonlyVariable): self.label = _("MAC") def get(self): - return map(lambda x: getMac(x).lower(), - self.Get('os_install_net_interfaces')) + return list(map(lambda x: getMac(x).lower(), + self.Get('os_install_net_interfaces'))) class VariableOsInstallNetStatus(NetHelper, Variable): @@ -363,8 +363,8 @@ class VariableOsInstallNetStatus(NetHelper, Variable): self.label = _("IP address") def get(self): - return 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 +389,9 @@ 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 map(lambda x: self.getDefaultValue(x[1]) \ + return list(map(lambda x: self.getDefaultValue(x[1]) \ if x[0] == "auto" else x[0], - zip(value, ifaces)) + zip(value, ifaces))) def check(self, value): for status in value: @@ -415,10 +415,10 @@ class VariableOsInstallNetIp(NetHelper, ReadonlyVariable): self.label = _("IP address") 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], zip(self.Get('os_install_net_interfaces'), - self.Get('os_install_net_status'))) + self.Get('os_install_net_status')))) # def check(self,value): # dhcps = self.Get('os_install_net_dhcp_set') @@ -439,9 +439,9 @@ class VariableOsInstallNetNetwork(NetHelper, ReadonlyVariable): self.label = _("Network") def get(self): - return map(lambda x: getIpNet(x[0], x[1]) if x[0] and x[1] else "", + 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'))) + self.Get('os_install_net_mask')))) class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable): @@ -457,8 +457,8 @@ class VariableOsInstallNetCidr(NetHelper, ReadonlyVariable): """ Get CIDR of ip,net (Example: 24) """ - return map(lambda x: maskToCidr(x) if x else '', - self.Get('os_install_net_mask')) + return list(map(lambda x: maskToCidr(x) if x else '', + self.Get('os_install_net_mask'))) class VariableOsInstallNetMask(NetHelper, Variable): @@ -471,8 +471,8 @@ class VariableOsInstallNetMask(NetHelper, Variable): self.label = _("Mask") def get(self): - return map(lambda x: cidrToMask(getMask(x)), - self.Get('os_install_net_interfaces')) + return list(map(lambda x: cidrToMask(getMask(x)), + self.Get('os_install_net_interfaces'))) def set(self, value): """ @@ -490,9 +490,9 @@ class VariableOsInstallNetMask(NetHelper, Variable): def check(self, value): dhcps = self.Get('os_install_net_status') - wrongMask = filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \ + wrongMask = list(filter(lambda x: (x[0] or not x[1] in ("off", "dhcp")) and \ not checkMask(x[0]), - zip(value, dhcps)) + zip(value, dhcps))) if wrongMask: raise VariableError(_("Wrong mask %s") % wrongMask[0][0]) @@ -514,8 +514,8 @@ class VariableOsInstallNetDhcpSet(NetHelper, Variable): self.label = _("DHCP") def get(self): - return map(lambda x: "on" if x == "dhcp" else "off", - self.Get('os_install_net_status')) + return list(map(lambda x: "on" if x == "dhcp" else "off", + self.Get('os_install_net_status'))) class VariableOsInstallNetRouteData(NetHelper, TableVariable): @@ -545,18 +545,18 @@ class VariableOsInstallNetRouteData(NetHelper, TableVariable): interfaces_status = self.Get('os_install_net_status') interfaces_network = self.Get('os_install_net_network') staticInterface = \ - map(itemgetter(0, 2), + list(map(itemgetter(0, 2), filter(lambda x: not x[1] in ("off", "dhcp"), - zip(interfaces, interfaces_status, interfaces_network))) + zip(interfaces, interfaces_status, interfaces_network)))) route_data = [] if 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('dev', ''), x[1].get('src', '')], - ifilter(lambda x: not x[0] in skipNet, - ip.getRouteTable(staticInterface))) or [[]] + filter(lambda x: not x[0] in skipNet, + ip.getRouteTable(staticInterface)))) or [[]] return [[]] def getHumanReadableAuto(self): @@ -598,8 +598,8 @@ class VariableOsInstallNetRouteNetwork(NetHelper, FieldValue, Variable): ########################## # detect duplicate network ########################## - for wrongnet in ifilterfalse(ip.checkNet, - ifilter("default".__ne__, + for wrongnet in filterfalse(ip.checkNet, + filter("default".__ne__, value)): raise VariableError(_("Wrong network %s") % wrongnet) dupNetwork = list(set(filter(lambda x: value.count(x) > 1, @@ -630,15 +630,15 @@ class VariableOsInstallNetRouteGw(NetHelper, FieldValue, Variable): chain(self.Get('os_install_net_route_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) - wrongGws = map(lambda x: x[GW], + 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))) + netsGw)))) if wrongGws: raise VariableError(_("Gateways %s are unreachable") % (",".join(wrongGws))) @@ -674,12 +674,12 @@ class VariableOsInstallNetRouteSrc(NetHelper, FieldValue, Variable): return [""] + self.Get('os_install_net_ip') def check(self, value): - for wrongip in ifilterfalse(ip.checkIp, - ifilter(None, value)): + for wrongip in filterfalse(ip.checkIp, + filter(None, value)): raise VariableError(_("Wrong source IP %s") % wrongip) ipAddrs = self.Get('os_install_net_ip') - wrongIps = filter(lambda x: x and not x in ipAddrs, - value) + wrongIps = list(filter(lambda x: x and not x in ipAddrs, + value)) if wrongIps: raise VariableError( _("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_src')) 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 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'), 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 +757,10 @@ class VariableOsInstallNetNmroute(VariableOsInstallNetRoute): def getRouteForInterfaceNM(interface, net, routeMatrix): 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 \ x[NET] == "default", - routeMatrix)) + routeMatrix))) return "{0}\n".format(defaultGw[0] if defaultGw else "") + \ "\n".join( # build string for route from net,gateway,dev and src @@ -799,10 +799,10 @@ class VariableOsInstallNetConfAvailable(NetHelper, Variable): with image as distr: try: distrPath = image.getDirectory() - return map(itemgetter(0, 2), + return list(map(itemgetter(0, 2), filter(lambda x: not x[1] or isPkgInstalled(x[1], prefix=distrPath), - mapNetConf)) + mapNetConf))) except DistributiveError as e: pass return sorted(map(itemgetter(0, 2), mapNetConf[-1:]), key=itemgetter(1)) @@ -822,9 +822,9 @@ class VariableOsInstallNetConf(NetHelper, Variable): def get(self): """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/default')) \ + listDirectory('/etc/runlevels/default'))) \ or self.Get('os_root_type') == "livecd": nm = "networkmanager" else: @@ -863,7 +863,7 @@ class VariableOsInstallNetDnsSearch(NetHelper, Variable): return False def set(self, value): - return " ".join(re.split('[; ,]', value)) + return " ".join(re.split(r'[; ,]', value)) def get(self): """Get current name servers""" @@ -891,7 +891,7 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch): self.help = _("domain name server (comma-separated)") def set(self, value): - return " ".join(re.split('[; ,]', value)) + return " ".join(re.split(r'[; ,]', value)) def get(self): dnsIps = filter(ip.checkIp, @@ -904,7 +904,7 @@ class VariableOsInstallNetDns(VariableOsInstallNetDnsSearch): def check(self, value): reIp = re.compile(ip.IP_ADDR) - if any(ifilterfalse(reIp.match, value.split(' '))): + if any(filterfalse(reIp.match, value.split(' '))): raise VariableError(_("Wrong IP address for DNS")) def humanReadable(self): @@ -938,11 +938,11 @@ class VariableOsInstallPxeIp(Variable): def get(self): ips = self.Get('os_net_ip').split(',') - for ipaddr in ifilter(None, ips): + for ipaddr in filter(None, ips): return ipaddr else: return "" def choice(self): ips = self.Get('os_net_ip').split(',') - return filter(None, ips) + return list(filter(None, ips)) diff --git a/pym/install/variables/system.py b/pym/install/variables/system.py index 4e03e85..8eb9b57 100644 --- a/pym/install/variables/system.py +++ b/pym/install/variables/system.py @@ -69,7 +69,7 @@ class GrubHelper(VariableInterface): Получить пароль из конфигурационного файла grub """ 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) if pwd: return pwd.group(1) @@ -121,7 +121,7 @@ class VariableOsFormatType(ReadonlyVariable): def get(self): """Filesystem format support by calcualte-install""" - return FileSystemManager.supportFS.keys() + return list(FileSystemManager.supportFS.keys()) class VariableOsFormatUse(ReadonlyVariable): @@ -141,7 +141,7 @@ class VariableOsFormatUse(ReadonlyVariable): return "no" def get(self): - return map(self.checkFunc, self.Get('os_format_type')) + return list(map(self.checkFunc, self.Get('os_format_type'))) class VariableClMigrateRootPwdPlain(GrubHelper, UserHelper, Variable): @@ -194,10 +194,10 @@ class VariableClMigrateRootShadowPwd(ReadonlyVariable): содержит пустую строку """ def get(self): - rootPasswd = map(lambda x: x[1], + rootPasswd = list(map(lambda x: x[1], filter("root".__eq__, map(lambda x: x.split(':')[0:2], - readLinesFile('/etc/shadow')))) + readLinesFile('/etc/shadow'))))) if rootPasswd: rootPasswd = rootPasswd[0] else: @@ -419,7 +419,7 @@ class VariableClMigrateAdmin(UserHelper, Variable): for x in self.Get('cl_migrate_user')] def set(self, value): - return map(lambda x: x if x else self.default_value, value) + return list(map(lambda x: x if x else self.default_value, value)) class VariableOsAvailableGroups(ReadonlyVariable): @@ -476,8 +476,8 @@ class VariableClMigrateUserGroups(UserHelper, Variable): yield value def set(self, value): - value = map(lambda x: sorted(list(set(self.process_groups(x)))), - value) + value = list(map(lambda x: sorted(list(set(self.process_groups(x)))), + value)) return value def getPrimaryGroup(self, username): @@ -491,11 +491,11 @@ class VariableClMigrateUserGroups(UserHelper, Variable): User groups """ passwdList = getPasswdUsers() - return map(lambda x: sorted(self.getPrimaryGroup(x) + + return list(map(lambda x: sorted(self.getPrimaryGroup(x) + (getUserGroups(x) if x in passwdList else self.getDefaultGroups())), - self.Get('cl_migrate_user')) + self.Get('cl_migrate_user'))) def choice(self): """ @@ -525,15 +525,15 @@ class VariableClMigrateUserPwd(UserHelper, Variable): if migrateusers: lenData = 9 with open(fileName) as f: - shadowData = filter(lambda x: len(x) == lenData, - map(lambda x: x.rstrip().split(":"), f)) - shadowData = filter(lambda x: x[0] in migrateusers, shadowData) - shadowData = map(lambda x: (x[0], x[1]), shadowData) - shadowUsers = map(lambda x: x[0], shadowData) + shadowData = 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)) for userName in migrateusers: if userName in shadowUsers: - userData = filter(lambda x: x[0] == userName, - shadowData) + userData = list(filter(lambda x: x[0] == userName, + shadowData)) hashPwd = userData[0][1] if (sha256_crypt.identify(hashPwd) and sha256_crypt.verify("guest", hashPwd)): @@ -559,8 +559,8 @@ class VariableClMigrateUserPwd(UserHelper, Variable): """ shadow_hash = get_shadow_hash() - return map(lambda x: x if shadow_hash.identify(x) or not x else \ - shadow_hash.hash(x), value) + return list(map(lambda x: x if shadow_hash.identify(x) or not x else \ + shadow_hash.hash(x), value)) class VariableClAutologin(UserHelper, Variable): @@ -587,8 +587,8 @@ class VariableClAutologin(UserHelper, Variable): if (not cmdDomainSet and self.Get('os_install_root_type') == "livecd") or \ self.Get('os_install_linux_shortname') == "CMC": - nonRootUsers = filter(lambda x: x != "root", - self.Get('cl_migrate_user')) + nonRootUsers = list(filter(lambda x: x != "root", + self.Get('cl_migrate_user'))) if nonRootUsers: return nonRootUsers[0] else: @@ -716,14 +716,14 @@ class VariableOsNvidiaMask(ReadonlyVariable): category = "0300" vendor = "10de:" lsPciProg = getProgPath("/usr/sbin/lspci") - nvidiacards = filter(lambda x: " %s: " % category in x, - process(lsPciProg, "-d", vendor, "-n")) + nvidiacards = list(filter(lambda x: " %s: " % category in x, + process(lsPciProg, "-d", vendor, "-n"))) cardsid = \ - map(lambda x: x.groups()[0], + list(map(lambda x: x.groups()[0], filter(lambda x: x, map(lambda x: re.search( - "[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x), - nvidiacards))) + r"[0-9a-fA-F]{4}:([0-9a-fA-F]{4})", x), + nvidiacards)))) if not cardsid: return set() return set(cardsid) @@ -748,7 +748,7 @@ class VariableOsNvidiaMask(ReadonlyVariable): eclassdata = readFile(nvidiaeclass) reBlock = re.compile( 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 = [] for block in reBlock.findall(eclassdata): nvidia_ids, mask_data = block @@ -838,9 +838,9 @@ class VariableOsGrub2Path(Variable): return grubInstall # find grub-install and check, that this is grub2-install (ver 1.99) grubInstall = getProgPath('/usr/sbin/grub-install', prefix=chroot_path) - if grubInstall and filter(lambda x: "1.99" in x or "2." in x, + if grubInstall and list(filter(lambda x: "1.99" in x or "2." in x, process(chroot_cmd, chroot_path, - grubInstall, '--version')): + grubInstall, '--version'))): return grubInstall return "" @@ -964,7 +964,7 @@ class VariableOsInstallGrubTerminal(Variable): if getValueFromConfig(grubDefault, 'GRUB_TERMINAL') == 'console': return 'console' 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 'gfxterm'