mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-24 07:49:42 +02:00
work in progress
This commit is contained in:
parent
1a29d021cf
commit
8191e075cf
2 changed files with 70 additions and 66 deletions
|
@ -9,7 +9,7 @@ context = pyudev.Context()
|
|||
monitor = pyudev.Monitor.from_netlink(context)
|
||||
monitor.filter_by("block")
|
||||
|
||||
autoMount = False
|
||||
AUTO_MOUNT = True
|
||||
|
||||
|
||||
def printDeviceInfo(dev):
|
||||
|
@ -26,38 +26,37 @@ def printDeviceInfo(dev):
|
|||
print("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE"))
|
||||
print("USB driver: %s" % dev.get("ID_USB_DRIVER"))
|
||||
print("Path id: %s" % dev.get("ID_PATH"))
|
||||
# print('Capacity: %s' % stdOut[0].strip())
|
||||
print('Usage: %s' % dev.get("ID_FS_USAGE"))
|
||||
print("</BLOCK INFORMATION>")
|
||||
print("")
|
||||
|
||||
|
||||
# enumerate at device connection
|
||||
for device in iter(monitor.poll, None):
|
||||
if "ID_FS_TYPE" in device:
|
||||
if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd":
|
||||
if device.action == "add":
|
||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
||||
printDeviceInfo(device)
|
||||
print("New device {}".format(device.device_node))
|
||||
# loop until device is mounted
|
||||
if autoMount:
|
||||
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
|
||||
else:
|
||||
print("mount device to /media/box")
|
||||
res = os.system("pmount " + device.device_node + " box")
|
||||
print("Return type: ", res)
|
||||
printDeviceInfo(device)
|
||||
print("New device {}".format(device.device_node))
|
||||
# loop until device is mounted
|
||||
if AUTO_MOUNT:
|
||||
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
|
||||
else:
|
||||
print("mount device to /media/box")
|
||||
res = os.system("pmount " + device.device_node + " box")
|
||||
print("Return type: ", res)
|
||||
|
||||
if device.action == "remove":
|
||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
||||
print("Device removed")
|
||||
if not autoMount:
|
||||
print("unmount device /media/box")
|
||||
res = os.system("pumount /media/box")
|
||||
print("Return type: ", res)
|
||||
print("Device removed")
|
||||
if not AUTO_MOUNT:
|
||||
print("unmount device /media/box")
|
||||
res = os.system("pumount /media/box")
|
||||
print("Return type: ", res)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue