2
0
mirror of https://github.com/mbusb/multibootusb synced 2024-11-01 15:40:16 +00:00

fix persistence logic

This commit is contained in:
Alin Trăistaru 2017-04-14 13:56:11 +03:00
parent 78ebfaf7e4
commit b1e7a3ae1f
3 changed files with 71 additions and 51 deletions

View File

@ -12,6 +12,8 @@ usb_mount = ""
usb_uuid = "" usb_uuid = ""
usb_label = "" usb_label = ""
persistence = 0 persistence = 0
persistence_available = False
persistence_max_size = 0
distro = "" distro = ""
status_text = "" status_text = ""
percentage = 0 percentage = 0

View File

@ -44,10 +44,9 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.tabWidget.setCurrentIndex(0) self.ui.tabWidget.setCurrentIndex(0)
# self.qemu = Qemu() # self.qemu = Qemu()
# FIXME self.ui.label_persistence_value.setVisible(False)
# self.ui.label_persistence_value.setVisible(False) self.ui.label_persistence.setVisible(False)
# self.ui.label_persistence.setVisible(False) self.ui.slider_persistence.setVisible(False)
# self.ui.slider_persistence.setVisible(False)
config.usb_disk = None config.usb_disk = None
config.image_path = None config.image_path = None
@ -64,6 +63,7 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.button_install_distro.clicked.connect(self.onCreateClick) self.ui.button_install_distro.clicked.connect(self.onCreateClick)
self.ui.button_uninstall_distro.clicked.connect(self.OnUninstallClick) self.ui.button_uninstall_distro.clicked.connect(self.OnUninstallClick)
self.ui.slider_persistence.valueChanged.connect(self.update_slider_text) self.ui.slider_persistence.valueChanged.connect(self.update_slider_text)
# self.ui.slider_persistence.sliderReleased.connect(self.ui_update_persistence)
# ISO Imager Tab # ISO Imager Tab
self.ui.button_write_image_to_disk.clicked.connect(self.dd_write) self.ui.button_write_image_to_disk.clicked.connect(self.dd_write)
@ -145,6 +145,7 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
if config.usb_disk: if config.usb_disk:
log("Selected device " + config.usb_disk) log("Selected device " + config.usb_disk)
config.persistence_max_size = persistence.max_disk_persistence(config.usb_disk)
self.usb_details = usb.details(config.usb_disk) self.usb_details = usb.details(config.usb_disk)
config.usb_mount = self.usb_details['mount_point'] config.usb_mount = self.usb_details['mount_point']
@ -164,6 +165,7 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.usb_mount.setText(self.usb_details['mount_point']) self.ui.usb_mount.setText(self.usb_details['mount_point'])
self.update_list_box(config.usb_disk) self.update_list_box(config.usb_disk)
self.ui_update_persistence()
else: else:
self.ui.usb_dev.clear() self.ui.usb_dev.clear()
self.ui.usb_vendor.clear() self.ui.usb_vendor.clear()
@ -258,9 +260,26 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.label_image_type_value.setText(str(config.distro)) self.ui.label_image_type_value.setText(str(config.distro))
self.ui.label_image_type_value.setVisible(True) self.ui.label_image_type_value.setVisible(True)
if config.distro: if config.distro:
per_availability = persistence.persistence_distro(config.distro, config.usb_disk, config.image_path)[0] per_availability = persistence.persistence_distro(config.distro, config.image_path)
per_max_size = persistence.persistence_distro(config.distro, config.usb_disk, config.image_path)[1]
if per_availability is not None: if per_availability is not None:
config.persistence_available = True
if config.usb_disk:
per_max_size = persistence.max_disk_persistence(config.usb_disk)
config.persistence_max_size = per_max_size
log('Persistence Max Size: ' + str(bytes2human(per_max_size)))
else:
config.persistence_available = False
log('Persistence is not available for ' + iso_name(config.image_path))
self.ui_update_persistence()
else:
log("File not selected...")
def ui_update_persistence(self):
log("===== config.persistence_available = " + str(config.persistence_available))
log("===== config.persistence_max_size = " + str(config.persistence_max_size))
log("===== config.persistence = " + str(config.persistence))
if config.persistence_available and config.persistence_max_size:
self.ui.label_persistence_value.setVisible(True) self.ui.label_persistence_value.setVisible(True)
self.ui.label_persistence.setVisible(True) self.ui.label_persistence.setVisible(True)
self.ui.slider_persistence.setVisible(True) self.ui.slider_persistence.setVisible(True)
@ -269,10 +288,8 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.slider_persistence.setEnabled(True) self.ui.slider_persistence.setEnabled(True)
self.ui.slider_persistence.setTickInterval(10) self.ui.slider_persistence.setTickInterval(10)
self.ui.slider_persistence.setSingleStep(10) self.ui.slider_persistence.setSingleStep(10)
ui_per_max_size = per_max_size / 1024 / 1024 self.ui.slider_persistence.setMaximum(config.persistence_max_size / 1024 / 1024)
# config.persistence = per_max_size # log("===== getMaximum = " + self.ui.slider_persistence.getMaximum()
self.ui.slider_persistence.setMaximum(ui_per_max_size)
log('Persistence Max Size: ' + str(bytes2human(per_max_size)))
else: else:
self.ui.label_persistence_value.setEnabled(False) self.ui.label_persistence_value.setEnabled(False)
self.ui.label_persistence.setEnabled(False) self.ui.label_persistence.setEnabled(False)
@ -280,9 +297,8 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
self.ui.label_persistence_value.setVisible(False) self.ui.label_persistence_value.setVisible(False)
self.ui.label_persistence.setVisible(False) self.ui.label_persistence.setVisible(False)
self.ui.slider_persistence.setVisible(False) self.ui.slider_persistence.setVisible(False)
log('Persistence is not available for ' + iso_name(config.image_path))
else:
log("File not selected...")
def update_slider_text(self): def update_slider_text(self):
slide_value = self.ui.slider_persistence.value() * 1024 * 1024 slide_value = self.ui.slider_persistence.value() * 1024 * 1024
@ -450,7 +466,7 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
copy_mbusb_dir_usb(config.usb_disk) copy_mbusb_dir_usb(config.usb_disk)
if not os.path.exists(os.path.join(config.usb_mount, "multibootusb", iso_basename(config.image_path))): if not os.path.exists(os.path.join(config.usb_mount, "multibootusb", iso_basename(config.image_path))):
config.persistence = self.ui.slider_persistence.value() * 1024 * 1024 config.persistence = self.ui.slider_persistence.value() * 1024 * 1024
log("Persistence chosen is " + str(config.persistence) + " MB") log("Persistence chosen is " + str(bytes2human(config.persistence)) + " MB")
install_size = iso_size(config.image_path) + config.persistence install_size = iso_size(config.image_path) + config.persistence
if install_size >= disk_usage(config.usb_mount).free: if install_size >= disk_usage(config.usb_mount).free:
log("ERROR: Not enough space available on " + config.usb_disk) log("ERROR: Not enough space available on " + config.usb_disk)

