diff --git a/pym/install/variables/autopartition.py b/pym/install/variables/autopartition.py index 2133281..6956cf0 100644 --- a/pym/install/variables/autopartition.py +++ b/pym/install/variables/autopartition.py @@ -23,7 +23,7 @@ import calculate.lib.utils.device as device from calculate.lib.utils.device import humanreadableSize from calculate.lib.utils import partition from calculate.lib.utils.files import (readLinesFile) -from calculate.lib.utils.mount import isMount +from calculate.lib.utils.mount import isMount, try_umount from calculate.install.fs_manager import FileSystemManager from calculate.lib.utils.tools import Sizes, traverse from itertools import * @@ -295,6 +295,24 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): if typecheck.search(fulltype): raise VariableError(_("RAID %s is wrong") % dev) + def is_force_param(self): + return "--force" in self.Get("cl_console_args") + + def get_mounted_devices(self): + mountedData = [(x,y) for x,y in self.ZipVars( + "os_disk_parent", "os_disk_dev") if isMount(y)] + mountedDevices = {} + for devices, disk in mountedData: + if not isMount(disk): + continue + if self.is_force_param() and try_umount(disk): + continue + for _device in traverse(devices.split(',')): + if _device not in mountedDevices: + mountedDevices[_device] = set() + mountedDevices[_device].add(disk) + return mountedDevices + def check(self, valuelist): if self.Get('cl_autopartition_set') == "on": if not valuelist: @@ -303,14 +321,8 @@ class VariableClAutopartitionDevice(AutopartitionHelper, Variable): useDisks = set(traverse(x.split(',') for x in self.Select( 'os_disk_parent', where='os_disk_mount', ne=''))) - mountedData = [(x,y) for x,y in self.ZipVars( - "os_disk_parent", "os_disk_dev") if isMount(y)] - mountedDevices = {} - for devices, disk in mountedData: - for _device in traverse(devices.split(',')): - if _device not in mountedDevices: - mountedDevices[_device] = set() - mountedDevices[_device].add(disk) + + mountedDevices = self.get_mounted_devices() for value in chain(valuelist): for disk in set(chain(self.select( diff --git a/pym/install/variables/disk.py b/pym/install/variables/disk.py index 04f4a68..18fcb06 100644 --- a/pym/install/variables/disk.py +++ b/pym/install/variables/disk.py @@ -35,7 +35,7 @@ from calculate.lib.utils.device import (getPartitionSize, from calculate.install.variables.autopartition import Sizes from calculate.lib.utils.files import getProgPath from calculate.lib.utils.mount import isMount, FStab, DiskSpace, Btrfs, \ - BtrfsError + BtrfsError, try_umount from calculate.install.fs_manager import FileSystemManager from calculate.lib.cl_lang import setLocalTranslate, _ @@ -1418,6 +1418,9 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): fixNtfs = lambda self, x: {'ntfs-3g': 'ntfs'}.get(x, x) + def is_force_param(self): + return "--force" in self.Get("cl_console_args") + def check(self, value): """Check perform format @@ -1453,9 +1456,10 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): "mounted to {mountpoint} on the current system").format( device=dev, mountpoint=diskMount.get(dev, ''))) if isMount(dev): - raise VariableError( - _("Please unmount {device}, as it will be used for " - "installation").format(device=dev)) + if not self.is_force_param() or not try_umount(dev): + raise VariableError( + _("Please unmount {device}, as it will be used for " + "installation").format(device=dev)) # but user select non-format if not self.isTrue(isformat): raise VariableError( @@ -1479,9 +1483,10 @@ class VariableOsLocationPerformFormat(LocationHelper, Variable): ).format( device=dev, mountpoint=diskMount.get(dev, ''))) elif isMount(dev): - raise VariableError( - _("Please unmount disk {device} to " - "use it for install").format(device=dev)) + if not self.is_force_param() or not try_umount(dev): + raise VariableError( + _("Please unmount disk {device} to " + "use it for install").format(device=dev)) def defaultPerformFormat(self): diskFormat = dict(zip(self.Get('os_disk_dev'), @@ -2036,6 +2041,9 @@ class VariableOsInstallUefi(LocationHelper, Variable): def install_to_flash(self): return self.Get('os_install_root_type') == 'flash' + def is_force_param(self): + return "--force" in self.Get("cl_console_args") + def get(self): # если используется авторазметка список разделов находится в ней if self.GetBool('cl_autopartition_set'): @@ -2117,9 +2125,11 @@ class VariableOsInstallUefi(LocationHelper, Variable): os_disk_format__ne="vfat") for efipart in value: if efipart in not_fat_efi and isMount(efipart): - raise VariableError( - _("Please unmount {device}, as it will be used for " - "installation").format(device=efipart)) + + if not self.is_force_param() or not try_umount(efipart): + raise VariableError( + _("Please unmount {device}, as it will be used for " + "installation").format(device=efipart)) for efipart in value: if efipart in self.select('os_location_source',