1
0
Fork 0
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:
dbarzin 2023-02-14 20:41:49 +01:00
parent e3b1884ba6
commit 7eca8b3a87
2 changed files with 31 additions and 30 deletions

View file

@ -13,17 +13,17 @@ jobs:
name: Quality check name: Quality check
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - name: Checkout
uses: actions/checkout@v3
with:
path: main
- name: Set up Python - name: Set up Python
uses: actions/setup-python@master uses: actions/setup-python@master
with: with:
python-version: 3.8 python-version: 3.8
- name: Wemake Python Stylguide - name: code quality checkout
uses: wemake-services/wemake-python-styleguide@0.13.4 run: |
continue-on-error: true pip install pylint
with: pylint ./pandora-box.py
reporter: 'github-pr-review'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -1,19 +1,19 @@
#!/usr/bin/python3 #!/usr/bin/python3
# #
# This file is part of the Pandora-box distribution. # This file is part of the Pandora-box distribution.
# https://github.com/dbarzin/pandora-box # https://github.com/dbarzin/pandora-box
# Copyright (c) 2022 Didier Barzin. # Copyright (c) 2022 Didier Barzin.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3. # the Free Software Foundation, version 3.
# #
# This program is distributed in the hope that it will be useful, but # This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of # WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
@ -21,7 +21,6 @@ import curses
from curses import wrapper from curses import wrapper
import pypandora import pypandora
import time import time
import sys
import pyudev import pyudev
import psutil import psutil
import os import os
@ -34,7 +33,7 @@ from datetime import datetime
# Config variables # Config variables
# ----------------------------------------------------------- # -----------------------------------------------------------
USB_AUTO_MOUNT = False USB_AUTO_MOUNT = False
PANDORA_ROOT_URL = "http://127.0.0.1:6100" PANDORA_ROOT_URL = "http://127.0.0.1:6100"
FAKE_SCAN = False FAKE_SCAN = False
QUARANTINE = False QUARANTINE = False
@ -93,7 +92,9 @@ def display_image(status):
# display image # display image
if "*" in image: if "*" in image:
# slide show # slide show
os.system("fim -qa -c 'while(1){display;sleep 1;next;}' %s </dev/null 2>/dev/null >/dev/null &" % image) os.system("fim -qa -c 'while(1){display;sleep 1;next;}' %s "\
"</dev/null 2>/dev/null >/dev/null &"
% image)
else : else :
# only one image # only one image
os.system("fim -qa %s </dev/null 2>/dev/null >/dev/null &" % image) os.system("fim -qa %s </dev/null 2>/dev/null >/dev/null &" % image)
@ -103,12 +104,12 @@ def display_image(status):
def waitMouseClick(): def waitMouseClick():
mouse = open( "/dev/input/mice", "rb" ) mouse = open( "/dev/input/mice", "rb" )
down = False; down = False
while True: while True:
buf = mouse.read(3) buf = mouse.read(3)
if ((buf[0] & 0x1)==1): if (buf[0] & 0x1)==1:
down = True down = True
if (((buf[0] & 0x1)==0) and down): if ((buf[0] & 0x1)==0) and down:
break; break;
mouse.close() mouse.close()
@ -126,7 +127,7 @@ def init_curses():
curses.flushinp() curses.flushinp()
curses.noecho() curses.noecho()
curses.curs_set(0) curses.curs_set(0)
else: else:
display_image("WAIT") display_image("WAIT")
"""Print FS Label""" """Print FS Label"""
@ -325,7 +326,7 @@ def mount_device():
try: try:
statvfs=os.statvfs(mount_point) statvfs=os.statvfs(mount_point)
except Exception as e : except Exception as e :
loop +=1 loop +=1
continue continue
break; break;
return "/media/box" return "/media/box"
@ -333,8 +334,8 @@ def mount_device():
"""Unmount USB device""" """Unmount USB device"""
def umount_device(): def umount_device():
if USB_AUTO_MOUNT: if USB_AUTO_MOUNT:
log("Sync partitions") log("Sync partitions")
res = os.system("sync") res = os.system("sync")
else: else:
log("Unmount partitions") log("Unmount partitions")
res = os.system("pumount /media/box 2>/dev/null >/dev/null") res = os.system("pumount /media/box 2>/dev/null >/dev/null")
@ -361,8 +362,8 @@ def log_device_info(dev):
"""Scan a mount point with Pandora""" """Scan a mount point with Pandora"""
def scan(mount_point, used): def scan(mount_point, used):
global device, infected_filed global device, infected_filed
infected_files = [] infected_files = []
scanned = 0 scanned = 0
file_count = 0 file_count = 0
scan_start_time = time.time() scan_start_time = time.time()
@ -391,7 +392,7 @@ def scan(mount_point, used):
loop = 0 loop = 0
while True and (loop < 960): while True and (loop < 960):
res = pandora.task_status(res["taskId"]) res = pandora.task_status(res["taskId"])
status = res["status"] status = res["status"]
if status != "WAITING": if status != "WAITING":
break break
time.sleep(0.5) time.sleep(0.5)
@ -399,8 +400,8 @@ def scan(mount_point, used):
file_scan_end_time = time.time() file_scan_end_time = time.time()
log("file=%s, size=%s, status=%s, duration=%ds" % ( log("file=%s, size=%s, status=%s, duration=%ds" % (
file, file,
human_readable_size(file_size), human_readable_size(file_size),
status, status,
(file_scan_end_time - file_scan_start_time))) (file_scan_end_time - file_scan_start_time)))
scanned += os.path.getsize(full_path) scanned += os.path.getsize(full_path)
file_count += 1 file_count += 1