mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-26 21:18:56 +00:00
Create SysCmds common class, and refactor Python codebase (#697)
* Move the oled script's PiCmds module to common, and rename it SysCmds. * Use sys_cmds.get_ip_and_host() in web UI code. * Move the auth_active() method to device_utils * Rename device_utils to web_utils. Make auth_active() method take the group as argument. * Migrate all pi_cmds methods to the SysCmds common class. * Display hostname and ip in Web UI. * Resolve or suppress pylint warnings. * Resolve a pylint warning. * Resolve or suppress pylint warnings. * Import libraries at the top level for readability. In my testing on a Pi3B+, this leads to ~1.5k more memory being used by the python3 process. * Change page title as requested by akuker. * Reenable the import-outside-toplevel pylint rule. * Resolve pylint warnings. * Fix error following refactoring. * Minor UI tweaks. * Cleanup. * Break out bridge config validation into a utility method. * Move the dropzonejs method into the web_utils package * Move get_logs method into SysCmds class. * Improve get logs UI. * Resolve pylint warning. * Standardize class instance name.
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
"""
|
||||
Module with methods that interact with the Pi's Linux system
|
||||
"""
|
||||
|
||||
|
||||
def get_ip_and_host():
|
||||
"""
|
||||
Use a mock socket connection to identify the Pi's hostname and IP address
|
||||
"""
|
||||
from socket import socket, gethostname, AF_INET, SOCK_DGRAM
|
||||
host = gethostname()
|
||||
sock = socket(AF_INET, SOCK_DGRAM)
|
||||
try:
|
||||
# mock ip address; doesn't have to be reachable
|
||||
sock.connect(('10.255.255.255', 1))
|
||||
ip_addr = sock.getsockname()[0]
|
||||
except Exception:
|
||||
ip_addr = False
|
||||
finally:
|
||||
sock.close()
|
||||
return ip_addr, host
|
||||
@@ -39,9 +39,9 @@ from board import I2C
|
||||
from adafruit_ssd1306 import SSD1306_I2C
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from interrupt_handler import GracefulInterruptHandler
|
||||
from pi_cmds import get_ip_and_host
|
||||
from rascsi.ractl_cmds import RaCtlCmds
|
||||
from rascsi.socket_cmds import SocketCmds
|
||||
from rascsi.sys_cmds import SysCmds
|
||||
|
||||
parser = argparse.ArgumentParser(description="RaSCSI OLED Monitor script")
|
||||
parser.add_argument(
|
||||
@@ -99,6 +99,7 @@ TOKEN = args.password
|
||||
|
||||
sock_cmd = SocketCmds(host=args.rascsi_host, port=args.rascsi_port)
|
||||
ractl_cmd = RaCtlCmds(sock_cmd=sock_cmd, token=TOKEN)
|
||||
sys_cmd = SysCmds()
|
||||
|
||||
WIDTH = 128
|
||||
BORDER = 5
|
||||
@@ -159,7 +160,7 @@ LINE_SPACING = 8
|
||||
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
|
||||
FONT = ImageFont.truetype('resources/type_writer.ttf', FONT_SIZE)
|
||||
|
||||
IP_ADDR, HOSTNAME = get_ip_and_host()
|
||||
IP_ADDR, HOSTNAME = sys_cmd.get_ip_and_host()
|
||||
REMOVABLE_DEVICE_TYPES = ractl_cmd.get_removable_device_types()
|
||||
PERIPHERAL_DEVICE_TYPES = ractl_cmd.get_peripheral_device_types()
|
||||
|
||||
@@ -183,7 +184,7 @@ def formatted_output():
|
||||
else:
|
||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['status']}")
|
||||
# Special handling of devices that don't use image files
|
||||
elif line["device_type"] in (PERIPHERAL_DEVICE_TYPES):
|
||||
elif line["device_type"] in PERIPHERAL_DEVICE_TYPES:
|
||||
if line["vendor"] == "RaSCSI":
|
||||
output.append(f"{line['id']} {line['device_type'][2:4]} {line['product']}")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user