Skip to content

Commit 1e0503d

Browse files
committed
Fix mounted polling for USBStick
1 parent 4efb5ba commit 1e0503d

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

software/openbookscanner/states/usbstick.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def poll(self):
4747
"""Check if USBStick is still mounted"""
4848
p = subprocess.run(["mount"], stdout=subprocess.PIPE)
4949
path = self.path.encode()
50-
if path not in p.stdout:
50+
if path not in p.stdout or not self.state_machine.is_plugged_in():
5151
self.transition_into(UnMounted())
5252
for line in p.stdout.splitlines():
5353
if path in line and not b"(rw" in line:
@@ -74,13 +74,14 @@ class NoSpaceLeft(FinalState, USBStickState):
7474

7575
class USBStick(StateMachine):
7676

77-
def __init__(self, device):
77+
def __init__(self, device, listener):
7878
"""Create a new USB device.
7979
8080
- device: is a path to a device in /dev/
8181
"""
8282
super().__init__()
8383
self._device = device
84+
self.listener = listener
8485
self.transition_into(PluggedIn())
8586

8687
def __repr__(self):
@@ -105,3 +106,6 @@ def is_scanner(self):
105106
def get_mount_partition_path(self):
106107
return "/dev/" + self._device + "1"
107108

109+
def is_plugged_in(self):
110+
return self._device in self.listener.get_block_devices()
111+

software/openbookscanner/states/usbstick_listener.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ class USBStickListener(HardwareListener):
1818
def __init__(self):
1919
super().__init__()
2020

21-
'''
22-
p = subprocess.run(["lsblk | grep disk"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23-
try:
24-
p.check_returncode()
25-
except CalledProcessError:
26-
# TODO: Raise the exception purposefully
27-
raise
28-
# Maybe with: self.transition_into(InitializationFailed())
29-
30-
#self._block_devices = set([line.split()[0].decode() for line in p.stdout.splitlines()])
31-
'''
32-
3321
self._block_devices = self.get_block_devices()
3422

3523
def get_block_devices(self):
@@ -44,11 +32,9 @@ def has_driver_support(self):
4432
def listen_for_hardware(self):
4533

4634
new_block_devices = self.get_block_devices()
47-
print(new_block_devices)
4835

4936
for new_block_device in new_block_devices.difference(self._block_devices):
50-
print('Found new block device')
51-
self.found_new_hardware(USBStick(new_block_device))
37+
self.found_new_hardware(USBStick(new_block_device, self))
5238

5339
self._block_devices = new_block_devices
5440

0 commit comments

Comments
 (0)