Skip to content

Commit

Permalink
GUI unmount exception (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ferelith-maker authored Oct 10, 2023
1 parent 735d249 commit 95bc25e
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions gui/mountPrimaryWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 95bc25e

Please sign in to comment.