Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: Look for cloudfuse CLI in path #167

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/common_qt_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def setComponentSettings(self):
self.settings.setValue('foreground',False)

# Common
self.settings.setValue('allow-other',True)
self.settings.setValue('allow-other',False)
self.settings.setValue('read-only',False)
self.settings.setValue('nonempty',False)
self.settings.setValue('restricted-characters-windows',False) # not exposed
Expand Down
143 changes: 69 additions & 74 deletions gui/mountPrimaryWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import time
import yaml
from shutil import which

# Import QT libraries
from PySide6.QtCore import Qt, QSettings
Expand All @@ -42,6 +43,17 @@

bucketOptions = ['s3storage', 'azstorage']
mountTargetComponent = 3
cloudfuseCli = 'cloudfuse'
mountDirSuffix = ''
if platform == 'win32':
# on Windows, the cli command ends in '.exe'
cloudfuseCli += '.exe'
# on Windows, the mound directory must not exist before mounting,
# so name a non-existent subdirectory of the user-chosen path
mountDirSuffix = 'cloudFuse'
foodprocessor marked this conversation as resolved.
Show resolved Hide resolved
# if cloudfuse is not in the path, look for it in the current directory
if which(cloudfuseCli) is None:
cloudfuseCli = './' + cloudfuseCli

class FUSEWindow(QMainWindow, Ui_primaryFUSEwindow):
def __init__(self):
Expand All @@ -63,8 +75,7 @@ def __init__(self):
# Note: Different versions of Python don't like the embedded null character, send in the raw string instead
self.lineEdit_mountPoint.setValidator(QtGui.QRegularExpressionValidator(r'^[^\0]*$',self))


# Set up the signals for all the interactable intities
# Set up the signals for all the interactive entities
self.button_browse.clicked.connect(self.getFileDirInput)
self.button_config.clicked.connect(self.showSettingsWidget)
self.button_mount.clicked.connect(self.mountBucket)
Expand Down Expand Up @@ -112,7 +123,6 @@ def updateMountPointInSettings(self):
# There are unique settings per bucket selected for the pipeline,
# so we must use different widgets to show the different settings
def showSettingsWidget(self):

targetIndex = self.dropDown_bucketSelect.currentIndex()
if bucketOptions[targetIndex] == 's3storage':
self.settings = s3SettingsWidget()
Expand All @@ -136,10 +146,7 @@ def showAboutQtPage(self):

# Display the custom dialog box for the cloudfuse 'about' page.
def showAboutCloudFusePage(self):
if platform == "win32":
commandParts = ['cloudfuse.exe', '--version']
else:
commandParts = ['./cloudfuse', '--version']
commandParts = [cloudfuseCli, '--version']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)

if not executableFound:
Expand All @@ -156,91 +163,81 @@ def showUnderConstructionPage(self):
self.page = underConstruction()
self.page.show()


def mountBucket(self):

# get mount directory
try:
directory = str(self.lineEdit_mountPoint.text())
except ValueError as e:
self.addOutputText(f"Invalid mount path: {str(e)}")
return
directory = os.path.join(directory, mountDirSuffix)
# get config path
configPath = os.path.join(widgetFuncs.getWorkingDir(self), 'config.yaml')

# on Windows, the mount directory should not exist (yet)
if platform == "win32":
# Windows mount has a quirk where the folder shouldn't exist yet,
# add CloudFuse at the end of the directory
directory = os.path.join(directory,'cloudFuse')

# make sure the mount directory doesn't already exist
if os.path.exists(directory):
self.addOutputText(f"Directory {directory} already exists! Aborting new mount.")
self.errorMessageBox(f"Error: Cloudfuse needs to create the directory {directory}, but it already exists!")
return
# do a dry run to validate options and credentials
commandParts = ['cloudfuse.exe', 'mount', directory, f'--config-file={configPath}', '--dry-run']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if not executableFound:
self.addOutputText("cloudfuse.exe not found! Is it installed?")
self.errorMessageBox("Error running cloudfuse CLI - Please re-install Cloudfuse.")
return
if exitCode != 0:
self.addOutputText(stdErr)
self.errorMessageBox("Mount failed: " + stdErr)
return
if stdOut != "":
self.addOutputText(stdOut)

# do a dry run to validate options and credentials
commandParts = [cloudfuseCli, 'mount', directory, f'--config-file={configPath}', '--dry-run']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if not executableFound:
self.addOutputText("cloudfuse.exe not found! Is it installed?")
self.errorMessageBox("Error running cloudfuse CLI - Please re-install Cloudfuse.")
return

if exitCode != 0:
self.addOutputText(stdErr)
self.errorMessageBox("Mount failed: " + stdErr)
return

if stdOut != "":
self.addOutputText(stdOut)

# now actually mount
commandParts = ['cloudfuse.exe', 'mount', directory, f'--config-file={configPath}']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if not executableFound:
self.addOutputText("cloudfuse.exe not found! Is it installed?")
self.errorMessageBox("Error running cloudfuse CLI - Please re-install Cloudfuse.")
return

if exitCode != 0:
self.addOutputText(stdErr)
if stdErr.find("mount path exists") != -1:
self.errorMessageBox("This container is already mounted at this directory.")
return

if stdOut != "":
self.addOutputText(stdOut)

# wait for mount, then check that mount succeeded by verifying that the mount directory exists
self.addOutputText("Mount command successfully sent to Windows service.\nVerifying mount success...")
def verifyMountSuccess():
if not os.path.exists(directory):
self.addOutputText(f"Failed to create mount directory {directory}")
self.errorMessageBox("Mount failed. Please check error logs.")
else:
self.addOutputText("Successfully mounted container")
QtCore.QTimer.singleShot(4000, verifyMountSuccess)
else:
commandParts = ['./cloudfuse', 'mount', directory, f'--config-file={configPath}']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if exitCode != 0:
self.addOutputText(f"Error mounting container: {stdErr}")
# now actually mount
commandParts = [cloudfuseCli, 'mount', directory, f'--config-file={configPath}']
(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if not executableFound:
self.addOutputText("cloudfuse.exe not found! Is it installed?")
self.errorMessageBox("Error running cloudfuse CLI - Please re-install Cloudfuse.")
return

if exitCode != 0:
self.addOutputText(f"Error mounting container: {stdErr}")
if stdErr.find("mount path exists") != -1:
self.errorMessageBox("This container is already mounted at this directory.")
else:
self.errorMessageBox(f"Error mounting container - check the settings and try again\n{stdErr}")
return

self.addOutputText("Successfully mounted container\n")
return

if stdOut != "":
self.addOutputText(stdOut)

# wait for mount, then check that mount succeeded by verifying that the mount directory exists
self.addOutputText("Verifying mount success...")
def verifyMountSuccess():
if platform == 'win32':
success = os.path.exists(directory)
else:
success = os.path.ismount(directory)
if not success:
self.addOutputText(f"Failed to create mount directory {directory}")
self.errorMessageBox("Mount failed. Please check error logs.")
else:
self.addOutputText("Successfully mounted container")
QtCore.QTimer.singleShot(4000, verifyMountSuccess)

def unmountBucket(self):
directory = str(self.lineEdit_mountPoint.text())
commandParts = []
# TODO: properly handle unmount. This is relying on the line_edit not being changed by the user.

if platform == "win32":
# for windows, 'cloudfuse' was added to the directory so add it back in for umount
directory = os.path.join(directory, 'cloudFuse')
commandParts = "cloudfuse.exe unmount".split()
else:
commandParts = "./cloudfuse unmount --lazy".split()
commandParts.append(directory)
directory = os.path.join(directory, mountDirSuffix)
commandParts = [cloudfuseCli, "unmount", directory]
if platform != "win32":
commandParts.append("--lazy")

(stdOut, stdErr, exitCode, executableFound) = self.runCommand(commandParts)
if not executableFound:
Expand All @@ -252,8 +249,6 @@ def unmountBucket(self):
else:
self.addOutputText(f"Successfully unmounted container {stdErr}")



# This function reads in the config file, modifies the components section, then writes the config file back
def modifyPipeline(self):

Expand Down
Loading