mirror of
https://github.com/mbusb/multibootusb
synced 2024-11-01 15:40:16 +00:00
Merge pull request #124 from alindt/all-drives
re-enable "All drives" functionality
This commit is contained in:
commit
df9779935f
@ -52,8 +52,7 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
config.image_path = None
|
||||
|
||||
# Main Tab
|
||||
self.ui.checkbox_all_drives.setVisible(False)
|
||||
# FIXME self.ui.checkbox_all_drives.clicked.connect(self.add_device)
|
||||
self.ui.checkbox_all_drives.clicked.connect(self.onAllDrivesClicked)
|
||||
self.ui.button_detect_drives.clicked.connect(self.onRefreshClick)
|
||||
self.ui.action_Quit.triggered.connect(self.on_close_Click)
|
||||
self.ui.action_About.triggered.connect(self.onAboutClick)
|
||||
@ -96,34 +95,27 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.progress_thread_dd.finished.connect(self.dd_finished)
|
||||
self.progress_thread_dd.status.connect(self.ui.statusbar.showMessage)
|
||||
|
||||
|
||||
# FIXME
|
||||
# self.add_device()
|
||||
prepare_mbusb_host_dir()
|
||||
self.onRefreshClick()
|
||||
|
||||
# def add_device(self):
|
||||
# """
|
||||
# Adds list of available USB devices to GUI combobox.
|
||||
# :return:
|
||||
# """
|
||||
# self.ui.combo_drives.clear()
|
||||
# if self.ui.checkbox_all_drives.isChecked():
|
||||
# detected_device = usb.list_devices(partition=1, fixed=True)
|
||||
# else:
|
||||
# detected_device = usb.list_devices()
|
||||
# if bool(detected_device):
|
||||
# for device in detected_device:
|
||||
# self.ui.combo_drives.addItem(str(device))
|
||||
# # if self.ui.combo_drives.currentText():
|
||||
# # self.onComboChange()
|
||||
#
|
||||
# # FIXME
|
||||
# # imager_detected_device = Imager.imager_list_usb(partition=0)
|
||||
# # if bool(imager_detected_device):
|
||||
# # for disk in imager_detected_device:
|
||||
# # self.ui.comboBox_2.addItem(str(disk))
|
||||
# # self.onImagerComboChange()
|
||||
def onAllDrivesClicked(self):
|
||||
"""
|
||||
Include fixed drives to available USB devices.
|
||||
:return:
|
||||
"""
|
||||
if self.ui.checkbox_all_drives.isChecked() is False:
|
||||
return
|
||||
|
||||
reply = QtWidgets.QMessageBox.warning(self, "WARNING!",
|
||||
"This option enables working with fixed drives\n\
|
||||
and is potentially VERY DANGEROUS\n\n\
|
||||
Are you SURE you want to enable it?",
|
||||
QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
|
||||
|
||||
if reply == QtWidgets.QMessageBox.No:
|
||||
self.ui.checkbox_all_drives.setChecked(False)
|
||||
elif reply == QtWidgets.QMessageBox.Yes:
|
||||
self.ui.checkbox_all_drives.setChecked(True)
|
||||
|
||||
def onAboutClick(self):
|
||||
about = QtWidgets.QDialog()
|
||||
@ -177,7 +169,6 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
log("No USB disk found...")
|
||||
|
||||
|
||||
def onRefreshClick(self):
|
||||
"""
|
||||
Calls function to detect USB devices.
|
||||
@ -201,29 +192,17 @@ class AppGui(qemu.Qemu, Imager, QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
# self.ui.usb_mount.clear()
|
||||
# self.ui.label_usb_mount.setVisible(False)
|
||||
|
||||
# self.add_device()
|
||||
self.ui.combo_drives.clear()
|
||||
if self.ui.checkbox_all_drives.isChecked():
|
||||
detected_devices = usb.list_devices(partition=1, fixed=True)
|
||||
else:
|
||||
detected_devices = usb.list_devices()
|
||||
|
||||
if detected_devices:
|
||||
for device in detected_devices:
|
||||
if platform.system() == 'Windows':
|
||||
self.ui.combo_drives.addItem(str(device))
|
||||
else:
|
||||
self.ui.combo_drives.addItem(str(device["DEVNAME"]))
|
||||
# if self.ui.combo_drives.currentText():
|
||||
# self.onComboChange()
|
||||
self.ui.combo_drives.setCurrentIndex(0)
|
||||
|
||||
# FIXME
|
||||
# imager_detected_device = Imager.imager_list_usb(partition=0)
|
||||
# if bool(imager_detected_device):
|
||||
# for disk in imager_detected_device:
|
||||
# self.ui.comboBox_2.addItem(str(disk))
|
||||
# self.onImagerComboChange()
|
||||
|
||||
def update_list_box(self, usb_disk):
|
||||
"""
|
||||
Updates listbox with installed distros on selected USB disk.
|
||||
|
@ -85,7 +85,7 @@ def disk_usage(mount_path):
|
||||
raise NotImplementedError("Platform not supported.")
|
||||
|
||||
|
||||
def list_devices(partition=1, fixed=None):
|
||||
def list_devices(partition=1, fixed=False):
|
||||
"""
|
||||
List inserted USB devices.
|
||||
:return: USB devices as list.
|
||||
@ -97,25 +97,17 @@ def list_devices(partition=1, fixed=None):
|
||||
gen.log("Using pyudev for detecting USB drives...")
|
||||
import pyudev
|
||||
context = pyudev.Context()
|
||||
# if fixed is None:
|
||||
# for device in context.list_devices(subsystem='block', DEVTYPE='partition',
|
||||
# ID_FS_USAGE="filesystem", ID_TYPE="disk",
|
||||
# ID_BUS="usb"):
|
||||
# # if device['ID_BUS'] == "usb" and device['DEVTYPE'] == "partition":
|
||||
# if device.get('ID_BUS') in ("usb", "scsi") and device.get('DEVTYPE') == "partition":
|
||||
# # gen.log(device['DEVNAME'])
|
||||
# devices.append(str(device['DEVNAME']))
|
||||
# else:
|
||||
# for device in context.list_devices(subsystem='block', DEVTYPE='partition'):
|
||||
# devices.append(str(device['DEVNAME']))
|
||||
for device in context.list_devices(subsystem='block',
|
||||
ID_FS_USAGE="filesystem",
|
||||
ID_TYPE="disk",
|
||||
ID_BUS="usb"):
|
||||
if device.get('ID_BUS') in ("usb", "scsi"):
|
||||
|
||||
if fixed is True:
|
||||
for device in context.list_devices(subsystem='block'):
|
||||
if device.get('ID_BUS') in ("usb", "scsi", "ata") and device['DEVTYPE'] in ['disk', 'partition']:
|
||||
devices.append(str(device['DEVNAME']))
|
||||
gen.log("\t" + device['DEVNAME'])
|
||||
else:
|
||||
for device in context.list_devices(subsystem='block', ID_BUS="usb"):
|
||||
devices.append(str(device['DEVNAME']))
|
||||
gen.log("\t" + device['DEVNAME'])
|
||||
# devices.append(str(device['DEVNAME']))
|
||||
devices.append(device)
|
||||
|
||||
except:
|
||||
import dbus
|
||||
bus = dbus.SystemBus()
|
||||
@ -159,8 +151,10 @@ def list_devices(partition=1, fixed=None):
|
||||
except:
|
||||
gen.log("No USB device found...")
|
||||
|
||||
devices.sort()
|
||||
|
||||
elif platform.system() == "Windows":
|
||||
if fixed is not None:
|
||||
if fixed is True:
|
||||
for drive in psutil.disk_partitions():
|
||||
if 'cdrom' in drive.opts or drive.fstype == '':
|
||||
# Skip cdrom drives or the disk with no filesystem
|
||||
|
Loading…
Reference in New Issue
Block a user