Новые параметры авторазметки

master3.4 3.4.5
parent f87e69036a
commit 96a518a14a

@ -69,6 +69,29 @@ class AutopartitionError(Exception):
pass pass
class SchemeOpt(object):
Swap = "swap"
Update = "update"
UEFI = "uefi"
LVM = "lvm"
Calculate = "calculate"
class SchemeDevices(object):
Swap = "swap"
Root1 = "system1"
Root2 = "system2"
UEFI = "uefi"
Data = "calculate"
@classmethod
def get_by_opt(cls, opt):
opt_map = {SchemeOpt.Swap: cls.Swap,
SchemeOpt.UEFI: cls.UEFI,
SchemeOpt.Calculate: cls.Data}
return opt_map.get(opt, opt)
class AutoPartition(object): class AutoPartition(object):
""" """
Autopartition maker Autopartition maker
@ -307,9 +330,9 @@ class AutoPartition(object):
lvname = disk.rpartition('/')[2] lvname = disk.rpartition('/')[2]
if not self._createLogicalVolume(vgname, lvname, size): if not self._createLogicalVolume(vgname, lvname, size):
raise AutopartitionError( raise AutopartitionError(
_("Failed to create logical volume {name}") _("Failed to create logical volume {name}").format(
.format(name=lvname)) name=lvname))
self._waitDevice('/dev/%s/root' % vgname) self._waitDevice('/dev/%s/%s' % (vgname, SchemeDevices.Root1))
class AutopartitionHelper(VariableInterface): class AutopartitionHelper(VariableInterface):
@ -318,55 +341,54 @@ class AutopartitionHelper(VariableInterface):
""" """
def deviceOpts(self, listvalue): def deviceOpts(self, listvalue):
l = [x for x in listvalue if x not in ("home", "lvm", "raid", "grub")] l = [x for x in listvalue if x not in (SchemeOpt.LVM,)]
for i in ("uefi", "swap", "boot"): for i in (SchemeOpt.UEFI, SchemeOpt.Swap):
if i in l: if i in l:
l.remove(i) l.remove(i)
yield i yield SchemeDevices.get_by_opt(i)
break break
yield "root2" yield SchemeDevices.Root1
if "root" in l: if SchemeOpt.Update in l:
l.remove("root") l.remove(SchemeOpt.Update)
yield "root" yield SchemeDevices.Root2
for i in l: for i in l:
yield i yield SchemeDevices.get_by_opt(i)
def bindOpts(self, listvalue): def bindOpts(self, listvalue):
return filter(lambda x: x in ("data",), return filter(lambda x: x in (SchemeOpt.Calculate,),
listvalue) listvalue)
def mpByOpts(self, value): def mpByOpts(self, value):
mapMp = {'swap': 'swap', mapMp = {SchemeDevices.Swap: 'swap',
'boot': '/boot', SchemeDevices.Root1: '/',
'root2': '/', SchemeDevices.Root2: '',
'root': '', SchemeDevices.UEFI: '/boot/efi',
'uefi': '/boot/efi', SchemeDevices.Data: '/var/calculate'}
'data': '/var/calculate'}
return mapMp.get(value, '') return mapMp.get(value, '')
def sourceMpByOpts(self, value): def sourceMpByOpts(self, value):
mapMp = {'data': '/var/calculate/home'} mapMp = {SchemeOpt.Calculate: '/var/calculate/home'}
return mapMp.get(value, '') return mapMp.get(value, '')
def targetMpByOpts(self, value): def targetMpByOpts(self, value):
mapMp = {'data': '/home'} mapMp = {SchemeOpt.Calculate: '/home'}
return mapMp.get(value, '') return mapMp.get(value, '')
def getAutopartitionScheme(self): def getAutopartitionScheme(self):
optOrder = {'uefi': 0, """
'root': 1, Получить список опций отсортированный в нужном порядке
'home': 2, """
'swap': 3, optOrder = {SchemeOpt.UEFI: 0,
'boot': 4, SchemeOpt.Update: 1,
'data': 5, SchemeOpt.Swap: 2,
SchemeOpt.Calculate: 3,
} }
return sorted(self.Get('cl_autopartition_scheme'), key=optOrder.get) return sorted(self.Get('cl_autopartition_scheme'), key=optOrder.get)
def uncompatible(self): def uncompatible(self):
if self.Get('cl_autopartition_set') == "off": if self.Get('cl_autopartition_set') == "off":
return \ return _("Autopartition options are not available with manual "
_("Autopartition options are not available with manual " "partitioning")
"partitioning")
return "" return ""
@ -546,23 +568,30 @@ class VariableClAutopartitionScheme(AutopartitionHelper, AutoPartition,
def get(self): def get(self):
if self.Get('os_uefi_set') == 'on': if self.Get('os_uefi_set') == 'on':
return ["uefi", "swap", "root", "data"] return [SchemeOpt.UEFI,
SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
elif self.Get('cl_autopartition_table') == 'gpt': elif self.Get('cl_autopartition_table') == 'gpt':
return ["swap", "root", "data"] return [SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
else: else:
return ["swap", "root", "data"] return [SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
def choice(self): def choice(self):
return [ return [
("swap", _("Swap partition")), (SchemeOpt.Swap, _("Swap partition")),
("root", _("Additional root partition")), (SchemeOpt.Update, _("The partition for the update")),
("data", _("/var/calculate partition")), (SchemeOpt.Calculate, _("/var/calculate partition")),
("uefi", _("Use the UEFI bootloader")), (SchemeOpt.UEFI, _("Use the UEFI bootloader")),
("lvm", _("Use LVM")), (SchemeOpt.LVM, _("Use LVM")),
] ]
def check(self, value): def check(self, value):
if "uefi" in value: if SchemeOpt.UEFI in value:
if self.Get('os_uefi_set') == 'off': if self.Get('os_uefi_set') == 'off':
raise VariableError( raise VariableError(
_("Your system must be loaded in UEFI for using this " _("Your system must be loaded in UEFI for using this "
@ -676,7 +705,8 @@ class VariableClAutopartitionLvmSet(ReadonlyVariable):
type = "bool" type = "bool"
def get(self): def get(self):
return "on" if "lvm" in self.Get('cl_autopartition_scheme') else "off" return ("on" if SchemeOpt.LVM in self.Get('cl_autopartition_scheme')
else "off")
class VariableClAutopartitionUefiSet(ReadonlyVariable): class VariableClAutopartitionUefiSet(ReadonlyVariable):
@ -686,7 +716,8 @@ class VariableClAutopartitionUefiSet(ReadonlyVariable):
type = "bool" type = "bool"
def get(self): def get(self):
return "on" if "uefi" in self.Get('cl_autopartition_scheme') else "off" return ("on" if SchemeOpt.UEFI in self.Get('cl_autopartition_scheme')
else "off")
class VariableClAutopartitionLvmVgname(Variable): class VariableClAutopartitionLvmVgname(Variable):
@ -697,7 +728,7 @@ class VariableClAutopartitionLvmVgname(Variable):
def get(self): def get(self):
def generateName(startName): def generateName(startName):
yield startName yield startName
for i in count(2): for i in count(20):
yield "%s%d" % (startName, i) yield "%s%d" % (startName, i)
for name in generateName("calculate"): for name in generateName("calculate"):
@ -732,10 +763,8 @@ class VariableClAutopartitionDiskDev(AutopartitionHelper, ReadonlyVariable):
def generateLvm(self, scheme=(), devices=(), **kwargs): def generateLvm(self, scheme=(), devices=(), **kwargs):
vgname = self.Get('cl_autopartition_lvm_vgname') vgname = self.Get('cl_autopartition_lvm_vgname')
number = 1 number = 1
for line in map(lambda x: {'root': 'root2', for line in self.deviceOpts(scheme):
'root2': 'root'}.get(x, x), if line in (SchemeDevices.UEFI,):
self.deviceOpts(scheme)):
if line in ("boot", "uefi"):
if (number == 4 and if (number == 4 and
self.Get('cl_autopartition_bios_grub_set') == 'on'): self.Get('cl_autopartition_bios_grub_set') == 'on'):
number += 1 number += 1
@ -771,7 +800,7 @@ class VariableClAutopartitionDiskScheme(AutopartitionHelper, ReadonlyVariable):
def generateScheme(self, scheme): def generateScheme(self, scheme):
""" """
Generate mount points for automount scheme Generate scheme for automount scheme
""" """
for line in self.deviceOpts(scheme): for line in self.deviceOpts(scheme):
yield line yield line
@ -818,9 +847,9 @@ class VariableClAutopartitionDiskFormat(AutopartitionHelper, ReadonlyVariable):
Generate filesystems for automount scheme Generate filesystems for automount scheme
""" """
for line in self.deviceOpts(scheme): for line in self.deviceOpts(scheme):
if line == "swap": if line == SchemeDevices.Swap:
yield "swap" yield "swap"
elif line == "uefi": elif line == SchemeDevices.UEFI:
yield "vfat" yield "vfat"
else: else:
yield FileSystemManager.defaultFS['hdd'] yield FileSystemManager.defaultFS['hdd']
@ -860,9 +889,7 @@ class VariableClAutopartitionDiskPart(AutopartitionHelper, ReadonlyVariable):
scheme = self.getAutopartitionScheme() scheme = self.getAutopartitionScheme()
table = self.Get('cl_autopartition_table') table = self.Get('cl_autopartition_table')
if scheme: if scheme:
return list(self.generatePart(scheme, return list(self.generatePart(scheme, table == 'dos'))
self.Get(
'cl_autopartition_table') == 'dos'))
return [] return []
@ -890,18 +917,18 @@ class VariableClAutopartitionDiskSize(AutopartitionHelper, ReadonlyVariable):
def generateSize(self, scheme, memory, bootsize, uefisize, rootsize, def generateSize(self, scheme, memory, bootsize, uefisize, rootsize,
availsize, minrootsize): availsize, minrootsize):
args = {'swap': memory, args = {SchemeDevices.Swap: memory,
'root': rootsize, SchemeDevices.Root1: rootsize,
'root2': rootsize, SchemeDevices.Root2: rootsize,
'boot': bootsize, SchemeDevices.UEFI: uefisize,
'uefi': uefisize,
} }
minrootsize = int(minrootsize) minrootsize = int(minrootsize)
deviceOpts = list(self.deviceOpts(scheme)) deviceOpts = list(self.deviceOpts(scheme))
for line in deviceOpts[:-1]: for line in deviceOpts[:-1]:
availsize -= int(args.get(line, 0)) availsize -= int(args.get(line, 0))
yield str(args.get(line, 0)) yield str(args.get(line, 0))
if "root" in deviceOpts[-1] and availsize < minrootsize: if deviceOpts[-1] in (SchemeDevices.Root1,
SchemeDevices.Root2) and availsize < minrootsize:
yield str(minrootsize) yield str(minrootsize)
elif availsize < 1 * Sizes.G: elif availsize < 1 * Sizes.G:
yield str(1 * Sizes.G) yield str(1 * Sizes.G)
@ -914,26 +941,20 @@ class VariableClAutopartitionDiskSize(AutopartitionHelper, ReadonlyVariable):
device = self.Get('cl_autopartition_device') device = self.Get('cl_autopartition_device')
availSize = self.Get('cl_autopartition_device_size') availSize = self.Get('cl_autopartition_device_size')
if device: if device:
return list(self.generateSize(scheme, return list(self.generateSize(
self.Get( scheme,
'cl_autopartition_swap_size'), self.Get('cl_autopartition_swap_size'),
self.Get( self.Get('cl_autopartition_boot_size'),
'cl_autopartition_boot_size'), self.Get('cl_autopartition_uefi_size'),
self.Get( self.Get('cl_autopartition_root_size'),
'cl_autopartition_uefi_size'), int(availSize),
self.Get( self.Get('cl_autopartition_root_size_min')))
'cl_autopartition_root_size'),
int(availSize),
self.Get(
'cl_autopartition_root_size_min')
))
return [] return []
def humanReadable(self): def humanReadable(self):
allSize = self.Get('cl_autopartition_free_size') allSize = self.Get('cl_autopartition_free_size')
return map(humanreadableSize, return map(humanreadableSize,
map(lambda x: allSize if x == "allfree" else x, map(lambda x: allSize if x == "allfree" else x, self.Get()))
self.Get()))
class VariableClAutopartitionUefiSize(Variable): class VariableClAutopartitionUefiSize(Variable):

Loading…
Cancel
Save