1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-07-19 13:29:42 +02:00

firsts tests

This commit is contained in:
dbarzin 2022-06-11 16:26:40 +02:00
parent 06a23b94f0
commit ffa508a783
4 changed files with 99 additions and 1 deletions

34
tests/detect-usb.py Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/python3
import pyudev
import psutil
import time
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by('block')
# enumerate at device connection
for device in iter(monitor.poll, None):
if 'ID_FS_TYPE' in device:
if device.action == 'add':
if device.device_node[5:7] == 'sd':
print("New device {}".format(device.device_node))
# loop until device is mounted
found=False
loop=0
while (not found) and (loop<10):
# need to sleep before devide is mounted
time.sleep(1)
for partition in psutil.disk_partitions():
if partition.device == device.device_node:
print("Mounted at {}".format(partition.mountpoint))
found=True
loop+=1
if device.action == 'remove':
if device.device_node[5:7] == 'sd':
print('Device removed')