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>
<form action="/scsi/attach_device" method="post">
<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>
{% if value.isnumeric() %}
<input name="{{ key }}" type="number" value="{{ value }}">
@ -544,9 +544,10 @@
</summary>
<ul>
<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>{{ _("NEC GENUINE is appropriate for 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 Apple image type improves compatibility with Apple Macintosh computers.") }}</li>
<li>{{ _("The NEC image type improves compatibility with NEC PC-98 computers.") }}</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>
</details>
<table style="border: none">
@ -557,18 +558,11 @@
<input name="file_name" placeholder="{{ _("File Name") }}" required="" type="text">
<label for="type">{{ _("Type:") }}</label>
<select name="type">
<option value="hds">
{{ _("SCSI Hard Disk image (Generic) [.hds]") }}
</option>
<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]") }}
{% for key, value in image_suffixes_to_create.items() %}
<option value="{{ key }}">
{{ value }} [.{{ key }}]
</option>
{% endfor %}
</select>
<label for="size">{{ _("Size:") }}</label>
<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,
map_device_types_and_names,
get_device_name,
map_image_file_descriptions,
auth_active,
is_bridge_configured,
upload_with_dropzonejs,
@ -133,6 +134,19 @@ def index():
scsi_ids, recommended_id = get_valid_scsi_ids(devices["device_list"], reserved_scsi_ids)
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(
server_info["schd"] +
server_info["scrm"] +
@ -174,6 +188,7 @@ def index():
netinfo=ractl_cmd.get_network_info(),
device_types=device_types,
free_disk=int(sys_cmd.disk_space()["free"] / 1024 / 1024),
image_suffixes_to_create=image_suffixes_to_create,
valid_image_suffixes=valid_image_suffixes,
cdrom_file_suffix=tuple(server_info["sccd"]),
removable_file_suffix=tuple(server_info["scrm"]),

View File

@ -99,6 +99,39 @@ def get_device_name(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):
"""
Inspects if the group defined in (str) group exists on the system.