diff --git a/python/common/src/rascsi/common_settings.py b/python/common/src/rascsi/common_settings.py index 84b5c2a1..8e0d80e5 100644 --- a/python/common/src/rascsi/common_settings.py +++ b/python/common/src/rascsi/common_settings.py @@ -4,14 +4,8 @@ Module for general settings used in the rascsi module from os import getcwd -WORK_DIR = getcwd() - -REMOVABLE_DEVICE_TYPES = ("SCCD", "SCRM", "SCMO") -NETWORK_DEVICE_TYPES = ("SCDP", "SCBR") -SUPPORT_DEVICE_TYPES = ("SCLP", "SCHS") - # There may be a more elegant way to get the HOME dir of the user that installed RaSCSI -HOME_DIR = "/".join(WORK_DIR.split("/")[0:3]) +HOME_DIR = "/".join(getcwd().split("/")[0:3]) CFG_DIR = f"{HOME_DIR}/.config/rascsi" CONFIG_FILE_SUFFIX = "json" diff --git a/python/common/src/rascsi/ractl_cmds.py b/python/common/src/rascsi/ractl_cmds.py index 5fcbc723..3e0576fe 100644 --- a/python/common/src/rascsi/ractl_cmds.py +++ b/python/common/src/rascsi/ractl_cmds.py @@ -3,7 +3,6 @@ Module for commands sent to the RaSCSI backend service. """ import rascsi_interface_pb2 as proto -from rascsi.common_settings import REMOVABLE_DEVICE_TYPES from rascsi.return_codes import ReturnCodes from rascsi.socket_cmds import SocketCmds @@ -137,14 +136,54 @@ class RaCtlCmds: result = proto.PbResult() result.ParseFromString(data) device_types = {} - import logging for device in result.device_types_info.properties: params = {} for key, value in device.properties.default_params.items(): params[key] = value - device_types[proto.PbDeviceType.Name(device.type)] = params + device_types[proto.PbDeviceType.Name(device.type)] = { + "removable": device.properties.removable, + "supports_file": device.properties.supports_file, + "params": params, + "block_sizes": device.properties.block_sizes, + } return {"status": result.status, "device_types": device_types} + def get_removable_device_types(self): + """ + Returns a (list) of (str) of four letter device acronyms + that are of the removable type. + """ + device_types = self.get_device_types() + removable_device_types = [] + for device, value in device_types["device_types"].items(): + if value["removable"]: + removable_device_types.append(device) + return removable_device_types + + def get_disk_device_types(self): + """ + Returns a (list) of (str) of four letter device acronyms + that take image files as arguments. + """ + device_types = self.get_device_types() + disk_device_types = [] + for device, value in device_types["device_types"].items(): + if value["supports_file"]: + disk_device_types.append(device) + return disk_device_types + + def get_peripheral_device_types(self): + """ + Returns a (list) of (str) of four letter device acronyms + that don't take image files as arguments. + """ + device_types = self.get_device_types() + image_device_types = self.get_disk_device_types() + peripheral_device_types = [ + x for x in device_types["device_types"] if x not in image_device_types + ] + return peripheral_device_types + def get_image_files_info(self): """ Sends a DEFAULT_IMAGE_FILES_INFO command to the server. @@ -208,7 +247,8 @@ class RaCtlCmds: else: current_type = None - if device_type in REMOVABLE_DEVICE_TYPES and current_type in REMOVABLE_DEVICE_TYPES: + removable_device_types = self.get_removable_device_types() + if device_type in removable_device_types and current_type in removable_device_types: if current_type != device_type: parameters = { "device_type": device_type, diff --git a/python/oled/src/rascsi_oled_monitor.py b/python/oled/src/rascsi_oled_monitor.py index d6ede5c1..343bd396 100755 --- a/python/oled/src/rascsi_oled_monitor.py +++ b/python/oled/src/rascsi_oled_monitor.py @@ -43,12 +43,6 @@ from pi_cmds import get_ip_and_host from rascsi.ractl_cmds import RaCtlCmds from rascsi.socket_cmds import SocketCmds -from rascsi.common_settings import ( - REMOVABLE_DEVICE_TYPES, - NETWORK_DEVICE_TYPES, - SUPPORT_DEVICE_TYPES, -) - parser = argparse.ArgumentParser(description="RaSCSI OLED Monitor script") parser.add_argument( "--rotation", @@ -166,7 +160,8 @@ LINE_SPACING = 8 FONT = ImageFont.truetype('resources/type_writer.ttf', FONT_SIZE) IP_ADDR, HOSTNAME = get_ip_and_host() - +REMOVABLE_DEVICE_TYPES = ractl_cmd.get_removable_device_types() +SUPPORT_DEVICE_TYPES = ractl_cmd.get_support_device_types() def formatted_output(): """ @@ -188,11 +183,12 @@ 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 (NETWORK_DEVICE_TYPES): - output.append(f"{line['id']} {line['device_type'][2:4]} {line['vendor']} " - f"{line['product']}") elif line["device_type"] in (SUPPORT_DEVICE_TYPES): - output.append(f"{line['id']} {line['device_type'][2:4]} {line['product']}") + if line["vendor"] == "RaSCSI": + output.append(f"{line['id']} {line['device_type'][2:4]} {line['product']}") + else: + output.append(f"{line['id']} {line['device_type'][2:4]} {line['vendor']} " + f"{line['product']}") # Print only the Vendor/Product info if it's not generic RaSCSI elif line["vendor"] not in "RaSCSI": output.append(f"{line['id']} {line['device_type'][2:4]} {line['file']} " diff --git a/python/web/src/device_utils.py b/python/web/src/device_utils.py index 53ca9b31..0d1d6cf8 100644 --- a/python/web/src/device_utils.py +++ b/python/web/src/device_utils.py @@ -52,33 +52,39 @@ def sort_and_format_devices(devices): return formatted_devices -def extend_device_names(device_types): +def map_device_types_and_names(device_types): """ - Takes a (list) of (str) device_types with the four letter device acronyms + Takes a (dict) corresponding to the data structure returned by RaCtlCmds.get_device_types() Returns a (dict) of device_type:device_name mappings of localized device names """ - mapped_device_types = {} - for device_type in device_types: - if device_type == "SAHD": - device_name = _("SASI Hard Disk") - elif device_type == "SCHD": - device_name = _("SCSI Hard Disk") - elif device_type == "SCRM": - device_name = _("Removable Disk") - elif device_type == "SCMO": - device_name = _("Magneto-Optical") - elif device_type == "SCCD": - device_name = _("CD / DVD") - elif device_type == "SCBR": - device_name = _("X68000 Host Bridge") - elif device_type == "SCDP": - device_name = _("DaynaPORT SCSI/Link") - elif device_type == "SCLP": - device_name = _("Printer") - elif device_type == "SCHS": - device_name = _("Host Services") - else: - device_name = _("Unknown Device") - mapped_device_types[device_type] = device_name + for key, value in device_types.items(): + device_types[key]["name"] = get_device_name(key) - return mapped_device_types + return device_types + + +def get_device_name(device_type): + """ + Takes a four letter device acronym (str) device_type. + Returns the human-readable name for the device type. + """ + if device_type == "SAHD": + return _("SASI Hard Disk") + elif device_type == "SCHD": + return _("SCSI Hard Disk") + elif device_type == "SCRM": + return _("Removable Disk") + elif device_type == "SCMO": + return _("Magneto-Optical") + elif device_type == "SCCD": + return _("CD / DVD") + elif device_type == "SCBR": + return _("X68000 Host Bridge") + elif device_type == "SCDP": + return _("DaynaPORT SCSI/Link") + elif device_type == "SCLP": + return _("Printer") + elif device_type == "SCHS": + return _("Host Services") + else: + return device_type diff --git a/python/web/src/templates/drives.html b/python/web/src/templates/drives.html index 24656035..accaee99 100644 --- a/python/web/src/templates/drives.html +++ b/python/web/src/templates/drives.html @@ -15,7 +15,7 @@ {{ _("Ref.") }} {{ _("Action") }} -{% for hd in hd_conf %} +{% for hd in hd_conf|sort(attribute='name') %} {{ hd.name }} {{ hd.size_mb }} @@ -59,7 +59,7 @@ {{ _("Ref.") }} {{ _("Action") }} -{% for cd in cd_conf %} +{% for cd in cd_conf|sort(attribute='name') %} {{ cd.name }} {{ cd.size_mb }} @@ -79,9 +79,9 @@ @@ -105,7 +105,7 @@ {{ _("Ref.") }} {{ _("Action") }} -{% for rm in rm_conf %} +{% for rm in rm_conf|sort(attribute='name') %} {{ rm.name }} {{ rm.size_mb }} diff --git a/python/web/src/templates/index.html b/python/web/src/templates/index.html index 832295d3..7dda1c79 100644 --- a/python/web/src/templates/index.html +++ b/python/web/src/templates/index.html @@ -15,7 +15,7 @@

{% for key, value in device_types.items() %} - {% if key not in (NETWORK_DEVICE_TYPES + SUPPORT_DEVICE_TYPES) %} + {% if key in DISK_DEVICE_TYPES %} {% endif %} {% endfor %} @@ -298,7 +298,7 @@
- {{ _("Attach Support Device") }} + {{ _("Attach Peripheral Device") }}
- - + + - {% for type in (NETWORK_DEVICE_TYPES + SUPPORT_DEVICE_TYPES) %} + {% for type in PERIPHERAL_DEVICE_TYPES %}
{{ _("Type") }}{{ _("Actions") }}{{ _("Peripheral") }}{{ _("Parameters and Actions") }}
-
{{ device_types[type] }}
+
{{ device_types[type]["name"] }}
- {% for key, value in device_params[type].items() %} + {% for key, value in device_types[type]["params"].items() %} {% if value.isnumeric() %} - + {% elif key == "interface" %}