mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-08 05:29:40 +00:00
4252d46844
* Add capabilities to RaCtlCmds.get_device_types() to return the image file support boolean, and list of supported block sizes. * Inquire rascsi backend about the min block size rather than hard coding values in the web UI. * Add class methods for getting lists of certain device types. * Use the new class methods to get lists of device types in the web ui. * Make use of the new class methods in the oled script. * Remove now unused constants, and simplify logic in common_settings * Improve device name mapping to extend the existing dictionary rather than creating a new data structure. * Use jinja2 sort filters instead of sorting in python code. Removing redundant variables. * Introduce the get_device_name() utility method which returns the translated name for a device acronym. Use the new method to display device name when attaching devices. * Fix typo * Rename Support Device to Periperal Device. General tweaks to UI strings. * Tweak UI string. * Fix error.
91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
"""
|
|
Module for RaSCSI device management utility methods
|
|
"""
|
|
|
|
from flask_babel import _
|
|
|
|
|
|
def get_valid_scsi_ids(devices, reserved_ids):
|
|
"""
|
|
Takes a list of (dict)s devices, and list of (int)s reserved_ids.
|
|
Returns:
|
|
- (list) of (int)s valid_ids, which are the SCSI ids that are not reserved
|
|
- (int) recommended_id, which is the id that the Web UI should default to recommend
|
|
"""
|
|
occupied_ids = []
|
|
for device in devices:
|
|
occupied_ids.append(device["id"])
|
|
|
|
unoccupied_ids = [i for i in list(range(8)) if i not in reserved_ids + occupied_ids]
|
|
unoccupied_ids.sort()
|
|
valid_ids = [i for i in list(range(8)) if i not in reserved_ids]
|
|
valid_ids.sort(reverse=True)
|
|
|
|
if unoccupied_ids:
|
|
recommended_id = unoccupied_ids[-1]
|
|
else:
|
|
recommended_id = occupied_ids.pop(0)
|
|
|
|
return valid_ids, recommended_id
|
|
|
|
|
|
def sort_and_format_devices(devices):
|
|
"""
|
|
Takes a (list) of (dict)s devices and returns a (list) of (dict)s.
|
|
Sorts by SCSI ID acending (0 to 7).
|
|
For SCSI IDs where no device is attached, inject a (dict) with placeholder text.
|
|
"""
|
|
occupied_ids = []
|
|
for device in devices:
|
|
occupied_ids.append(device["id"])
|
|
|
|
formatted_devices = devices
|
|
|
|
# Add padding devices and sort the list
|
|
for i in range(8):
|
|
if i not in occupied_ids:
|
|
formatted_devices.append({"id": i, "device_type": "-", \
|
|
"status": "-", "file": "-", "product": "-"})
|
|
# Sort list of devices by id
|
|
formatted_devices.sort(key=lambda dic: str(dic["id"]))
|
|
|
|
return formatted_devices
|
|
|
|
|
|
def map_device_types_and_names(device_types):
|
|
"""
|
|
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
|
|
"""
|
|
for key, value in device_types.items():
|
|
device_types[key]["name"] = get_device_name(key)
|
|
|
|
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
|