1
0
Fork 0
mirror of https://github.com/dbarzin/pandora-box.git synced 2025-08-04 05:15:26 +02:00

work in progress

This commit is contained in:
dbarzin 2022-06-12 11:41:35 +02:00
parent 27710ff92d
commit fa51c1168e

View file

@ -61,6 +61,7 @@ def print_size(label):
status_win.addstr(2, 1, "Size : ",curses.color_pair(2)) status_win.addstr(2, 1, "Size : ",curses.color_pair(2))
else: else:
status_win.addstr(2, 1, "Size : %4.1fGB " % label,curses.color_pair(2)) status_win.addstr(2, 1, "Size : %4.1fGB " % label,curses.color_pair(2))
logging.info("Size: %4.1fGB" % label)
status_win.refresh() status_win.refresh()
"""Print FS Used Size""" """Print FS Used Size"""
@ -70,6 +71,7 @@ def print_used(label):
status_win.addstr(3, 1, "Used : ",curses.color_pair(2)) status_win.addstr(3, 1, "Used : ",curses.color_pair(2))
else: else:
status_win.addstr(3, 1, "Used : %4.1fGB " % label,curses.color_pair(2)) status_win.addstr(3, 1, "Used : %4.1fGB " % label,curses.color_pair(2))
logging.info("Used: %4.1fGB " % label)
status_win.refresh() status_win.refresh()
def print_fstype(label): def print_fstype(label):
@ -108,25 +110,25 @@ def update_bar(progress):
def init_log(): def init_log():
global log_win global log_win
global logging
log_win = curses.newwin(16, 101, 20, 0) log_win = curses.newwin(16, 101, 20, 0)
log_win.border(0) log_win.border(0)
logging.basicConfig( logging.basicConfig(
filename='pandorabox.log', filename='pandorabox.log',
level=logging.INFO, level=logging.INFO,
format='%(asctime)s - %(message)s', format='%(asctime)s - %(message)s',
datefmt='%m/%d/%y %H:%M', datefmt='%m/%d/%y %H:%M'
filemode='w'
) )
logs = [] logs = []
def log(str): def log(str):
log_win.addstr(1,1,str,curses.color_pair(3)) global log_win
log_win.refresh() global logging
logging.info(str) logging.info(str)
logs.append(str) logs.append(str)
if len(logs)>15: if len(logs)>14:
logs.pop(0) logs.pop(0)
for i in range(min(15,len(logs))): for i in range(min(14,len(logs))):
log_win.addstr(i+1,1,"%-80s"%logs[i],curses.color_pair(3)) log_win.addstr(i+1,1,"%-80s"%logs[i],curses.color_pair(3))
log_win.refresh() log_win.refresh()
@ -174,7 +176,6 @@ def print_screen():
print_serial("") print_serial("")
init_bar() init_bar()
update_bar(0) update_bar(0)
init_log()
log('Ready.') log('Ready.')
"""Closes curses""" """Closes curses"""
@ -239,7 +240,11 @@ def device_loop():
print_serial(device.get("ID_SERIAL_SHORT")) print_serial(device.get("ID_SERIAL_SHORT"))
# Mount device # Mount device
mount_point = mount_device(device) mount_point = mount_device(device)
try:
statvfs=os.statvfs(mount_point) statvfs=os.statvfs(mount_point)
except:
log("Unexpected error: %-80s" % sys.exc_info()[0])
continue
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...........") log("Scan started...........")
@ -317,14 +322,16 @@ def scan(mountPoint):
"""Main entry point""" """Main entry point"""
def main(stdscr): def main(stdscr):
try: try:
init_log()
intit_curses() intit_curses()
print_screen() print_screen()
device_loop() device_loop()
except:
logging.error("Unexpected error:", sys.exc_info()[0])
logging.error(traceback.format_exc())
finally: finally:
end_curses() end_curses()
# -------------------------------------- # --------------------------------------