mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-23 07:19:42 +02:00
work in progress
This commit is contained in:
parent
e5c781ad47
commit
7134251bb3
3 changed files with 100 additions and 18 deletions
|
@ -4,6 +4,17 @@ import curses
|
||||||
import pypandora
|
import pypandora
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import pyudev
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
#-----------------------------------------------------------
|
||||||
|
# Variables
|
||||||
|
#-----------------------------------------------------------
|
||||||
|
|
||||||
|
NO_SCAN=True
|
||||||
|
USB_AUTO_MOUNT=True
|
||||||
|
PANDORA_ROOT_URL="http://127.0.0.1:6100"
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------
|
#-----------------------------------------------------------
|
||||||
# Screen
|
# Screen
|
||||||
|
@ -19,6 +30,32 @@ def intitCurses():
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
|
||||||
|
def printStatus(strStatus):
|
||||||
|
screen.addstr(12,0,'Status : %-32s' % strStatus)
|
||||||
|
screen.refresh()
|
||||||
|
|
||||||
|
def printFSLabel(strLabel):
|
||||||
|
screen.addstr(13,0,'Device : %-32s' % strLabel)
|
||||||
|
screen.refresh()
|
||||||
|
|
||||||
|
def printAction(strAction):
|
||||||
|
screen.addstr(14,0,'Action : %-64s' % strAction)
|
||||||
|
screen.refresh()
|
||||||
|
|
||||||
|
def initBar():
|
||||||
|
global progress_win
|
||||||
|
progress_win = curses.newwin(3, 62, 3, 16)
|
||||||
|
progress_win.border(0)
|
||||||
|
|
||||||
|
def updateBar(progress):
|
||||||
|
global progress_win
|
||||||
|
rangex = (60 / float(100)) * progress
|
||||||
|
pos = int(rangex)
|
||||||
|
display = '#'
|
||||||
|
if pos != 0:
|
||||||
|
progress_win.addstr(1, pos, "{}".format(display))
|
||||||
|
progress_win.refresh()
|
||||||
|
|
||||||
def printScreen():
|
def printScreen():
|
||||||
screen.addstr(1,0," ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒")
|
screen.addstr(1,0," ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒")
|
||||||
screen.addstr(2,0," ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░")
|
screen.addstr(2,0," ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░")
|
||||||
|
@ -30,7 +67,11 @@ 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," ░ ░ ")
|
||||||
screen.addstr(11,0,"READY.");
|
printStatus("WAITING")
|
||||||
|
printFSLabel('')
|
||||||
|
printAction('')
|
||||||
|
initBar()
|
||||||
|
updateBar(1)
|
||||||
|
|
||||||
def endCurses():
|
def endCurses():
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
@ -42,8 +83,7 @@ def endCurses():
|
||||||
|
|
||||||
# mount device
|
# mount device
|
||||||
def mountDevice(device):
|
def mountDevice(device):
|
||||||
global autoMount
|
if USB_AUTO_MOUNT:
|
||||||
if autoMount:
|
|
||||||
found=False
|
found=False
|
||||||
loop=0
|
loop=0
|
||||||
while (not found) and (loop<10):
|
while (not found) and (loop<10):
|
||||||
|
@ -51,33 +91,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:
|
||||||
print("Mounted at {}".format(partition.mountpoint))
|
printAction("Mounted at {}".format(partition.mountpoint))
|
||||||
found=True
|
found=True
|
||||||
loop+=1
|
loop+=1
|
||||||
else:
|
else:
|
||||||
print("mount device to /media/box")
|
printAction("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)
|
||||||
|
|
||||||
# unmount device
|
# unmount device
|
||||||
def umountDevice(device):
|
def umountDevice():
|
||||||
if not autoMount:
|
if not USB_AUTO_MOUNT:
|
||||||
print("unmount device /media/box")
|
printAction("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 deviceLoop():
|
||||||
|
context = pyudev.Context()
|
||||||
|
monitor = pyudev.Monitor.from_netlink(context)
|
||||||
|
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 'ID_FS_TYPE' in device:
|
||||||
if device.action == 'add':
|
if device.action == 'add':
|
||||||
if device.device_node[5:7] == 'sd' and device.get('DEVTYPE')=='partition':
|
if device.device_node[5:7] == 'sd' and device.get('DEVTYPE')=='partition':
|
||||||
#printDeviceInfo(device)
|
#print("New device {}".format(device.device_node))
|
||||||
print("New device {}".format(device.device_node))
|
mountDevice(device)
|
||||||
mountDevice(device.device_node)
|
# display device type
|
||||||
|
printStatus("KEY INSERTED")
|
||||||
|
printFSLabel(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':
|
if device.device_node[5:7] == 'sd' and device.get('DEVTYPE')=='partition':
|
||||||
print('Device removed')
|
printStatus("WAITING")
|
||||||
|
printAction('Device removed')
|
||||||
|
printFSLabel('')
|
||||||
umountDevice()
|
umountDevice()
|
||||||
|
|
||||||
#-----------------------------------------------------------
|
#-----------------------------------------------------------
|
||||||
|
@ -86,7 +133,7 @@ def deviceLoop():
|
||||||
|
|
||||||
# scan device at mountPoint
|
# scan device at mountPoint
|
||||||
def scan(mountPoint):
|
def scan(mountPoint):
|
||||||
pp = pypandora.PyPandora(root_url= 'http://127.0.0.1:6100')
|
pp = pypandora.PyPandora(root_url= PANDORA_ROOT_URL)
|
||||||
|
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
print(arg,end='',flush=True)
|
print(arg,end='',flush=True)
|
||||||
|
@ -109,6 +156,8 @@ def scan(mountPoint):
|
||||||
intitCurses()
|
intitCurses()
|
||||||
printScreen()
|
printScreen()
|
||||||
|
|
||||||
|
deviceLoop()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
if key == curses.KEY_MOUSE:
|
if key == curses.KEY_MOUSE:
|
||||||
|
|
|
@ -11,7 +11,7 @@ monitor.filter_by('block')
|
||||||
|
|
||||||
autoMount=False
|
autoMount=False
|
||||||
|
|
||||||
def printInfo(dev):
|
def printDeviceInfo(dev):
|
||||||
print('')
|
print('')
|
||||||
print('<BLOCK INFORMATION>')
|
print('<BLOCK INFORMATION>')
|
||||||
print('Device name: %s' % dev.get('DEVNAME'))
|
print('Device name: %s' % dev.get('DEVNAME'))
|
||||||
|
@ -33,7 +33,7 @@ for device in iter(monitor.poll, None):
|
||||||
if 'ID_FS_TYPE' in device:
|
if 'ID_FS_TYPE' in device:
|
||||||
if device.action == 'add':
|
if device.action == 'add':
|
||||||
if device.device_node[5:7] == 'sd' and device.get('DEVTYPE')=='partition':
|
if device.device_node[5:7] == 'sd' and device.get('DEVTYPE')=='partition':
|
||||||
#printInfo(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 autoMount:
|
||||||
|
|
33
tests/progress-bar.py
Executable file
33
tests/progress-bar.py
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import curses
|
||||||
|
import time
|
||||||
|
|
||||||
|
curses.initscr()
|
||||||
|
|
||||||
|
def initBar():
|
||||||
|
global progress_win
|
||||||
|
progress_win = curses.newwin(3, 62, 3, 10)
|
||||||
|
progress_win.border(0)
|
||||||
|
|
||||||
|
def updateBar(progress):
|
||||||
|
global progress_win
|
||||||
|
rangex = (60 / float(100)) * progress
|
||||||
|
pos = int(rangex)
|
||||||
|
display = '#'
|
||||||
|
if pos != 0:
|
||||||
|
progress_win.addstr(1, pos, "{}".format(display))
|
||||||
|
progress_win.refresh()
|
||||||
|
|
||||||
|
initBar()
|
||||||
|
loading = 0
|
||||||
|
while loading < 100:
|
||||||
|
loading += 1
|
||||||
|
time.sleep(0.03)
|
||||||
|
updateBar(loading)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
curses.endwin()
|
||||||
|
curses.flushinp()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue