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

imporve log in screen mode

This commit is contained in:
dbarzin 2022-07-25 01:40:02 +02:00
parent 15328ef26c
commit cb005441d7
2 changed files with 107 additions and 97 deletions

View file

@ -3,7 +3,7 @@
CURSES = False CURSES = False
; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys ; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys
USB_AUTO_MOUNT = False USB_AUTO_MOUNT = True
; Set PANDORA_ROOT_URL to the URL of the Pandora server ; Set PANDORA_ROOT_URL to the URL of the Pandora server
; the default value is "http://127.0.0.1:6100" ; the default value is "http://127.0.0.1:6100"

View file

@ -74,6 +74,7 @@ def human_readable_size(size, decimal_places=1):
# ----------------------------------------------------------- # -----------------------------------------------------------
def display_image(status): def display_image(status):
if not CURSES:
if status=="WAIT": if status=="WAIT":
image = "images/key*.png" image = "images/key*.png"
elif status=="WORK": elif status=="WORK":
@ -96,6 +97,7 @@ def display_image(status):
# only one image # only one image
os.system("fim -qa %s </dev/null 2>/dev/null &" % image) os.system("fim -qa %s </dev/null 2>/dev/null &" % image)
# ----------------------------------------------------------- # -----------------------------------------------------------
def waitMouseClick(): def waitMouseClick():
@ -247,8 +249,12 @@ def print_screen():
"""Closes curses""" """Closes curses"""
def end_curses(): def end_curses():
if CURSES:
curses.endwin() curses.endwin()
curses.flushinp() curses.flushinp()
else:
# hide old image
os.system("killall -s 9 fim 2>/dev/null")
# ----------------------------------------------------------- # -----------------------------------------------------------
# Logging windows # Logging windows
@ -280,6 +286,8 @@ def log(str):
for i in range(min(curses.LINES-22,len(logs))): for i in range(min(curses.LINES-22,len(logs))):
log_win.addstr(i+1,1,logs[i][:curses.COLS-2],curses.color_pair(3)) log_win.addstr(i+1,1,logs[i][:curses.COLS-2],curses.color_pair(3))
log_win.refresh() log_win.refresh()
else:
print(str,end="\n\r")
# ----------------------------------------------------------- # -----------------------------------------------------------
# Device # Device
@ -335,7 +343,7 @@ 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")
#try: try:
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":
@ -354,11 +362,15 @@ def device_loop():
log('Partition mounted at %s' % mount_point) log('Partition mounted at %s' % mount_point)
if mount_point == None: if mount_point == None:
# no partition # no partition
if not CURSES:
display_image("WAIT")
continue continue
try: try:
statvfs=os.statvfs(mount_point) statvfs=os.statvfs(mount_point)
except Exception as e : except Exception as e :
log("Unexpected error: %s" % e) log("Unexpected error: %s" % e)
if not CURSES:
display_image("WAIT")
continue continue
print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks)) print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks))
print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))) print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)))
@ -404,11 +416,10 @@ def device_loop():
print_model("") print_model("")
print_serial("") print_serial("")
update_bar(0) update_bar(0)
# except Exception as e: except Exception as e:
# log("Unexpected error: %s" % str(e) ) log("Unexpected error: %s" % str(e) )
# finally: finally:
# log("Done.") log("Done.")
def log_device_info(dev): def log_device_info(dev):
logging.info("Device name: %s" % dev.get("DEVNAME")) logging.info("Device name: %s" % dev.get("DEVNAME"))
@ -510,8 +521,7 @@ def main(stdscr):
while True: while True:
device_loop() device_loop()
except Exception as e : except Exception as e :
end_curses() log("Unexpected error: %s" % e)
print("Unexpected error: ", e)
finally: finally:
end_curses() end_curses()