Added final unmount and unmount on press when connected
This commit is contained in:
25
main.py
25
main.py
@@ -1,5 +1,6 @@
|
||||
from functools import partial
|
||||
import json
|
||||
from os import getuid
|
||||
from pathlib import Path
|
||||
from queue import Empty, Queue
|
||||
import subprocess
|
||||
@@ -59,7 +60,12 @@ def loadOrCreateConfig(path: Path) -> Config:
|
||||
|
||||
|
||||
def onButtonPressed(state: AppState) -> None:
|
||||
if state.diskState == "disconnected":
|
||||
state.diskState = "pairing"
|
||||
elif state.diskState == "pairing":
|
||||
state.diskState = "disconnected"
|
||||
elif state.diskState == "connected":
|
||||
unmountDisk(state)
|
||||
print("Changing disk state")
|
||||
|
||||
|
||||
@@ -153,6 +159,8 @@ def mountDisk(state: AppState) -> None:
|
||||
"mount",
|
||||
f"{node}1",
|
||||
f"/mnt/{state.config.diskSerial}",
|
||||
"-o",
|
||||
f"uid={getuid()}",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
@@ -162,6 +170,21 @@ def mountDisk(state: AppState) -> None:
|
||||
state.diskState = "connected"
|
||||
|
||||
|
||||
def unmountDisk(state: AppState) -> None:
|
||||
try:
|
||||
subprocess.run(
|
||||
[
|
||||
"umount",
|
||||
f"/mnt/{state.config.diskSerial}",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
else:
|
||||
state.diskState = "disconnected"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
try:
|
||||
state = AppState()
|
||||
@@ -214,6 +237,8 @@ def main() -> None:
|
||||
|
||||
finally:
|
||||
state.stopEvent.set()
|
||||
if state.diskState == "connected":
|
||||
unmountDisk(state)
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user