View File

@ -16,40 +16,42 @@ from . import iso
from . import gen from . import gen
from . import config from . import config
def max_disk_persistence(usb_disk):
"""
Detect max persistence value for filesystem on usb_disk
:param usb_disk: Disk filesystem to check
:return: Max persistence supported (bytes)
"""
assert usb_disk is not None
def persistence_distro(distro, usb_disk, iso_link): fat_max_size = (4096 * 1024 * 1024)
usb_details = usb.details(usb_disk)
config.usb_uuid = usb_details['uuid']
config.usb_label = usb_details['label']
if usb_details['file_system'] in ['vfat', 'FAT32'] and usb_details['size_free'] > fat_max_size:
_max_size = fat_max_size
else:
_max_size = usb_details['size_free']
return _max_size
def persistence_distro(distro, iso_link):
""" """
Function to detect if distro can have persistence option. Function to detect if distro can have persistence option.
:param distro: Detected distro name. :param distro: Detected distro name.
:return: Distro name as string or None otherwise. :return: Distro name as string or None otherwise.
""" """
assert distro is not None
assert iso_link is not None
iso_size = iso.iso_size(iso_link) iso_size = iso.iso_size(iso_link)
fat_max_size = (4096 * 1024 * 1024)
usb_details = usb.details(usb_disk) if distro in ["ubuntu", "debian", "debian-install", "fedora"]:
usb_sf = usb_details['file_system']
usb_free_size = usb_details['size_free']
config.usb_uuid = usb_details['uuid']
config.usb_label = usb_details['label']
if usb_sf == 'vfat' or 'FAT32':
if usb_free_size > fat_max_size:
_max_size = fat_max_size
else:
_max_size = usb_free_size
else:
_max_size = usb_free_size
if distro == "ubuntu":
gen.log("Persistence option is available.") gen.log("Persistence option is available.")
return "ubuntu", _max_size return distro
# FIXME to get debian persistence workable...
# Able to add successfully but unable to keep persistence data.
elif distro == "debian" or distro == "debian-install":
gen.log("Persistence option is available.")
return "debian", _max_size
elif distro == "fedora":
gen.log("Persistence option is available.")
return "fedora", _max_size
else: else:
return None, None return None
def create_persistence(): def create_persistence():