mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-19 21:39:40 +02:00
add logs
This commit is contained in:
parent
6c831b1e01
commit
27710ff92d
3 changed files with 82 additions and 25 deletions
104
pandorabox.py
104
pandorabox.py
|
@ -10,6 +10,7 @@ import sys
|
||||||
import pyudev
|
import pyudev
|
||||||
import psutil
|
import psutil
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Config variables
|
# Config variables
|
||||||
|
@ -73,7 +74,7 @@ def print_used(label):
|
||||||
|
|
||||||
def print_fstype(label):
|
def print_fstype(label):
|
||||||
global status_win
|
global status_win
|
||||||
status_win.addstr(1, 50, "FS Type : %-32s" % label, curses.color_pair(2))
|
status_win.addstr(1, 50, "Part / Type : %-32s" % label, curses.color_pair(2))
|
||||||
status_win.refresh()
|
status_win.refresh()
|
||||||
|
|
||||||
def print_model(label):
|
def print_model(label):
|
||||||
|
@ -89,7 +90,7 @@ def print_serial(label):
|
||||||
"""Initialise progress bar"""
|
"""Initialise progress bar"""
|
||||||
def init_bar():
|
def init_bar():
|
||||||
global progress_win
|
global progress_win
|
||||||
progress_win = curses.newwin(3, 83, 18, 10)
|
progress_win = curses.newwin(3, 83, 17, 10)
|
||||||
# progress_win.border(1)
|
# progress_win.border(1)
|
||||||
progress_win.refresh()
|
progress_win.refresh()
|
||||||
|
|
||||||
|
@ -97,8 +98,9 @@ def init_bar():
|
||||||
def update_bar(progress):
|
def update_bar(progress):
|
||||||
global progress_win
|
global progress_win
|
||||||
if progress == 0:
|
if progress == 0:
|
||||||
#progress_win.clear()
|
progress_win.clear()
|
||||||
progress_win.border(1)
|
progress_win.border(0)
|
||||||
|
time.sleep(0)
|
||||||
else:
|
else:
|
||||||
pos = (80 * progress) // 100
|
pos = (80 * progress) // 100
|
||||||
progress_win.addstr(1, pos+1, "#")
|
progress_win.addstr(1, pos+1, "#")
|
||||||
|
@ -106,12 +108,40 @@ def update_bar(progress):
|
||||||
|
|
||||||
def init_log():
|
def init_log():
|
||||||
global log_win
|
global log_win
|
||||||
log_win = curses.newwin(10, 101, 22, 0)
|
log_win = curses.newwin(16, 101, 20, 0)
|
||||||
log_win.border(0)
|
log_win.border(0)
|
||||||
|
logging.basicConfig(
|
||||||
|
filename='pandorabox.log',
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(message)s',
|
||||||
|
datefmt='%m/%d/%y %H:%M',
|
||||||
|
filemode='w'
|
||||||
|
)
|
||||||
|
|
||||||
|
logs = []
|
||||||
def log(str):
|
def log(str):
|
||||||
log_win.addstr(1,1,str,curses.color_pair(3))
|
log_win.addstr(1,1,str,curses.color_pair(3))
|
||||||
log_win.refresh()
|
log_win.refresh()
|
||||||
|
logging.info(str)
|
||||||
|
logs.append(str)
|
||||||
|
if len(logs)>15:
|
||||||
|
logs.pop(0)
|
||||||
|
for i in range(min(15,len(logs))):
|
||||||
|
log_win.addstr(i+1,1,"%-80s"%logs[i],curses.color_pair(3))
|
||||||
|
log_win.refresh()
|
||||||
|
|
||||||
|
"""Splash screen"""
|
||||||
|
s = [None] * 10;
|
||||||
|
s[0] = " ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒"
|
||||||
|
s[1] = " ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░"
|
||||||
|
s[2] = " ▓██░ ██▓▒▒██ ▀█▄ ▓██ ▀█ ██▒░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▒██▒ ▄██▒██░ ██▒░░ █ ░"
|
||||||
|
s[3] = " ▒██▄█▓▒ ▒░██▄▄▄▄██ ▓██▒ ▐▌██▒░▓█▄ ▌▒██ ██░▒██▀▀█▄ ░██▄▄▄▄██ ▒██░█▀ ▒██ ██░ ░ █ █ ▒ "
|
||||||
|
s[4] = " ▒██▒ ░ ░ ▓█ ▓██▒▒██░ ▓██░░▒████▓ ░ ████▓▒░░██▓ ▒██▒ ▓█ ▓██▒ ░▓█ ▀█▓░ ████▓▒░▒██▒ ▒██▒"
|
||||||
|
s[5] = " ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ░▒▓███▀▒░ ▒░▒░▒░ ▒▒ ░ ░▓ ░"
|
||||||
|
s[6] = " ░▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░ ░ ▒ ▒ ░ ▒ ▒░ ░▒ ░ ▒░ ▒ ▒▒ ░ ▒░▒ ░ ░ ▒ ▒░ ░░ ░▒ ░"
|
||||||
|
s[7] = " ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ▒ ░ ░ "
|
||||||
|
s[8] = " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ "
|
||||||
|
s[9] = " ░ ░ "
|
||||||
|
|
||||||
"""Print main screen"""
|
"""Print main screen"""
|
||||||
def print_screen():
|
def print_screen():
|
||||||
|
@ -120,21 +150,21 @@ def print_screen():
|
||||||
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
|
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
|
||||||
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
||||||
title_win = curses.newwin(12, 101, 0, 0)
|
title_win = curses.newwin(12, 101, 0, 0)
|
||||||
title_win.border(0)
|
# title_win.border(0)
|
||||||
title_win.addstr(1, 1, " ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒",curses.color_pair(1))
|
title_win.addstr(1, 1, s[0], curses.color_pair(1))
|
||||||
title_win.addstr(2, 1, " ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░",curses.color_pair(1))
|
title_win.addstr(2, 1, s[1], curses.color_pair(1))
|
||||||
title_win.addstr(3, 1, " ▓██░ ██▓▒▒██ ▀█▄ ▓██ ▀█ ██▒░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▒██▒ ▄██▒██░ ██▒░░ █ ░",curses.color_pair(1))
|
title_win.addstr(3, 1, s[2], curses.color_pair(1))
|
||||||
title_win.addstr(4, 1, " ▒██▄█▓▒ ▒░██▄▄▄▄██ ▓██▒ ▐▌██▒░▓█▄ ▌▒██ ██░▒██▀▀█▄ ░██▄▄▄▄██ ▒██░█▀ ▒██ ██░ ░ █ █ ▒ ",curses.color_pair(1))
|
title_win.addstr(4, 1, s[3], curses.color_pair(1))
|
||||||
title_win.addstr(5, 1, " ▒██▒ ░ ░ ▓█ ▓██▒▒██░ ▓██░░▒████▓ ░ ████▓▒░░██▓ ▒██▒ ▓█ ▓██▒ ░▓█ ▀█▓░ ████▓▒░▒██▒ ▒██▒",curses.color_pair(1))
|
title_win.addstr(5, 1, s[4], curses.color_pair(1))
|
||||||
title_win.addstr(6, 1, " ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ░▒▓███▀▒░ ▒░▒░▒░ ▒▒ ░ ░▓ ░",curses.color_pair(1))
|
title_win.addstr(6, 1, s[5], curses.color_pair(1))
|
||||||
title_win.addstr(7, 1, " ░▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░ ░ ▒ ▒ ░ ▒ ▒░ ░▒ ░ ▒░ ▒ ▒▒ ░ ▒░▒ ░ ░ ▒ ▒░ ░░ ░▒ ░",curses.color_pair(1))
|
title_win.addstr(7, 1, s[6], curses.color_pair(1))
|
||||||
title_win.addstr(8, 1, " ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ",curses.color_pair(1))
|
title_win.addstr(8, 1, s[7], curses.color_pair(1))
|
||||||
title_win.addstr(9, 1, " ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ",curses.color_pair(1))
|
title_win.addstr(9, 1, s[8], curses.color_pair(1))
|
||||||
title_win.addstr(10, 1, " ░ ░ ",curses.color_pair(1))
|
title_win.addstr(10, 1, s[9], curses.color_pair(1))
|
||||||
title_win.refresh()
|
title_win.refresh()
|
||||||
status_win = curses.newwin(5, 101, 12, 0)
|
status_win = curses.newwin(5, 101, 12, 0)
|
||||||
status_win.border(0)
|
status_win.border(0)
|
||||||
print_status("WAITING")
|
# print_status("WAITING")
|
||||||
print_fslabel("")
|
print_fslabel("")
|
||||||
print_size(0.0)
|
print_size(0.0)
|
||||||
print_used(0.0)
|
print_used(0.0)
|
||||||
|
@ -167,7 +197,7 @@ def mount_device(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_action("Mounted at {}".format(partition.mountpoint))
|
log("Device mounted at {}".format(partition.mountpoint))
|
||||||
found = True
|
found = True
|
||||||
loop += 1
|
loop += 1
|
||||||
if loop < 10:
|
if loop < 10:
|
||||||
|
@ -175,18 +205,18 @@ def mount_device(device):
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
print_action("mount device to /media/box")
|
|
||||||
res = os.system("pmount " + device.device_node + " box")
|
res = os.system("pmount " + device.device_node + " box")
|
||||||
if res == 1:
|
if res == 1:
|
||||||
return "/media/box"
|
return "/media/box"
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
log("Device mounted at /media/box")
|
||||||
|
|
||||||
|
|
||||||
"""Unmount USB device"""
|
"""Unmount USB device"""
|
||||||
def umount_device():
|
def umount_device():
|
||||||
if not USB_AUTO_MOUNT:
|
if not USB_AUTO_MOUNT:
|
||||||
print_action("unmount device /media/box")
|
log("Unmounting device /media/box")
|
||||||
res = os.system("pumount /media/box")
|
res = os.system("pumount /media/box")
|
||||||
# print("Return type: ", res)
|
# print("Return type: ", res)
|
||||||
|
|
||||||
|
@ -199,10 +229,12 @@ def device_loop():
|
||||||
for device in iter(monitor.poll, None):
|
for device in iter(monitor.poll, None):
|
||||||
if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd":
|
if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd":
|
||||||
if device.action == "add":
|
if device.action == "add":
|
||||||
|
log("Device inserted")
|
||||||
|
log_device_info(device)
|
||||||
# display device type
|
# display device type
|
||||||
print_status("KEY INSERTED")
|
print_status("KEY INSERTED")
|
||||||
print_fslabel(device.get("ID_FS_LABEL"))
|
print_fslabel(device.get("ID_FS_LABEL"))
|
||||||
print_fstype(device.get("ID_PART_TABLE_TYPE"))
|
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
|
||||||
print_model(device.get("ID_MODEL"))
|
print_model(device.get("ID_MODEL"))
|
||||||
print_serial(device.get("ID_SERIAL_SHORT"))
|
print_serial(device.get("ID_SERIAL_SHORT"))
|
||||||
# Mount device
|
# Mount device
|
||||||
|
@ -210,22 +242,48 @@ def device_loop():
|
||||||
statvfs=os.statvfs(mount_point)
|
statvfs=os.statvfs(mount_point)
|
||||||
print_size(statvfs.f_frsize * statvfs.f_blocks // 1024 // 1024 / 1024)
|
print_size(statvfs.f_frsize * statvfs.f_blocks // 1024 // 1024 / 1024)
|
||||||
print_used(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree) // 1024 // 1024 / 1024)
|
print_used(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree) // 1024 // 1024 / 1024)
|
||||||
|
log("Scan started...........")
|
||||||
# fake scan
|
# fake scan
|
||||||
loading = 0
|
loading = 0
|
||||||
while loading < 100:
|
while loading < 100:
|
||||||
loading += 1
|
loading += 1
|
||||||
time.sleep(0.03)
|
time.sleep(0.03)
|
||||||
update_bar(loading)
|
update_bar(loading)
|
||||||
|
log("Scan done.")
|
||||||
|
|
||||||
if device.action == "remove":
|
if device.action == "remove":
|
||||||
print_status("WAITING")
|
log("Device removed")
|
||||||
|
#print_status("WAITING")
|
||||||
print_action("Device removed")
|
print_action("Device removed")
|
||||||
print_fslabel("")
|
print_fslabel("")
|
||||||
|
print_size(0.0)
|
||||||
|
print_used(0.0)
|
||||||
|
print_fstype("")
|
||||||
|
print_action("")
|
||||||
|
print_model("")
|
||||||
|
print_serial("")
|
||||||
umount_device()
|
umount_device()
|
||||||
update_bar(0)
|
update_bar(0)
|
||||||
|
|
||||||
|
|
||||||
|
def log_device_info(dev):
|
||||||
|
logging.info("Device name: %s" % dev.get("DEVNAME"))
|
||||||
|
logging.info("Path id: %s" % dev.get("ID_PATH"))
|
||||||
|
logging.info("Bus system: %s" % dev.get("ID_BUS"))
|
||||||
|
logging.info("USB driver: %s" % dev.get("ID_USB_DRIVER"))
|
||||||
|
logging.info("Device type: %s" % dev.get("DEVTYPE"))
|
||||||
|
logging.info("Device usage: %s" % dev.get("ID_FS_USAGE"))
|
||||||
|
logging.info("Partition type: %s" % dev.get("ID_PART_TABLE_TYPE"))
|
||||||
|
logging.info("FS type: %s" % dev.get("ID_FS_TYPE"))
|
||||||
|
logging.info("Partition label: %s" % dev.get("ID_FS_LABEL"))
|
||||||
|
# logging.info("FS: %s" % dev.get("ID_FS_SYSTEM_ID"))
|
||||||
|
logging.info("Device model: %s" % dev.get("ID_MODEL"))
|
||||||
|
# logging.info('Usage: %s' % dev.get("ID_FS_USAGE"))
|
||||||
|
logging.info('Model: %s' % dev.get("ID_MODEL_ID"))
|
||||||
|
logging.info('Serial short: %s' % dev.get("ID_SERIAL_SHORT"))
|
||||||
|
logging.info('Serial: %s' % dev.get("ID_SERIAL"))
|
||||||
|
# logging.info(os.stat(dev.get("DEVNAME")))
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# pandora
|
# pandora
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
|
@ -31,7 +31,6 @@ def printDeviceInfo(dev):
|
||||||
print('Serial: %s' % dev.get("ID_SERIAL"))
|
print('Serial: %s' % dev.get("ID_SERIAL"))
|
||||||
print('Model: %s' % dev.get("ID_MODEL_ID"))
|
print('Model: %s' % dev.get("ID_MODEL_ID"))
|
||||||
print(os.stat(dev.get("DEVNAME")))
|
print(os.stat(dev.get("DEVNAME")))
|
||||||
|
|
||||||
print("</BLOCK INFORMATION>")
|
print("</BLOCK INFORMATION>")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ def updateBar(progress):
|
||||||
global progress_win
|
global progress_win
|
||||||
pos = (60 * progress) // 100
|
pos = (60 * progress) // 100
|
||||||
if pos != 0 :
|
if pos != 0 :
|
||||||
progress_win.addstr(1, pos, "{}".format("#"))
|
progress_win.addstr(1, pos, "#")
|
||||||
progress_win.refresh()
|
progress_win.refresh()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue