From 95bc25e0ad0236bfe3cc6b08d2737c16cbef586a Mon Sep 17 00:00:00 2001 From: Ferelith-maker <83234598+Ferelith-maker@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:11:52 -0600 Subject: [PATCH] GUI unmount exception (#13) * subprocess w/ shell=true for error missing file * unmount test * mount/unmount for Linux works now * windows unmount check * Move comment - Windows mount/unmount WIP * Windows cmd WIP * Winodws subprocess revert - admin isssues WIP * Wrap service install with Try Except * revert check=True to false - for service install --- gui/mountPrimaryWindow.py | 49 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/gui/mountPrimaryWindow.py b/gui/mountPrimaryWindow.py index d7db4b8f4..fb25c2805 100644 --- a/gui/mountPrimaryWindow.py +++ b/gui/mountPrimaryWindow.py @@ -83,13 +83,17 @@ def windowsServiceInstall(self): # Use the completedProcess object in mount var to determine next steps # if service already installed, run cloudfuse.exe service start # if start successful, run cloudfuse.exe service mount - - mount = subprocess.run([".\cloudfuse.exe", "service", "install"], capture_output=True, check=False) - if mount.returncode == 0 or mount.stderr.decode().find("cloudfuse service already exists") != -1: #we found this message - mount = (subprocess.run([".\cloudfuse.exe", "service", "start"], capture_output=True)) - if mount.stderr.decode().find("An instance of the service is already running.") != -1: + + try: + windowsServiceCmd = subprocess.run([".\cloudfuse.exe", "service", "install"], capture_output=True, check=False) + except: + return False + + if windowsServiceCmd.returncode == 0 or windowsServiceCmd.stderr.decode().find("cloudfuse service already exists") != -1: #we found this message + windowsServiceCmd = (subprocess.run([".\cloudfuse.exe", "service", "start"], capture_output=True)) + if windowsServiceCmd.stderr.decode().find("An instance of the service is already running.") != -1: return True - elif mount.returncode == 1: + elif windowsServiceCmd.returncode == 1: self.textEdit_output.setText("!!Error starting service before mounting container!!\n")# + mount.stdout.decode()) # Get the users attention by popping open a new window on an error msg.setWindowTitle("Error") @@ -123,13 +127,14 @@ def mountBucket(self): if platform == "win32": # Windows mount has a quirk where the folder shouldn't exist yet, # add CloudFuse at the end of the directory - directory = directory+'/cloudFuse' + directory = directory+'\cloudFuse' # Install and start the service isRunning = self.windowsServiceInstall() if isRunning: - mount = (subprocess.run([".\cloudfuse.exe", "service", "mount", directory, "--config-file=.\config.yaml"], capture_output=True)) + # ".\cloudfuse.exe", "service", "mount", directory, "--config-file=.\config.yaml" + mount = (subprocess.run([".\cloudfuse.exe","service","mount", directory,"--config-file=.\config.yaml"],capture_output=True)) if mount.returncode == 0: self.textEdit_output.setText("Successfully mounted container\n") elif mount.stderr.decode().find("mount path exists") != -1: @@ -150,15 +155,19 @@ def mountBucket(self): # TODO: For future use to get output on Popen # for line in mount.stdout.readlines(): else: - mount = subprocess.run(["./cloudfuse", "mount", directory, "--config-file=./config.yaml"], capture_output=True) + # Create the mount command to send to subprocess. If shell=True is set and the command is not in one string + # the subprocess will interpret the additional arguments as separate commands. + cmd = "./cloudfuse mount " + directory + " --config-file=./config.yaml" + mount = subprocess.run([cmd], shell=True, capture_output=True) + # Print to the text edit window the results of the mount if mount.returncode == 0: self.textEdit_output.setText("Successfully mounted container\n") else: - self.textEdit_output.setText("!!Error mounting container!!\n")# + mount.stdout.decode()) + self.textEdit_output.setText("!!Error mounting container!!\n" + mount.stderr.decode()) # Get the users attention by popping open a new window on an error msg.setWindowTitle("Error") - msg.setText("Error mounting container - check the settings and try again") + msg.setText("Error mounting container - check the settings and try again\n" + mount.stderr.decode()) # Show the message box msg.exec() except ValueError: @@ -169,15 +178,23 @@ def unmountBucket(self): directory = str(self.lineEdit_mountPoint.text()) # TODO: properly handle unmount. This is relying on the line_edit not being changed by the user. try: - directory = directory+'/cloudFuse' - unmount = (subprocess.run([".\cloudfuse", "service", "unmount", directory], capture_output=True)) + if platform == "win32": + # for windows, 'cloudfuse' was added to the directory so add it back in for umount + directory = directory+'/cloudFuse' + unmount = subprocess.run([".\cloudfuse.exe", "service", "unmount", directory], shell=True, capture_output=True) + else: + # Create the mount command to send to subprocess. If shell=True is set and the command is not in one string + # the subprocess will interpret the additional arguments as separate commands. + cmd = "./cloudfuse unmount " + directory + unmount = subprocess.run([cmd], shell=True, capture_output=True) + # Print to the text edit window the results of the unmount if unmount.returncode == 0: - self.textEdit_output.setText("Successfully unmounted container\n" + unmount.stdout.decode()) + self.textEdit_output.setText("Successfully unmounted container\n" + unmount.stderr.decode()) else: - self.textEdit_output.setText("!!Error unmounting container!!\n" + unmount.stdout.decode()) + self.textEdit_output.setText("!!Error unmounting container!!\n" + unmount.stderr.decode()) msg.setWindowTitle("Error") - msg.setText("Error unmounting container - check the logs") + msg.setText("Error unmounting container - check the logs\n" + unmount.stderr.decode()) # Show the message box msg.exec() except ValueError: