mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-19 13:29:42 +02:00
imporve log in screen mode
This commit is contained in:
parent
15328ef26c
commit
cb005441d7
2 changed files with 107 additions and 97 deletions
|
@ -3,7 +3,7 @@
|
|||
CURSES = False
|
||||
|
||||
; 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
|
||||
; the default value is "http://127.0.0.1:6100"
|
||||
|
|
|
@ -74,6 +74,7 @@ def human_readable_size(size, decimal_places=1):
|
|||
# -----------------------------------------------------------
|
||||
|
||||
def display_image(status):
|
||||
if not CURSES:
|
||||
if status=="WAIT":
|
||||
image = "images/key*.png"
|
||||
elif status=="WORK":
|
||||
|
@ -96,6 +97,7 @@ def display_image(status):
|
|||
# only one image
|
||||
os.system("fim -qa %s </dev/null 2>/dev/null &" % image)
|
||||
|
||||
|
||||
# -----------------------------------------------------------
|
||||
|
||||
def waitMouseClick():
|
||||
|
@ -247,8 +249,12 @@ def print_screen():
|
|||
|
||||
"""Closes curses"""
|
||||
def end_curses():
|
||||
if CURSES:
|
||||
curses.endwin()
|
||||
curses.flushinp()
|
||||
else:
|
||||
# hide old image
|
||||
os.system("killall -s 9 fim 2>/dev/null")
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Logging windows
|
||||
|
@ -280,6 +286,8 @@ def log(str):
|
|||
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.refresh()
|
||||
else:
|
||||
print(str,end="\n\r")
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Device
|
||||
|
@ -335,7 +343,7 @@ def device_loop():
|
|||
context = pyudev.Context()
|
||||
monitor = pyudev.Monitor.from_netlink(context)
|
||||
monitor.filter_by("block")
|
||||
#try:
|
||||
try:
|
||||
for device in iter(monitor.poll, None):
|
||||
if device.get("ID_FS_USAGE") == "filesystem" and device.device_node[5:7] == "sd":
|
||||
if device.action == "add":
|
||||
|
@ -354,11 +362,15 @@ def device_loop():
|
|||
log('Partition mounted at %s' % mount_point)
|
||||
if mount_point == None:
|
||||
# no partition
|
||||
if not CURSES:
|
||||
display_image("WAIT")
|
||||
continue
|
||||
try:
|
||||
statvfs=os.statvfs(mount_point)
|
||||
except Exception as e :
|
||||
log("Unexpected error: %s" % e)
|
||||
if not CURSES:
|
||||
display_image("WAIT")
|
||||
continue
|
||||
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)))
|
||||
|
@ -404,11 +416,10 @@ def device_loop():
|
|||
print_model("")
|
||||
print_serial("")
|
||||
update_bar(0)
|
||||
# except Exception as e:
|
||||
# log("Unexpected error: %s" % str(e) )
|
||||
# finally:
|
||||
# log("Done.")
|
||||
|
||||
except Exception as e:
|
||||
log("Unexpected error: %s" % str(e) )
|
||||
finally:
|
||||
log("Done.")
|
||||
|
||||
def log_device_info(dev):
|
||||
logging.info("Device name: %s" % dev.get("DEVNAME"))
|
||||
|
@ -510,8 +521,7 @@ def main(stdscr):
|
|||
while True:
|
||||
device_loop()
|
||||
except Exception as e :
|
||||
end_curses()
|
||||
print("Unexpected error: ", e)
|
||||
log("Unexpected error: %s" % e)
|
||||
finally:
|
||||
end_curses()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue