mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-24 07:49: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
|
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"
|
||||||
|
|
200
pandora-box.py
200
pandora-box.py
|
@ -74,27 +74,29 @@ def human_readable_size(size, decimal_places=1):
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
def display_image(status):
|
def display_image(status):
|
||||||
if status=="WAIT":
|
if not CURSES:
|
||||||
image = "images/key*.png"
|
if status=="WAIT":
|
||||||
elif status=="WORK":
|
image = "images/key*.png"
|
||||||
image = "images/wait*.png"
|
elif status=="WORK":
|
||||||
elif status=="OK":
|
image = "images/wait*.png"
|
||||||
image = "images/ok.png"
|
elif status=="OK":
|
||||||
elif status=="BAD":
|
image = "images/ok.png"
|
||||||
image = "images/bad.png"
|
elif status=="BAD":
|
||||||
elif status=="ERROR":
|
image = "images/bad.png"
|
||||||
image = "images/error.png"
|
elif status=="ERROR":
|
||||||
else:
|
image = "images/error.png"
|
||||||
return
|
else:
|
||||||
# hide old image
|
return
|
||||||
os.system("killall -s 9 fim 2>/dev/null")
|
# hide old image
|
||||||
# display image
|
os.system("killall -s 9 fim 2>/dev/null")
|
||||||
if "*" in image:
|
# display image
|
||||||
# slide show
|
if "*" in image:
|
||||||
os.system("fim -qa -c 'while(1){display;sleep 1;next;}' %s </dev/null 2>/dev/null &" % image)
|
# slide show
|
||||||
else :
|
os.system("fim -qa -c 'while(1){display;sleep 1;next;}' %s </dev/null 2>/dev/null &" % image)
|
||||||
# only one image
|
else :
|
||||||
os.system("fim -qa %s </dev/null 2>/dev/null &" % image)
|
# only one image
|
||||||
|
os.system("fim -qa %s </dev/null 2>/dev/null &" % image)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
|
@ -247,8 +249,12 @@ def print_screen():
|
||||||
|
|
||||||
"""Closes curses"""
|
"""Closes curses"""
|
||||||
def end_curses():
|
def end_curses():
|
||||||
curses.endwin()
|
if CURSES:
|
||||||
curses.flushinp()
|
curses.endwin()
|
||||||
|
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,80 +343,83 @@ 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":
|
||||||
log("Device inserted")
|
log("Device inserted")
|
||||||
log_device_info(device)
|
log_device_info(device)
|
||||||
if not CURSES:
|
|
||||||
display_image("WORK")
|
|
||||||
else:
|
|
||||||
# display device type
|
|
||||||
print_fslabel(device.get("ID_FS_LABEL"))
|
|
||||||
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
|
|
||||||
print_model(device.get("ID_MODEL"))
|
|
||||||
print_serial(device.get("ID_SERIAL_SHORT"))
|
|
||||||
# Mount device
|
|
||||||
mount_point = mount_device(device)
|
|
||||||
log('Partition mounted at %s' % mount_point)
|
|
||||||
if mount_point == None:
|
|
||||||
# no partition
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
statvfs=os.statvfs(mount_point)
|
|
||||||
except Exception as e :
|
|
||||||
log("Unexpected error: %s" % e)
|
|
||||||
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)))
|
|
||||||
|
|
||||||
# Scan files
|
|
||||||
log("Scan started...........")
|
|
||||||
infected_files = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
|
|
||||||
|
|
||||||
# Clean files
|
|
||||||
if len(infected_files) > 0:
|
|
||||||
log('%d infected files found !' % len(infected_files))
|
|
||||||
if not CURSES:
|
if not CURSES:
|
||||||
display_image("BAD")
|
display_image("WORK")
|
||||||
waitMouseClick()
|
|
||||||
else:
|
else:
|
||||||
log('PRESS KEY TO CLEAN')
|
# display device type
|
||||||
screen.getch()
|
print_fslabel(device.get("ID_FS_LABEL"))
|
||||||
# Remove infected files
|
print_fstype(device.get("ID_PART_TABLE_TYPE") + " " + device.get("ID_FS_TYPE"))
|
||||||
for file in infected_files:
|
print_model(device.get("ID_MODEL"))
|
||||||
try :
|
print_serial(device.get("ID_SERIAL_SHORT"))
|
||||||
os.remove(file)
|
# Mount device
|
||||||
log('%s removed' % file)
|
mount_point = mount_device(device)
|
||||||
except Exception as e :
|
log('Partition mounted at %s' % mount_point)
|
||||||
log("Unexpected error: %s" % str(e))
|
if mount_point == None:
|
||||||
os.system("sync")
|
# no partition
|
||||||
log("Clean done.")
|
if not CURSES:
|
||||||
if not CURSES:
|
display_image("WAIT")
|
||||||
display_image("OK")
|
continue
|
||||||
else:
|
try:
|
||||||
if not CURSES:
|
statvfs=os.statvfs(mount_point)
|
||||||
display_image("OK")
|
except Exception as e :
|
||||||
umount_device()
|
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)))
|
||||||
|
|
||||||
if device.action == "remove":
|
# Scan files
|
||||||
log("Device removed")
|
log("Scan started...........")
|
||||||
if not CURSES:
|
infected_files = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
|
||||||
display_image("WAIT")
|
|
||||||
else:
|
|
||||||
print_fslabel("")
|
|
||||||
print_size(None)
|
|
||||||
print_used(None)
|
|
||||||
print_fstype("")
|
|
||||||
print_model("")
|
|
||||||
print_serial("")
|
|
||||||
update_bar(0)
|
|
||||||
# except Exception as e:
|
|
||||||
# log("Unexpected error: %s" % str(e) )
|
|
||||||
# finally:
|
|
||||||
# log("Done.")
|
|
||||||
|
|
||||||
|
# Clean files
|
||||||
|
if len(infected_files) > 0:
|
||||||
|
log('%d infected files found !' % len(infected_files))
|
||||||
|
if not CURSES:
|
||||||
|
display_image("BAD")
|
||||||
|
waitMouseClick()
|
||||||
|
else:
|
||||||
|
log('PRESS KEY TO CLEAN')
|
||||||
|
screen.getch()
|
||||||
|
# Remove infected files
|
||||||
|
for file in infected_files:
|
||||||
|
try :
|
||||||
|
os.remove(file)
|
||||||
|
log('%s removed' % file)
|
||||||
|
except Exception as e :
|
||||||
|
log("Unexpected error: %s" % str(e))
|
||||||
|
os.system("sync")
|
||||||
|
log("Clean done.")
|
||||||
|
if not CURSES:
|
||||||
|
display_image("OK")
|
||||||
|
else:
|
||||||
|
if not CURSES:
|
||||||
|
display_image("OK")
|
||||||
|
umount_device()
|
||||||
|
|
||||||
|
if device.action == "remove":
|
||||||
|
log("Device removed")
|
||||||
|
if not CURSES:
|
||||||
|
display_image("WAIT")
|
||||||
|
else:
|
||||||
|
print_fslabel("")
|
||||||
|
print_size(None)
|
||||||
|
print_used(None)
|
||||||
|
print_fstype("")
|
||||||
|
print_model("")
|
||||||
|
print_serial("")
|
||||||
|
update_bar(0)
|
||||||
|
except Exception as e:
|
||||||
|
log("Unexpected error: %s" % str(e) )
|
||||||
|
finally:
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue