mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-23 15:29:43 +02:00
code quality
This commit is contained in:
parent
08ef826869
commit
9a89ba19c5
1 changed files with 24 additions and 31 deletions
|
@ -39,9 +39,9 @@ import pypandora
|
||||||
# Threading variables
|
# Threading variables
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
threads = []
|
threads = []
|
||||||
exitFlag = False
|
exit_flag = False
|
||||||
queueLock = threading.Lock()
|
queue_lock = threading.Lock()
|
||||||
workQueue = None
|
work_queue = None
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Config variables
|
# Config variables
|
||||||
|
@ -84,16 +84,15 @@ class scanThread (threading.Thread):
|
||||||
self.pandora = pypandora.PyPandora(root_url=pandora_root_url)
|
self.pandora = pypandora.PyPandora(root_url=pandora_root_url)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not exitFlag:
|
while not exit_flag:
|
||||||
queueLock.acquire()
|
queue_lock.acquire()
|
||||||
if not workQueue.empty():
|
if not work_queue.empty():
|
||||||
file = workQueue.get()
|
file = work_queue.get()
|
||||||
queueLock.release()
|
queue_lock.release()
|
||||||
self.scan(file)
|
self.scan(file)
|
||||||
else:
|
else:
|
||||||
queueLock.release()
|
queue_lock.release()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
# print(f"Thread-{self.id} Done.")
|
|
||||||
|
|
||||||
def scan(self, file):
|
def scan(self, file):
|
||||||
global infected_files, scanned, file_count, used
|
global infected_files, scanned, file_count, used
|
||||||
|
@ -127,7 +126,7 @@ class scanThread (threading.Thread):
|
||||||
|
|
||||||
# Handle responde from Pandora
|
# Handle responde from Pandora
|
||||||
status = res["status"]
|
status = res["status"]
|
||||||
if (status != "WAITING"):
|
if status != "WAITING":
|
||||||
break
|
break
|
||||||
|
|
||||||
# wait a little
|
# wait a little
|
||||||
|
@ -151,7 +150,7 @@ class scanThread (threading.Thread):
|
||||||
f'duration="{int(file_scan_end_time - file_scan_start_time)}"')
|
f'duration="{int(file_scan_end_time - file_scan_start_time)}"')
|
||||||
|
|
||||||
# Get lock
|
# Get lock
|
||||||
queueLock.acquire()
|
queue_lock.acquire()
|
||||||
|
|
||||||
scanned += file_size
|
scanned += file_size
|
||||||
file_count += 1
|
file_count += 1
|
||||||
|
@ -161,7 +160,7 @@ class scanThread (threading.Thread):
|
||||||
infected_files.append(file)
|
infected_files.append(file)
|
||||||
|
|
||||||
# Release lock
|
# Release lock
|
||||||
queueLock.release()
|
queue_lock.release()
|
||||||
|
|
||||||
# update status bar
|
# update status bar
|
||||||
update_bar(scanned * 100 // used)
|
update_bar(scanned * 100 // used)
|
||||||
|
@ -387,8 +386,6 @@ def print_screen():
|
||||||
|
|
||||||
|
|
||||||
def end_curses():
|
def end_curses():
|
||||||
global has_curses
|
|
||||||
global curses
|
|
||||||
"""Closes curses"""
|
"""Closes curses"""
|
||||||
if has_curses:
|
if has_curses:
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
@ -525,8 +522,8 @@ def log_device_info(dev):
|
||||||
def scan():
|
def scan():
|
||||||
"""Scan devce with pypandora"""
|
"""Scan devce with pypandora"""
|
||||||
global pandora, qfolder
|
global pandora, qfolder
|
||||||
global workQueue, exitFlag, threads, queueLock
|
global work_queue, exit_flag, threads, scanned
|
||||||
global mount_point, infected_files, scanned, file_count, used
|
global mount_point, infected_files, file_count, used
|
||||||
|
|
||||||
# get device size
|
# get device size
|
||||||
try:
|
try:
|
||||||
|
@ -558,10 +555,10 @@ def scan():
|
||||||
qfolder = os.path.join(quarantine_folder, datetime.datetime.now().strftime("%y%m%d-%H%M"))
|
qfolder = os.path.join(quarantine_folder, datetime.datetime.now().strftime("%y%m%d-%H%M"))
|
||||||
|
|
||||||
# Instantice work quere
|
# Instantice work quere
|
||||||
workQueue = queue.Queue(512)
|
work_queue = queue.Queue(512)
|
||||||
|
|
||||||
# set exit condition to false
|
# set exit condition to false
|
||||||
exitFlag = False
|
exit_flag = False
|
||||||
|
|
||||||
# Instanciate threads
|
# Instanciate threads
|
||||||
for _ in range(maxThreads):
|
for _ in range(maxThreads):
|
||||||
|
@ -572,18 +569,18 @@ def scan():
|
||||||
# Fill the work queue
|
# Fill the work queue
|
||||||
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 workQueue.full():
|
while work_queue.full():
|
||||||
pass
|
pass
|
||||||
queueLock.acquire()
|
queue_lock.acquire()
|
||||||
workQueue.put(os.path.join(root, file))
|
work_queue.put(os.path.join(root, file))
|
||||||
queueLock.release()
|
queue_lock.release()
|
||||||
|
|
||||||
# Wait for queue to empty
|
# Wait for queue to empty
|
||||||
while not workQueue.empty():
|
while not work_queue.empty():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Notify threads it's time to exit
|
# Notify threads it's time to exit
|
||||||
exitFlag = True
|
exit_flag = True
|
||||||
|
|
||||||
# Wait for all threads to complete
|
# Wait for all threads to complete
|
||||||
for t in threads:
|
for t in threads:
|
||||||
|
@ -625,7 +622,6 @@ def wait():
|
||||||
|
|
||||||
|
|
||||||
def device_inserted(dev):
|
def device_inserted(dev):
|
||||||
global has_curses
|
|
||||||
global device
|
global device
|
||||||
log("Device inserted", flush=True)
|
log("Device inserted", flush=True)
|
||||||
logging.info(
|
logging.info(
|
||||||
|
@ -645,7 +641,6 @@ def device_inserted(dev):
|
||||||
|
|
||||||
|
|
||||||
def device_removed():
|
def device_removed():
|
||||||
global has_curses
|
|
||||||
global device
|
global device
|
||||||
log("Device removed", flush=True)
|
log("Device removed", flush=True)
|
||||||
logging.info(
|
logging.info(
|
||||||
|
@ -670,7 +665,6 @@ def device_removed():
|
||||||
def mount():
|
def mount():
|
||||||
""" Mount device """
|
""" Mount device """
|
||||||
global mount_point
|
global mount_point
|
||||||
global has_curses
|
|
||||||
mount_device()
|
mount_device()
|
||||||
log(f'Partition mounted at {mount_point}', flush=True)
|
log(f'Partition mounted at {mount_point}', flush=True)
|
||||||
if mount_point is None:
|
if mount_point is None:
|
||||||
|
@ -695,7 +689,6 @@ def mount():
|
||||||
|
|
||||||
def error():
|
def error():
|
||||||
""" Display error message """
|
""" Display error message """
|
||||||
global has_curses
|
|
||||||
if not has_curses:
|
if not has_curses:
|
||||||
display_image("ERROR")
|
display_image("ERROR")
|
||||||
return "WAIT"
|
return "WAIT"
|
||||||
|
@ -721,7 +714,7 @@ def clean():
|
||||||
for file in infected_files:
|
for file in infected_files:
|
||||||
log(file)
|
log(file)
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
if (cnt >= 10):
|
if cnt >= 10:
|
||||||
log('...')
|
log('...')
|
||||||
break
|
break
|
||||||
# wait for clean
|
# wait for clean
|
||||||
|
@ -848,7 +841,7 @@ def get_lock(process_name):
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
def main(args):
|
def main(_):
|
||||||
"""Main entry point"""
|
"""Main entry point"""
|
||||||
try:
|
try:
|
||||||
state = "START"
|
state = "START"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue