mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-23 15:29:43 +02:00
work on logs
This commit is contained in:
parent
aabbfed387
commit
654f302ba8
2 changed files with 29 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
; Curses mode (full text)
|
; Curses mode (full text)
|
||||||
CURSES = False
|
CURSES = True
|
||||||
|
|
||||||
; Set USB_AUTO_MOUNT to true is if the OS automaticaly mount USB keys
|
; Set USB_AUTO_MOUNT to true is if the OS automaticaly mount USB keys
|
||||||
USB_AUTO_MOUNT = False
|
USB_AUTO_MOUNT = False
|
||||||
|
|
|
@ -168,21 +168,18 @@ class PandoraBox:
|
||||||
if self.has_curses:
|
if self.has_curses:
|
||||||
self.status_win.addstr(2, 1, f"Size : {label:32} ", curses.color_pair(2))
|
self.status_win.addstr(2, 1, f"Size : {label:32} ", curses.color_pair(2))
|
||||||
self.status_win.refresh()
|
self.status_win.refresh()
|
||||||
logging.info('fs_size="%s"', label)
|
|
||||||
|
|
||||||
def _print_used(self, label):
|
def _print_used(self, label):
|
||||||
"""Print FS Used Size"""
|
"""Print FS Used Size"""
|
||||||
if self.has_curses:
|
if self.has_curses:
|
||||||
self.status_win.addstr(3, 1, f"Used : {label:32} ",curses.color_pair(2))
|
self.status_win.addstr(3, 1, f"Used : {label:32} ",curses.color_pair(2))
|
||||||
self.status_win.refresh()
|
self.status_win.refresh()
|
||||||
logging.info('fs_usage="%s"',label)
|
|
||||||
|
|
||||||
def _print_fstype(self, label):
|
def _print_fstype(self, label):
|
||||||
"""Print device FS type"""
|
"""Print device FS type"""
|
||||||
if self.has_curses:
|
if self.has_curses:
|
||||||
self.status_win.addstr(1, 50, f"Part / Type : {label:32}", curses.color_pair(2))
|
self.status_win.addstr(1, 50, f"Part / Type : {label:32}", curses.color_pair(2))
|
||||||
self.status_win.refresh()
|
self.status_win.refresh()
|
||||||
logging.info('fs_type="%s"',label)
|
|
||||||
|
|
||||||
def _print_model(self, label):
|
def _print_model(self, label):
|
||||||
"""Print device model"""
|
"""Print device model"""
|
||||||
|
@ -249,6 +246,7 @@ class PandoraBox:
|
||||||
self._init_bar()
|
self._init_bar()
|
||||||
self._update_bar(0)
|
self._update_bar(0)
|
||||||
self._log('Ready.')
|
self._log('Ready.')
|
||||||
|
logging.info("pandora-box-start")
|
||||||
|
|
||||||
def _end_curses(self):
|
def _end_curses(self):
|
||||||
"""Closes curses"""
|
"""Closes curses"""
|
||||||
|
@ -269,7 +267,7 @@ class PandoraBox:
|
||||||
self.log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
self.log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
||||||
self.log_win.border(0)
|
self.log_win.border(0)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename='pandora-box.log',
|
filename='/var/log/pandora-box.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'
|
||||||
|
@ -278,7 +276,6 @@ class PandoraBox:
|
||||||
logs = []
|
logs = []
|
||||||
def _log(self, msg):
|
def _log(self, msg):
|
||||||
"""log something"""
|
"""log something"""
|
||||||
logging.info(msg)
|
|
||||||
if self.has_curses:
|
if self.has_curses:
|
||||||
# display log on screen
|
# display log on screen
|
||||||
self.logs.append(msg)
|
self.logs.append(msg)
|
||||||
|
@ -296,7 +293,7 @@ class PandoraBox:
|
||||||
|
|
||||||
def mount_device(self):
|
def mount_device(self):
|
||||||
"""Mount USB device"""
|
"""Mount USB device"""
|
||||||
self._log('Try to mount partition')
|
self._log('Mount device')
|
||||||
if self.has_usb_auto_mount:
|
if self.has_usb_auto_mount:
|
||||||
self.mount_point = None
|
self.mount_point = None
|
||||||
loop = 0
|
loop = 0
|
||||||
|
@ -394,7 +391,8 @@ class PandoraBox:
|
||||||
if file_size > (1024*1024*1024):
|
if file_size > (1024*1024*1024):
|
||||||
status = "TOO BIG"
|
status = "TOO BIG"
|
||||||
else:
|
else:
|
||||||
self._log(f'scan=[{full_path}]')
|
self._log(f'-> [{full_path}]')
|
||||||
|
logging.info(f'scan=[{full_path}]')
|
||||||
res = pandora.submit_from_disk(full_path)
|
res = pandora.submit_from_disk(full_path)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
loop = 0
|
loop = 0
|
||||||
|
@ -406,9 +404,15 @@ class PandoraBox:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
loop += 1
|
loop += 1
|
||||||
file_scan_end_time = time.time()
|
file_scan_end_time = time.time()
|
||||||
|
|
||||||
self._log(
|
self._log(
|
||||||
f'file="{file}" , '\
|
f'Scan {file} '\
|
||||||
f'size="{self._human_readable_size(file_size)}", '\
|
f'[{self._human_readable_size(file_size)}] '\
|
||||||
|
'-> '\
|
||||||
|
f'{status} ({int(file_scan_end_time - file_scan_start_time)}s)')
|
||||||
|
logging.info(
|
||||||
|
f'file="{file}", '\
|
||||||
|
f'size="{file_size}", '\
|
||||||
f'status="{status}"", '\
|
f'status="{status}"", '\
|
||||||
f'duration="{int(file_scan_end_time - file_scan_start_time)}"')
|
f'duration="{int(file_scan_end_time - file_scan_start_time)}"')
|
||||||
scanned += os.path.getsize(full_path)
|
scanned += os.path.getsize(full_path)
|
||||||
|
@ -423,10 +427,12 @@ class PandoraBox:
|
||||||
shutil.copyfile(full_path, os.path.join(qfolder,file))
|
shutil.copyfile(full_path, os.path.join(qfolder,file))
|
||||||
except Exception as ex :
|
except Exception as ex :
|
||||||
self._log(f"Unexpected error: {str(ex)}")
|
self._log(f"Unexpected error: {str(ex)}")
|
||||||
logging.info("An exception was thrown!", exc_info=True)
|
logging.info(f'error="{str(ex)}"', exc_info=True)
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
self._update_bar(100)
|
self._update_bar(100)
|
||||||
self._log(
|
self._log("Scan done in %ds, %d files scanned, %d files infected" %
|
||||||
|
((time.time() - scan_start_time),file_count,len(self.infected_files)))
|
||||||
|
logging.info(
|
||||||
f'duration="{int(time.time() - scan_start_time)}s", '\
|
f'duration="{int(time.time() - scan_start_time)}s", '\
|
||||||
f'files_scanned="{file_count}", '\
|
f'files_scanned="{file_count}", '\
|
||||||
f'files_infected="{len(self.infected_files)}"')
|
f'files_infected="{len(self.infected_files)}"')
|
||||||
|
@ -449,7 +455,7 @@ class PandoraBox:
|
||||||
return self._device_removed()
|
return self._device_removed()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self._log(f"Unexpected error: {str(ex)}")
|
self._log(f"Unexpected error: {str(ex)}")
|
||||||
logging.info("An exception was thrown!", exc_info=True)
|
logging.info(f'error="{str(ex)}"', exc_info=True)
|
||||||
finally:
|
finally:
|
||||||
self._log("Done.")
|
self._log("Done.")
|
||||||
return "STOP"
|
return "STOP"
|
||||||
|
@ -457,6 +463,7 @@ class PandoraBox:
|
||||||
def _device_inserted(self, dev):
|
def _device_inserted(self, dev):
|
||||||
self.device = dev
|
self.device = dev
|
||||||
self._log_device_info(self.device)
|
self._log_device_info(self.device)
|
||||||
|
logging.info("device_inserted")
|
||||||
if not self.has_curses:
|
if not self.has_curses:
|
||||||
self.display_image("WORK")
|
self.display_image("WORK")
|
||||||
else:
|
else:
|
||||||
|
@ -495,8 +502,8 @@ class PandoraBox:
|
||||||
try:
|
try:
|
||||||
os.statvfs(self.mount_point)
|
os.statvfs(self.mount_point)
|
||||||
except Exception as ex :
|
except Exception as ex :
|
||||||
self._log(f"error={ex}")
|
self._log(f"Unexpected error: {str(ex)}")
|
||||||
logging.info("An exception was thrown!", exc_info=True)
|
logging.info(f'error="{str(ex)}"', exc_info=True)
|
||||||
if not self.has_curses:
|
if not self.has_curses:
|
||||||
self.display_image("WAIT")
|
self.display_image("WAIT")
|
||||||
return "WAIT"
|
return "WAIT"
|
||||||
|
@ -532,7 +539,8 @@ class PandoraBox:
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Remove infected files"""
|
"""Remove infected files"""
|
||||||
if len(self.infected_files) > 0:
|
if len(self.infected_files) > 0:
|
||||||
self._log(f"infeted_files={len(self.infected_files)}")
|
self._log(f"{len(self.infected_files)} infected_files detecetd !")
|
||||||
|
logging.info(f"infeted_files={len(self.infected_files)}")
|
||||||
if not self.has_curses:
|
if not self.has_curses:
|
||||||
self.display_image("BAD")
|
self.display_image("BAD")
|
||||||
self.wait_mouse_click()
|
self.wait_mouse_click()
|
||||||
|
@ -544,9 +552,10 @@ class PandoraBox:
|
||||||
try :
|
try :
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
self._log(f"{file} removed")
|
self._log(f"{file} removed")
|
||||||
|
logging.info(f'removed="{file}"')
|
||||||
except Exception as ex :
|
except Exception as ex :
|
||||||
self._log(f"Unexpected error: {ex}")
|
self._log(f"Unexpected error: {str(ex)}")
|
||||||
logging.info("An exception was thrown!", exc_info=True)
|
logging.info(f'error="{str(ex)}"', exc_info=True)
|
||||||
os.system("sync")
|
os.system("sync")
|
||||||
if not self.has_curses:
|
if not self.has_curses:
|
||||||
self.display_image("OK")
|
self.display_image("OK")
|
||||||
|
@ -614,12 +623,11 @@ class PandoraBox:
|
||||||
while state!="STOP":
|
while state!="STOP":
|
||||||
state = self.loop(state)
|
state = self.loop(state)
|
||||||
except Exception as ex :
|
except Exception as ex :
|
||||||
self._log(f"error={ex}")
|
self._log(f"Unexpected error: {str(ex)}")
|
||||||
logging.info("An exception was thrown!", exc_info=True)
|
logging.info(f'error="{str(ex)}"', exc_info=True)
|
||||||
finally:
|
finally:
|
||||||
self._end_curses()
|
self._end_curses()
|
||||||
|
|
||||||
|
|
||||||
def main(_):
|
def main(_):
|
||||||
"""Main entry point"""
|
"""Main entry point"""
|
||||||
pandora_box = PandoraBox()
|
pandora_box = PandoraBox()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue