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

imporve logging

This commit is contained in:
didier 2025-04-16 16:56:07 +02:00
parent 4e5e7ff871
commit 5f105c2a4f

View file

@ -93,28 +93,31 @@ class scanThread(threading.Thread):
self.scan(file) self.scan(file)
else: else:
queue_lock.release() queue_lock.release()
time.sleep(0.1) time.sleep(1)
def scan(self, file): def scan(self, file):
global infected_files, scanned, file_count, used global infected_files, scanned, file_count, used
logging.info(f"Start scan.")
try: try:
# get file information # get file information
file_name = os.path.basename(file) file_name = os.path.basename(file)
file_size = os.path.getsize(file) file_size = os.path.getsize(file)
# log the scan has started # log the scan has started
# log( logging.info(
# f'Scan {file_name} ' f'Scan {file_name} '
# f'[{human_readable_size(file_size)}] ' f'[{human_readable_size(file_size)}] '
# f'Thread-{id} ') f'Thread-{id} ')
start_time = time.time() start_time = time.time()
if is_fake_scan: if is_fake_scan:
status = "SKIPPED" status = "SKIPPED"
logging.info(f"Fake scan - skipped.")
else: else:
# do not scan files bigger than 1G # do not scan files bigger than 1G
if file_size > (1024 * 1024 * 1024): if file_size > (1024 * 1024 * 1024):
status = "TOO BIG" status = "TOO BIG"
logging.info(f"File too big.")
else: else:
worker = self.pandora.submit_from_disk(file, seed_expire=6000) worker = self.pandora.submit_from_disk(file, seed_expire=6000)
if (not 'taskId' in worker) or (not 'seed' in worker) : if (not 'taskId' in worker) or (not 'seed' in worker) :
@ -180,6 +183,7 @@ class scanThread(threading.Thread):
log(f"Unexpected error: {str(ex)}", flush=True) log(f"Unexpected error: {str(ex)}", flush=True)
logging.info(f'boxname="{boxname}", ' f'error="{str(ex)}"', exc_info=True) logging.info(f'boxname="{boxname}", ' f'error="{str(ex)}"', exc_info=True)
logging.info(f"Start done.")
# ---------------------------------------------------------- # ----------------------------------------------------------
@ -331,7 +335,7 @@ def update_bar(progress, flush=False):
if progress == 0: if progress == 0:
progress_win.clear() progress_win.clear()
progress_win.border(0) progress_win.border(0)
time.sleep(0) time.sleep(1)
progress_win.addstr(0, 1, "Progress:") progress_win.addstr(0, 1, "Progress:")
else: else:
pos = ((curses.COLS - 14) * progress) // 100 pos = ((curses.COLS - 14) * progress) // 100
@ -527,11 +531,13 @@ def scan():
return "ERROR" return "ERROR"
# Print device information # Print device information
print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks)) f_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_size(f_size)
human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)) logging.info(f'size="{f_size}")
used = statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree) f_used = statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)
print_used(human_readable_size(f_used)))
logging.info(f'used="{f_used}")
# scan device # scan device
infected_files = [] infected_files = []
@ -558,6 +564,7 @@ def scan():
for root, _, files in os.walk(mount_point): for root, _, files in os.walk(mount_point):
for file in files: for file in files:
while work_queue.full(): while work_queue.full():
time.sleep(1)
pass pass
queue_lock.acquire() queue_lock.acquire()
work_queue.put(os.path.join(root, file)) work_queue.put(os.path.join(root, file))
@ -565,6 +572,7 @@ def scan():
# Wait for queue to empty # Wait for queue to empty
while not work_queue.empty(): while not work_queue.empty():
time.sleep(1)
pass pass
# Notify threads it's time to exit # Notify threads it's time to exit
@ -655,6 +663,8 @@ def mount():
global mount_point global mount_point
mount_device() mount_device()
log(f"Partition mounted at {mount_point}", flush=True) log(f"Partition mounted at {mount_point}", flush=True)
logging.info(f"Partition mounted at {mount_point}")
if mount_point is None: if mount_point is None:
# no partition # no partition
if not has_curses: if not has_curses:
@ -702,7 +712,7 @@ def mouseClickThread():
down = True down = True
if ((buf[0] & 0x1) == 0) and down: if ((buf[0] & 0x1) == 0) and down:
break break
time.sleep(0.1) time.sleep(1)
mouse.close() mouse.close()
mouseEvent.set() mouseEvent.set()