From 806941b3de09fa625b336b3c505d715a80c84bec Mon Sep 17 00:00:00 2001 From: Brennen Raimer <5969754+norweeg@users.noreply.github.com> Date: Thu, 9 May 2019 16:51:38 -0400 Subject: [PATCH] trying be a little more platform independant --- .../ui/installer_wizard.py | 19 ++++++++----------- .../validators/location_validator.py | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/portable_computing_toolkit_installer/ui/installer_wizard.py b/portable_computing_toolkit_installer/ui/installer_wizard.py index 7d3ece4..c80a809 100755 --- a/portable_computing_toolkit_installer/ui/installer_wizard.py +++ b/portable_computing_toolkit_installer/ui/installer_wizard.py @@ -17,11 +17,10 @@ from PyQt5 import QtCore, QtGui, QtNetwork, QtWebEngineWidgets, QtWidgets from PyQt5.uic import loadUi try: - import win32api import win32file except ImportError: if platform.system()=='Windows': - raise #require win32api and win32file on windows + raise #require win32file on windows from validators.location_validator import Location_Validator from .menu_iterator import MenuIterator @@ -74,17 +73,15 @@ class InstallerWizard(QtWidgets.QWizard): if no suitable external device is found """ if platform.system() == 'Windows': - drives = [drive for drive in win32api.GetLogicalDriveStrings().split('\0') if drive] - dialog_location = drives.pop() - while (win32file.GetDriveType(dialog_location) == win32file.DRIVE_CDROM - or win32file.GetDriveType(dialog_location) == win32file.DRIVE_REMOTE): - dialog_location = drives.pop() - if dialog_location == "C:\\": - dialog_location = Path.home() - break + #get all drives read-writable drives except C:\ + drives = [drive for drive in psutil.disk_partitions(all = True) if drive.device not in ("","C:\\") and "rw" in drive.opts] + if drives: #drives other than C:\ exist, are likely installation locations + dialog_location = Path(drives[0].mountpoint) + else: #C:\ was only drive, so start in user home + dialog_location = Path.home() else: dialog_location = Path.home() - + selected_location = QtWidgets.QFileDialog.getExistingDirectory(parent=self,caption="Select Location", directory=str(dialog_location), options=(QtWidgets.QFileDialog.ShowDirsOnly)) diff --git a/portable_computing_toolkit_installer/validators/location_validator.py b/portable_computing_toolkit_installer/validators/location_validator.py index 557c8c7..f08b8be 100644 --- a/portable_computing_toolkit_installer/validators/location_validator.py +++ b/portable_computing_toolkit_installer/validators/location_validator.py @@ -25,7 +25,7 @@ class Location_Validator(QtGui.QValidator): Arguments: location {str} -- A string representing a folder path """ - match = [drive for drive in psutil.disk_partitions() if (Path(drive.mountpoint) in Path(location).parents and drive.fstype.lower() == "ntfs")] + match = [drive for drive in psutil.disk_partitions(all = True) if (Path(drive.mountpoint) in Path(location).parents and drive.fstype.lower() == "ntfs")] if match: self._ntfs_location_selected = True return True