Исправления для установки на USB Flash

master3.4
parent adbd4cf890
commit 7e6394161e

@ -314,6 +314,14 @@ class Distributive(object):
raise DistributiveError(_("Failed to create the directory") +
" '%s':\n%s" % (pathname, str(e)))
def get_squash_size(self):
"""
Получить размер squash образа
:return:
"""
raise DistributiveError(_("Squash size unsupported for %s") %
str(self.__class__.__name__))
def _removeDirectory(self, directory):
"""Remove directory and files contained in it"""
try:
@ -535,7 +543,8 @@ class Distributive(object):
extname = mapExtName.get(distr.__class__, "")
image = distr.convertToDirectory()
except Exception as e:
print str(e)
# TODO: отладка почему образ не подходит
#print str(e)
if distr:
distr.close()
return {}.copy()
@ -616,6 +625,7 @@ class DirectoryDistributive(Distributive):
def __init__(self, directory, parent=None, mdirectory=None):
Distributive.__init__(self, parent=parent)
self.no_unmount = False
self.directory = directory
self.mdirectory = mdirectory
self.system_mounted = False
@ -1487,6 +1497,14 @@ class IsoDistributive(Distributive):
return path.exists(path.join(pathname, "syslinux")) and \
path.exists(path.join(pathname, "isolinux"))
def get_squash_size(self):
try:
dn = self.getIsoContentDirectory()
fn = path.join(dn, "livecd.squashfs")
return path.getsize(fn)
except Exception:
raise DistributiveError(_("Failed to get size of the squash image"))
def _mountIso(self, file, directory):
if self.file != self.mdirectory:
self._makeDirectory(directory)
@ -1704,6 +1722,22 @@ class FlashDistributive(PartitionDistributive):
return path.exists(path.join(pathname, "syslinux")) and \
path.exists(path.join(pathname, "isolinux"))
def convertToDirectory(self):
mp = isMount(self.partition)
if mp:
d = DirectoryDistributive(mp)
d.no_unmount = True
return d
else:
return super(FlashDistributive, self).convertToDirectory()
def releaseChild(self, child):
"""Umount child Directory distributive"""
if isinstance(child, DirectoryDistributive):
if not child.no_unmount:
self._umountPartition(child.directory)
child.directory = None
def installFrom(self, source, **kwargs):
"""Install distributive to partition from source distributive"""
# make temporary directory for creating iso image

