From 57df4358f0a026d0d6b98048070acbd2ed4b2ee3 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Thu, 22 Jul 2021 09:30:40 +0300 Subject: [PATCH] fixed old sorting function, modernized classes --- pym/install/distr.py | 8 ++++---- pym/install/fs_manager.py | 2 +- pym/install/migrate_users.py | 4 ++-- pym/install/variables/autopartition.py | 2 +- pym/install/variables/distr.py | 22 +++++++++++++++------- pym/install/variables/kernel.py | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pym/install/distr.py b/pym/install/distr.py index 9db46b7..ed6edf1 100644 --- a/pym/install/distr.py +++ b/pym/install/distr.py @@ -52,7 +52,7 @@ from functools import reduce setLocalTranslate('cl_install3', sys.modules[__name__]) -class DefaultMountPath(object): +class DefaultMountPath(): """ Пути по умолчанию для монтирования образов """ @@ -129,12 +129,12 @@ class DistributiveError(Exception): pass -class Distributive(object): +class Distributive(): """ Distributive object. Parent object for all distributive. """ - class Type(object): + class Type(): Directory = "dir" Partition = "part" SquashFS = "squash" @@ -766,7 +766,7 @@ class DirectoryDistributive(Distributive): return ld -class DataPartition(object): +class DataPartition(): """Data partition""" dev = None mountPoint = None diff --git a/pym/install/fs_manager.py b/pym/install/fs_manager.py index 148e846..4b2e70a 100644 --- a/pym/install/fs_manager.py +++ b/pym/install/fs_manager.py @@ -22,7 +22,7 @@ from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_install3', sys.modules[__name__]) -class FileSystemManager(object): +class FileSystemManager(): """Convert dict install option""" defaultOpt = ['noatime'] diff --git a/pym/install/migrate_users.py b/pym/install/migrate_users.py index 399ee82..32ab02c 100644 --- a/pym/install/migrate_users.py +++ b/pym/install/migrate_users.py @@ -29,7 +29,7 @@ class MigrationError(Exception): pass -class _shareData(object): +class _shareData(): """Share class""" _reNumb = re.compile("^\d+$") @@ -240,7 +240,7 @@ class migrateShadow(_shareData): dataThisShadow) -class migrate(object): +class migrate(): """Migrate users ang groups to new system""" templateShadow = "%(user)s:%(hash)s:%(days)s:0:%(maxDays)s:%(warnDays)s:::" templateUser = "%(user)s:x:%(id)s:%(gid)s::/home/%(user)s:/bin/bash" diff --git a/pym/install/variables/autopartition.py b/pym/install/variables/autopartition.py index fb42dc4..02f92b8 100644 --- a/pym/install/variables/autopartition.py +++ b/pym/install/variables/autopartition.py @@ -71,7 +71,7 @@ class AutopartitionError(Exception): pass -class SchemeOpt(object): +class SchemeOpt(): Swap = "swap" Update = "update" UEFI = "uefi" diff --git a/pym/install/variables/distr.py b/pym/install/variables/distr.py index 0c42d8b..706fd68 100644 --- a/pym/install/variables/distr.py +++ b/pym/install/variables/distr.py @@ -34,7 +34,7 @@ from calculate.install.distr import (Distributive, PartitionDistributive, from calculate.lib.cl_lang import setLocalTranslate, _ from calculate.install.fs_manager import FileSystemManager -from functools import reduce +from functools import reduce, cmp_to_key setLocalTranslate('cl_install3', sys.modules[__name__]) @@ -168,6 +168,7 @@ class DistroRepository(Linux): # join files lists to one list return [x for x in reduce(lambda x, y: x + y, allFiles, []) if distfilter(x)] + @staticmethod def extcomparator(self, *exts): """Compare extensions""" mapExts = {'iso': 0, @@ -175,9 +176,16 @@ class DistroRepository(Linux): 'isodir': -2, 'partdir': -3, 'dir': -4} - return cmp(mapExts.get(exts[0], -4), mapExts.get(exts[1], -4)) + + # return cmp(mapExts.get(exts[0], -4), mapExts.get(exts[1], -4)) + #no cmp in python3, instead do (a > b) - (a < b) + return (mapExts.get(exts[0], -4) > mapExts.get(exts[1], -4)) - \ + (mapExts.get(exts[0], -4) < mapExts.get(exts[1], -4)) + - def sortdistrfunc(self, x, y): + + @staticmethod + def sortdistrfunc(x, y): """Func of comparing two distributive""" ver1, ver2 = x[1].get('os_linux_ver', ""), y[1].get('os_linux_ver', "") if ver1 and ver2 and ver1 != "0" and ver2 != "0" and ver1 != ver2: @@ -193,7 +201,7 @@ class DistroRepository(Linux): return cmp(int(ser1), int(ser2)) ext1 = x[1].get('ext', "") ext2 = y[1].get('ext', "") - return self.extcomparator(ext1, ext2) + return DistroRepository.extcomparator(ext1, ext2) def getAvailableDristibutives(self, dirs, system=None, shortname=None, march=None, version=None, build=None, @@ -204,10 +212,10 @@ class DistroRepository(Linux): availDistrs = self._getAvailableDistributives(dirs, system, shortname, march, version, build) - availDistrs = [x for x + 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)] + if x[1] and "ext" in x[1] and not x[1]["ext"] in discardType) + return [x[0] for x in sorted(availDistrs, key=cmp_to_key(DistroRepository.sortdistrfunc), reverse=True)] def getBestDistributive(self, dirs, system=None, shortname=None, march=None, version=None, build=None, discardType=()): diff --git a/pym/install/variables/kernel.py b/pym/install/variables/kernel.py index eeed8f3..fbf8207 100644 --- a/pym/install/variables/kernel.py +++ b/pym/install/variables/kernel.py @@ -104,7 +104,7 @@ class VariableOsInstallKernelScheduler(Variable): return _("I/O scheduler unavailable for Flash install") -class KernelConfig(object): +class KernelConfig(): def __init__(self, kernel_config): self.data = readFile(kernel_config).split('\n') self.config = kernel_config