mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-23 15:29:43 +02:00
work in progress
This commit is contained in:
parent
1a29d021cf
commit
8191e075cf
2 changed files with 70 additions and 66 deletions
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
"""Pandora-Box is a USB scaning station based on Pandora."""
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
import pypandora
|
import pypandora
|
||||||
import time
|
import time
|
||||||
|
@ -21,8 +23,8 @@ PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
||||||
# Screen
|
# Screen
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
|
"""Initialise curses"""
|
||||||
def intitCurses():
|
def intit_curses():
|
||||||
global screen
|
global screen
|
||||||
screen = curses.initscr()
|
screen = curses.initscr()
|
||||||
screen.keypad(1)
|
screen.keypad(1)
|
||||||
|
@ -33,28 +35,33 @@ def intitCurses():
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
|
||||||
|
|
||||||
def printStatus(strStatus):
|
"""Print status string"""
|
||||||
|
def print_status(strStatus):
|
||||||
screen.addstr(12, 0, "Status : %-32s" % strStatus)
|
screen.addstr(12, 0, "Status : %-32s" % strStatus)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
|
|
||||||
def printFSLabel(strLabel):
|
"""Print FS Label"""
|
||||||
|
def print_fslabel(strLabel):
|
||||||
screen.addstr(13, 0, "Device : %-32s" % strLabel)
|
screen.addstr(13, 0, "Device : %-32s" % strLabel)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
|
|
||||||
def printAction(strAction):
|
"""Print current action"""
|
||||||
|
def print_action(strAction):
|
||||||
screen.addstr(14, 0, "Action : %-64s" % strAction)
|
screen.addstr(14, 0, "Action : %-64s" % strAction)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
|
|
||||||
def initBar():
|
"""Initialise progress bar"""
|
||||||
|
def init_bar():
|
||||||
global progress_win
|
global progress_win
|
||||||
progress_win = curses.newwin(3, 62, 3, 16)
|
progress_win = curses.newwin(3, 62, 3, 16)
|
||||||
progress_win.border(0)
|
progress_win.border(0)
|
||||||
|
|
||||||
|
|
||||||
def updateBar(progress):
|
"""Update progress bar"""
|
||||||
|
def update_bar(progress):
|
||||||
global progress_win
|
global progress_win
|
||||||
rangex = (60 / float(100)) * progress
|
rangex = (60 / float(100)) * progress
|
||||||
pos = int(rangex)
|
pos = int(rangex)
|
||||||
|
@ -64,7 +71,7 @@ def updateBar(progress):
|
||||||
progress_win.refresh()
|
progress_win.refresh()
|
||||||
|
|
||||||
|
|
||||||
def printScreen():
|
def print_screen():
|
||||||
screen.addstr(1, 0, " ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒")
|
screen.addstr(1, 0, " ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒")
|
||||||
screen.addstr(2, 0, " ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░")
|
screen.addstr(2, 0, " ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░")
|
||||||
screen.addstr(3, 0, " ▓██░ ██▓▒▒██ ▀█▄ ▓██ ▀█ ██▒░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▒██▒ ▄██▒██░ ██▒░░ █ ░")
|
screen.addstr(3, 0, " ▓██░ ██▓▒▒██ ▀█▄ ▓██ ▀█ ██▒░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▒██▒ ▄██▒██░ ██▒░░ █ ░")
|
||||||
|
@ -75,14 +82,14 @@ def printScreen():
|
||||||
screen.addstr(8, 0, " ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ")
|
screen.addstr(8, 0, " ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ")
|
||||||
screen.addstr(9, 0, " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ")
|
screen.addstr(9, 0, " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ")
|
||||||
screen.addstr(10, 0, " ░ ░ ")
|
screen.addstr(10, 0, " ░ ░ ")
|
||||||
printStatus("WAITING")
|
print_status("WAITING")
|
||||||
printFSLabel("")
|
print_fslabel("")
|
||||||
printAction("")
|
print_action("")
|
||||||
initBar()
|
init_bar()
|
||||||
updateBar(1)
|
update_bar(1)
|
||||||
|
|
||||||
|
|
||||||
def endCurses():
|
def end_curses():
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
curses.flushinp()
|
curses.flushinp()
|
||||||
|
|
||||||
|
@ -92,7 +99,7 @@ def endCurses():
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def mountDevice(device):
|
def mount_device(device):
|
||||||
if USB_AUTO_MOUNT:
|
if USB_AUTO_MOUNT:
|
||||||
found = False
|
found = False
|
||||||
loop = 0
|
loop = 0
|
||||||
|
@ -101,42 +108,40 @@ def mountDevice(device):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
for partition in psutil.disk_partitions():
|
for partition in psutil.disk_partitions():
|
||||||
if partition.device == device.device_node:
|
if partition.device == device.device_node:
|
||||||
printAction("Mounted at {}".format(partition.mountpoint))
|
print_action("Mounted at {}".format(partition.mountpoint))
|
||||||
found = True
|
found = True
|
||||||
loop += 1
|
loop += 1
|
||||||
else:
|
else:
|
||||||
printAction("mount device to /media/box")
|
print_action("mount device to /media/box")
|
||||||
res = os.system("pmount " + device.device_node + " box")
|
res = os.system("pmount " + device.device_node + " box")
|
||||||
# print("Return type: ", res)
|
# print("Return type: ", res)
|
||||||
|
|
||||||
|
|
||||||
def umountDevice():
|
def umount_device():
|
||||||
if not USB_AUTO_MOUNT:
|
if not USB_AUTO_MOUNT:
|
||||||
printAction("unmount device /media/box")
|
print_action("unmount device /media/box")
|
||||||
res = os.system("pumount /media/box")
|
res = os.system("pumount /media/box")
|
||||||
# print("Return type: ", res)
|
# print("Return type: ", res)
|
||||||
|
|
||||||
|
|
||||||
def deviceLoop():
|
def device_loop():
|
||||||
context = pyudev.Context()
|
context = pyudev.Context()
|
||||||
monitor = pyudev.Monitor.from_netlink(context)
|
monitor = pyudev.Monitor.from_netlink(context)
|
||||||
monitor.filter_by("block")
|
monitor.filter_by("block")
|
||||||
for device in iter(monitor.poll, None):
|
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.action == "add":
|
||||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
|
||||||
# print("New device {}".format(device.device_node))
|
# print("New device {}".format(device.device_node))
|
||||||
mountDevice(device)
|
mount_device(device)
|
||||||
# display device type
|
# display device type
|
||||||
printStatus("KEY INSERTED")
|
print_status("KEY INSERTED")
|
||||||
printFSLabel(device.get("ID_FS_LABEL"))
|
print_fslabel(device.get("ID_FS_LABEL"))
|
||||||
|
|
||||||
if device.action == "remove":
|
if device.action == "remove":
|
||||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
print_status("WAITING")
|
||||||
printStatus("WAITING")
|
print_action("Device removed")
|
||||||
printAction("Device removed")
|
print_fslabel("")
|
||||||
printFSLabel("")
|
umount_device()
|
||||||
umountDevice()
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
@ -168,18 +173,18 @@ def scan(mountPoint):
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def pandoraBox():
|
def pandorabox():
|
||||||
try:
|
try:
|
||||||
intitCurses()
|
intit_curses()
|
||||||
printScreen()
|
print_screen()
|
||||||
deviceLoop()
|
device_loop()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
endCurses()
|
end_curses()
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pandoraBox()
|
pandorabox()
|
|
@ -9,7 +9,7 @@ context = pyudev.Context()
|
||||||
monitor = pyudev.Monitor.from_netlink(context)
|
monitor = pyudev.Monitor.from_netlink(context)
|
||||||
monitor.filter_by("block")
|
monitor.filter_by("block")
|
||||||
|
|
||||||
autoMount = False
|
AUTO_MOUNT = True
|
||||||
|
|
||||||
|
|
||||||
def printDeviceInfo(dev):
|
def printDeviceInfo(dev):
|
||||||
|
@ -26,19 +26,19 @@ def printDeviceInfo(dev):
|
||||||
print("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE"))
|
print("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE"))
|
||||||
print("USB driver: %s" % dev.get("ID_USB_DRIVER"))
|
print("USB driver: %s" % dev.get("ID_USB_DRIVER"))
|
||||||
print("Path id: %s" % dev.get("ID_PATH"))
|
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("</BLOCK INFORMATION>")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
# enumerate at device connection
|
# enumerate at device connection
|
||||||
for device in iter(monitor.poll, None):
|
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.action == "add":
|
||||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
|
||||||
printDeviceInfo(device)
|
printDeviceInfo(device)
|
||||||
print("New device {}".format(device.device_node))
|
print("New device {}".format(device.device_node))
|
||||||
# loop until device is mounted
|
# loop until device is mounted
|
||||||
if autoMount:
|
if AUTO_MOUNT:
|
||||||
found = False
|
found = False
|
||||||
loop = 0
|
loop = 0
|
||||||
while (not found) and (loop < 10):
|
while (not found) and (loop < 10):
|
||||||
|
@ -55,9 +55,8 @@ for device in iter(monitor.poll, None):
|
||||||
print("Return type: ", res)
|
print("Return type: ", res)
|
||||||
|
|
||||||
if device.action == "remove":
|
if device.action == "remove":
|
||||||
if device.device_node[5:7] == "sd" and device.get("DEVTYPE") == "partition":
|
|
||||||
print("Device removed")
|
print("Device removed")
|
||||||
if not autoMount:
|
if not AUTO_MOUNT:
|
||||||
print("unmount device /media/box")
|
print("unmount device /media/box")
|
||||||
res = os.system("pumount /media/box")
|
res = os.system("pumount /media/box")
|
||||||
print("Return type: ", res)
|
print("Return type: ", res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue