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