Generate list of image types to create programmatically in the Web UI (#850)

* Generate list of image types to create programmatically based on rascsi capabilities, rather than a hard-coded list in the Web UI.

* Add explicit sorting of dicts for display in the Web UI, to avoid random order in certain environments.

* Remove redundant sorting line, and add code comments.

* Add helptext for the SCSI-1 image type
This commit is contained in:
Daniel Markstedt 2022-09-21 17:14:53 -07:00 committed by GitHub
parent e6ade9d510
commit e7775a72cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 15 deletions

View File

@ -336,7 +336,7 @@
<td> <td>
<form action="/scsi/attach_device" method="post"> <form action="/scsi/attach_device" method="post">
<input name="type" type="hidden" value="{{ type }}"> <input name="type" type="hidden" value="{{ type }}">
{% for key, value in device_types[type]["params"].items() %} {% for key, value in device_types[type]["params"] | dictsort %}
<label for="{{ key }}">{{ key }}:</label> <label for="{{ key }}">{{ key }}:</label>
{% if value.isnumeric() %} {% if value.isnumeric() %}
<input name="{{ key }}" type="number" value="{{ value }}"> <input name="{{ key }}" type="number" value="{{ value }}">
@ -544,9 +544,10 @@
</summary> </summary>
<ul> <ul>
<li>{{ _("The Generic Hard Disk image type is recommended for most computer platforms.") }}</li> <li>{{ _("The Generic Hard Disk image type is recommended for most computer platforms.") }}</li>
<li>{{ _("APPLE GENUINE is appropriate for Apple Macintosh computers.") }}</li> <li>{{ _("The Apple image type improves compatibility with Apple Macintosh computers.") }}</li>
<li>{{ _("NEC GENUINE is appropriate for NEC PC-98 computers.") }}</li> <li>{{ _("The NEC image type improves compatibility with NEC PC-98 computers.") }}</li>
<li>{{ _("The Generic Removable Disk image type can be used with SCSI floppy drives, SyQuest drives, Zip drives etc.") }}</li> <li>{{ _("The SCSI-1 image type makes RaSCSI behave like a legacy SCSI-1 device, which may improve compatibility with very old SCSI controllers.") }}</li>
<li>{{ _("The Removable Disk image type can be used with SCSI floppy drives, SyQuest drives, Zip drives, etc.") }}</li>
</ul> </ul>
</details> </details>
<table style="border: none"> <table style="border: none">
@ -557,18 +558,11 @@
<input name="file_name" placeholder="{{ _("File Name") }}" required="" type="text"> <input name="file_name" placeholder="{{ _("File Name") }}" required="" type="text">
<label for="type">{{ _("Type:") }}</label> <label for="type">{{ _("Type:") }}</label>
<select name="type"> <select name="type">
<option value="hds"> {% for key, value in image_suffixes_to_create.items() %}
{{ _("SCSI Hard Disk image (Generic) [.hds]") }} <option value="{{ key }}">
</option> {{ value }} [.{{ key }}]
<option value="hda">
{{ _("SCSI Hard Disk image (APPLE GENUINE) [.hda]") }}
</option>
<option value="hdn">
{{ _("SCSI Hard Disk image (NEC GENUINE) [.hdn]") }}
</option>
<option value="hdr">
{{ _("SCSI Removable Disk image (Generic) [.hdr]") }}
</option> </option>
{% endfor %}
</select> </select>
<label for="size">{{ _("Size:") }}</label> <label for="size">{{ _("Size:") }}</label>
<input name="size" type="number" placeholder="{{ _("MB") }}" min="1" max="262144" required> <input name="size" type="number" placeholder="{{ _("MB") }}" min="1" max="262144" required>

View File

@ -49,6 +49,7 @@ from web_utils import (
get_valid_scsi_ids, get_valid_scsi_ids,
map_device_types_and_names, map_device_types_and_names,
get_device_name, get_device_name,
map_image_file_descriptions,
auth_active, auth_active,
is_bridge_configured, is_bridge_configured,
upload_with_dropzonejs, upload_with_dropzonejs,
@ -133,6 +134,19 @@ def index():
scsi_ids, recommended_id = get_valid_scsi_ids(devices["device_list"], reserved_scsi_ids) scsi_ids, recommended_id = get_valid_scsi_ids(devices["device_list"], reserved_scsi_ids)
formatted_devices = sort_and_format_devices(devices["device_list"]) formatted_devices = sort_and_format_devices(devices["device_list"])
image_suffixes_to_create = map_image_file_descriptions(
# Here we strip out hdi and nhd, since they are proprietary PC-98 emulator formats
# that require a particular header to work. We can't generate them on the fly.
# We also reverse the resulting list, in order for hds to be the default in the UI.
# This might break if something like 'hdt' etc. gets added in the future.
sorted(
[suffix for suffix in server_info["schd"] if suffix not in {"hdi", "nhd"}],
reverse=True
) +
server_info["scrm"] +
server_info["scmo"]
)
valid_image_suffixes = "." + ", .".join( valid_image_suffixes = "." + ", .".join(
server_info["schd"] + server_info["schd"] +
server_info["scrm"] + server_info["scrm"] +
@ -174,6 +188,7 @@ def index():
netinfo=ractl_cmd.get_network_info(), netinfo=ractl_cmd.get_network_info(),
device_types=device_types, device_types=device_types,
free_disk=int(sys_cmd.disk_space()["free"] / 1024 / 1024), free_disk=int(sys_cmd.disk_space()["free"] / 1024 / 1024),
image_suffixes_to_create=image_suffixes_to_create,
valid_image_suffixes=valid_image_suffixes, valid_image_suffixes=valid_image_suffixes,
cdrom_file_suffix=tuple(server_info["sccd"]), cdrom_file_suffix=tuple(server_info["sccd"]),
removable_file_suffix=tuple(server_info["scrm"]), removable_file_suffix=tuple(server_info["scrm"]),

View File

@ -99,6 +99,39 @@ def get_device_name(device_type):
return device_type return device_type
def map_image_file_descriptions(file_suffixes):
"""
Takes a (list) of (str) file suffixes for images file types.
Returns a (dict) with file suffix and description pairs, both (str)
"""
supported_image_types = {}
for suffix in file_suffixes:
supported_image_types[suffix] = get_image_description(suffix)
return supported_image_types
# pylint: disable=too-many-return-statements
def get_image_description(file_suffix):
"""
Takes a three char file suffix (str) file_suffix.
Returns the help text description for said file suffix.
"""
if file_suffix == "hds":
return _("Hard Disk Image (Generic)")
if file_suffix == "hda":
return _("Hard Disk Image (Apple)")
if file_suffix == "hdn":
return _("Hard Disk Image (NEC)")
if file_suffix == "hd1":
return _("Hard Disk Image (SCSI-1)")
if file_suffix == "hdr":
return _("Removable Disk Image")
if file_suffix == "mos":
return _("Magneto-Optical Disk Image")
return file_suffix
def auth_active(group): def auth_active(group):
""" """
Inspects if the group defined in (str) group exists on the system. Inspects if the group defined in (str) group exists on the system.