fixed old sorting function, modernized classes

py3_forced
idziubenko 3 years ago
parent 545a3a583c
commit 57df4358f0

@ -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

@ -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']

@ -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"

@ -71,7 +71,7 @@ class AutopartitionError(Exception):
pass
class SchemeOpt(object):
class SchemeOpt():
Swap = "swap"
Update = "update"
UEFI = "uefi"

@ -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=()):

@ -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

Loading…
Cancel
Save