@ -23,6 +23,8 @@ from subprocess import Popen
from os import path
from itertools import *
from operator import itemgetter
from calculate.install.distr import FlashDistributive, DistributiveError, \
IsoDistributive
from calculate.lib.datavars import (TableVariable, Variable, VariableError,
ReadonlyVariable, ReadonlyTableVariable,
SourceReadonlyVariable, VariableInterface,
@ -35,7 +37,7 @@ from calculate.lib.utils.device import (getUdevDeviceInfo, getDeviceType,
getUUIDDict, getCommonDeviceName)
from calculate.install.variables.autopartition import Sizes
from calculate.lib.utils.files import (listDirectory, pathJoin, readFile, FStab,
isMount, getProgPath)
isMount, getProgPath, DiskSpace)
from calculate.install.fs_manager import FileSystemManager
from calculate.lib.cl_lang import setLocalTranslate, _
@ -2053,8 +2055,8 @@ class VariableOsInstallRootDev(ReadonlyVariable):
"""Get install root device"""
if self.Get('cl_action') == 'system':
return self.Select('os_install_disk_dev_base',
where='os_install_disk_mount_base',
eq="/", limit=1) or ''
where='os_install_disk_mount_base',
eq="/", limit=1) or ''
else:
return self.Get('os_root_dev')
@ -2152,47 +2154,26 @@ class VariableOsInstallDiskSingle(Variable):
"""
Installation disk
"""
type = "choice"
type = "choiceedit"
opt = ["--disk", "-d"]
metavalue = 'DISK'
untrusted = True
value = ""
def init(self):
self.label = _("Installation disk")
self.help = _("set the USB Flash device")
def availDevs(self):
"""
Available devices
"""
if self.Get('cl_install_type') == 'flash':
flashDrives = self.Select('os_device_dev',
where='os_device_type',
eq="flash")
return self.Select('os_disk_dev',
where='os_disk_parent',
_in=flashDrives)
else:
return self.Get('os_disk_dev') + self.Get('os_bind_path')
def get(self):
if self.Get('cl_install_type') == 'flash':
disks = self.availDevs()
if disks:
return disks[0]
return ""
def choice(self):
# TODO: любой раздел vfat, неформатированный или раздел на flash
# ??????
diskParentMap = dict(zip(self.Get('os_disk_dev'),
self.Get('os_disk_parent')))
deviceParentMap = dict(self.ZipVars('os_device_dev', 'os_device_name'))
disks = self.select('os_disk_dev', os_disk_part__ne="")
return map(lambda x: (x, "%s (%s)" % (x,
deviceParentMap.get(
diskParentMap.get(x, x),
_("Unknown")))),
self.availDevs()) + [("", "")]
disks)
def check(self, value):
# проверить, чтобы был выбран именно раздел
@ -2234,6 +2215,7 @@ class VariableOsInstallFormatSingleSet(Variable):
type = "bool"
opt = ["--format"]
untrusted = True
value = "off"
def init(self):
self.label = _("Format the USB Flash")
@ -2249,22 +2231,34 @@ class VariableOsInstallFormatSingleSet(Variable):
flash_dev = self.Get('os_root_flash_dev')
return flash_dev and dev == flash_dev
def get(self):
dev = self.Get('os_install_disk_single')
if self.must_be_formatted(dev):
return "on"
if self.cannot_be_formatted(dev):
return "off"
return "on"
def check(self, value):
devs = self.Get('os_disk_dev')
dev = self.Get('os_install_disk_single')
if value == "off":
if self.must_be_formatted(dev):
raise VariableError(
_("{device} must be formatted").format(device=dev))
else:
if dev not in devs:
return
if value == "on":
if self.cannot_be_formatted(dev):
raise VariableError(
_("You cannot format the USB Flash which "
"contains the current system"))
else:
if self.must_be_formatted(dev):
raise VariableError(
_("{device} must be formatted").format(device=dev))
if dev:
try:
with FlashDistributive(dev) as f:
dn = f.getDirectory()
df = DiskSpace()
free_size = df.get_free(dev)
squash_fn = path.join(dn, "livecd.squashfs")
if not path.exists(squash_fn):
source = self.Get('cl_image')
if isinstance(source, IsoDistributive):
image_size = source.get_squash_size()
if image_size > free_size:
raise VariableError(
_("Not enough free space on the "
"USB Flash"))
except DistributiveError:
pass

@ -532,7 +532,7 @@ class VariableClTarget(ReadonlyVariable):
'vfat', {}).get('msdos', '0b')
isFormat = self.GetBool('os_install_format_single_set')
partTable = self.select('os_disk_part',
os_disk_dev='disk', limit=1)
os_disk_dev=disk, limit=1)
return FlashDistributive(
disk, mdirectory=DefaultMountPath.InstallMount,
check=True, fileSystem=fileSystem,

@ -59,7 +59,8 @@ class Wsdl(WsdlBase):
'native_error': (VariableError, DistributiveError,
DataVarsError, install.InstallError),
# значения по умолчанию для переменных этого метода
'setvars': {'cl_action!': 'system', 'cl_dispatch_conf': 'usenew'},
'setvars': {'cl_action!': 'system', 'cl_install_type': 'hdd',
'cl_dispatch_conf': 'usenew'},
# описание груп (список лямбда функций)
'groups': [
lambda group: group(_("Language and locale"),

Loading…
Cancel
Save