mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
Feature attach suggestion (#260)
* Issue 232 -- will not generate PC98 emulator image formats * Introducing dropdown for selecting device type which defaults to a recommendation based on file ending, while removing the quiet logic to autodetect type on the frond end side * Added device type to PbImageFile * Comment update * Code cleanup * More code cleanup * Extraced methods * Extracted methods * Renaming * Moved code * Visility update * Updated error handling * Removed duplicate error handling * Removed duplicate code * Code cleanup * Moved code * Moved code * Leverage new device type field for files in protobuf interface * Tweak label * Tweak template * Fix bug * Add types legend * Add tip about renaming image files Co-authored-by: Uwe Seimet <Uwe.Seimet@seimet.de>
This commit is contained in:
parent
3d0c200521
commit
18e55bea2d
@ -21,7 +21,8 @@ def list_files():
|
||||
files = []
|
||||
for f in result.image_files_info.image_files:
|
||||
size_mb = "{:,.1f}".format(f.size / 1024 / 1024)
|
||||
files.append({"name": f.name, "size": f.size, "size_mb": size_mb})
|
||||
dtype = proto.PbDeviceType.Name(f.type)
|
||||
files.append({"name": f.name, "size": f.size, "size_mb": size_mb, "detected_type": dtype})
|
||||
|
||||
return {"status": result.status, "msg": result.msg, "files": files}
|
||||
|
||||
|
@ -31,6 +31,19 @@ def get_network_info():
|
||||
return {"status": result.status, "ifs": ifs}
|
||||
|
||||
|
||||
def get_device_types():
|
||||
command = proto.PbCommand()
|
||||
command.operation = proto.PbOperation.DEVICE_TYPES_INFO
|
||||
|
||||
data = send_pb_command(command.SerializeToString())
|
||||
result = proto.PbResult()
|
||||
result.ParseFromString(data)
|
||||
device_types = []
|
||||
for t in result.device_types_info.properties:
|
||||
device_types.append(proto.PbDeviceType.Name(t.type))
|
||||
return {"status": result.status, "device_types": device_types}
|
||||
|
||||
|
||||
def validate_scsi_id(scsi_id):
|
||||
from re import match
|
||||
if match("[0-7]", str(scsi_id)) != None:
|
||||
@ -87,6 +100,7 @@ def attach_image(scsi_id, **kwargs):
|
||||
devices.id = int(scsi_id)
|
||||
|
||||
if "device_type" in kwargs.keys():
|
||||
if kwargs["device_type"] not in [None, ""]:
|
||||
devices.type = proto.PbDeviceType.Value(str(kwargs["device_type"]))
|
||||
if "unit" in kwargs.keys():
|
||||
devices.unit = kwargs["unit"]
|
||||
@ -110,13 +124,13 @@ def attach_image(scsi_id, **kwargs):
|
||||
if kwargs["interfaces"] not in [None, ""]:
|
||||
devices.params["interfaces"] = kwargs["interfaces"]
|
||||
if "vendor" in kwargs.keys():
|
||||
if kwargs["vendor"] not in [None, ""]:
|
||||
if kwargs["vendor"] != None:
|
||||
devices.vendor = kwargs["vendor"]
|
||||
if "product" in kwargs.keys():
|
||||
if kwargs["product"] not in [None, ""]:
|
||||
if kwargs["product"] != None:
|
||||
devices.product = kwargs["product"]
|
||||
if "revision" in kwargs.keys():
|
||||
if kwargs["revision"] not in [None, ""]:
|
||||
if kwargs["revision"] != None:
|
||||
devices.revision = kwargs["revision"]
|
||||
if "block_size" in kwargs.keys():
|
||||
if kwargs["block_size"] not in [None, ""]:
|
||||
@ -187,6 +201,7 @@ def list_devices(scsi_id=None):
|
||||
device_list = []
|
||||
n = 0
|
||||
|
||||
# Return an empty list if no devices are attached
|
||||
if len(result.device_info.devices) == 0:
|
||||
return {"status": False, "device_list": []}
|
||||
|
||||
|
@ -7,11 +7,14 @@ DEFAULT_CONFIG = "default.json"
|
||||
MAX_FILE_SIZE = getenv("MAX_FILE_SIZE", 1024 * 1024 * 1024 * 4) # 4gb
|
||||
|
||||
HARDDRIVE_FILE_SUFFIX = ("hda", "hdn", "hdi", "nhd", "hdf", "hds")
|
||||
CDROM_FILE_SUFFIX = ("iso", "cdr", "toast", "img")
|
||||
SASI_FILE_SUFFIX = ("hdf",)
|
||||
REMOVABLE_FILE_SUFFIX = ("hdr",)
|
||||
CDROM_FILE_SUFFIX = ("iso",)
|
||||
MO_FILE_SUFFIX = ("mos",)
|
||||
ARCHIVE_FILE_SUFFIX = ("zip",)
|
||||
VALID_FILE_SUFFIX = HARDDRIVE_FILE_SUFFIX + REMOVABLE_FILE_SUFFIX + \
|
||||
CDROM_FILE_SUFFIX + ARCHIVE_FILE_SUFFIX
|
||||
VALID_FILE_SUFFIX = HARDDRIVE_FILE_SUFFIX + SASI_FILE_SUFFIX + \
|
||||
REMOVABLE_FILE_SUFFIX + CDROM_FILE_SUFFIX + \
|
||||
MO_FILE_SUFFIX + ARCHIVE_FILE_SUFFIX
|
||||
|
||||
# File containing canonical drive properties
|
||||
DRIVE_PROPERTIES_FILE = home_dir + "/drive_properties.json"
|
||||
|
@ -79,9 +79,11 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><tt>Types: SAHD = SASI HDD | SCHD = SCSI HDD | SCRM = Removable | SCMO = Magneto-Optical | SCCD = CD-ROM | SCBR = Host Bridge | SCDP = DaynaPORT</tt></p>
|
||||
|
||||
<hr/>
|
||||
<h2>Image File Management</h2>
|
||||
|
||||
<h2>Valid Image Files</h2>
|
||||
<table cellpadding="3" border="black">
|
||||
<tbody>
|
||||
<tr>
|
||||
@ -107,6 +109,16 @@
|
||||
<option value="{{id}}">{{id}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if file["detected_type"] != "UNDEFINED" %}
|
||||
{{file["detected_type"]}}
|
||||
{% else %}
|
||||
<select name="type">
|
||||
<option value="" Selected>????</option>
|
||||
{% for d in device_types %}
|
||||
<option value="{{d}}">{{d}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
<input type="submit" value="Attach" />
|
||||
</form>
|
||||
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file?')">
|
||||
@ -162,6 +174,7 @@
|
||||
|
||||
<h2>Upload File</h2>
|
||||
<p>Uploads file to <tt>{{base_dir}}</tt>. The largest file size accepted is {{max_file_size}} MB. Zip files will be unzipped.</p>
|
||||
<p>For unrecognized file types, try renaming hard drive images to '.hds' and CD-ROM images to '.iso' before uploading.</p>
|
||||
<table style="border: none">
|
||||
<tr style="border: none">
|
||||
<td style="border: none; vertical-align:top;">
|
||||
@ -233,10 +246,7 @@
|
||||
<label for="type">Type:</label>
|
||||
<select name="type">
|
||||
<option value="hds">SCSI Hard Disk image (Generic - recommended for most systems) [.hds]</option>
|
||||
<option value="hdn">SCSI Hard Disk image (NEC GENUINE) [.hdn]</option>
|
||||
<!-- Disabling due to https://github.com/akuker/RASCSI/issues/232
|
||||
<option value="hdi">SCSI Hard Disk image (Anex86 HD image) [.hdi]</option>
|
||||
<option value="nhd">SCSI Hard Disk image (T98Next HD image) [.nhd]</option> -->
|
||||
<option value="hdn">SCSI Hard Disk image (NEC GENUINE - only for PC98) [.hdn]</option>
|
||||
<option value="hdr">SCSI Removable Media Disk image (Generic) [.hdr]</option>
|
||||
<option value="hdf">SASI Hard Disk image (legacy format) [.hdf]</option>
|
||||
</select>
|
||||
|
@ -42,6 +42,7 @@ from ractl_cmds import (
|
||||
detach_all,
|
||||
get_server_info,
|
||||
get_network_info,
|
||||
get_device_types,
|
||||
validate_scsi_id,
|
||||
set_log_level,
|
||||
)
|
||||
@ -55,6 +56,7 @@ def index():
|
||||
server_info = get_server_info()
|
||||
disk = disk_space()
|
||||
devices = list_devices()
|
||||
device_types=get_device_types()
|
||||
files=list_files()
|
||||
config_files=list_config_files()
|
||||
|
||||
@ -78,6 +80,7 @@ def index():
|
||||
running_env=running_env(),
|
||||
server_info=server_info,
|
||||
netinfo=get_network_info(),
|
||||
device_types=device_types["device_types"],
|
||||
free_disk=int(disk["free"] / 1024 / 1024),
|
||||
valid_file_suffix="."+", .".join(VALID_FILE_SUFFIX),
|
||||
removable_device_types=REMOVABLE_DEVICE_TYPES,
|
||||
@ -319,6 +322,7 @@ def attach():
|
||||
file_name = request.form.get("file_name")
|
||||
file_size = request.form.get("file_size")
|
||||
scsi_id = request.form.get("scsi_id")
|
||||
device_type = request.form.get("type")
|
||||
|
||||
validate = validate_scsi_id(scsi_id)
|
||||
if validate["status"] == False:
|
||||
@ -327,14 +331,8 @@ def attach():
|
||||
|
||||
kwargs = {"image": file_name}
|
||||
|
||||
# Validate image type by file name suffix
|
||||
# Supplementing file ending based image type detection on the backend side
|
||||
if file_name.lower().endswith(CDROM_FILE_SUFFIX):
|
||||
kwargs["device_type"] = "SCCD"
|
||||
elif file_name.lower().endswith(REMOVABLE_FILE_SUFFIX):
|
||||
kwargs["device_type"] = "SCRM"
|
||||
else:
|
||||
kwargs["device_type"] = "SCHD"
|
||||
if device_type != "":
|
||||
kwargs["device_type"] = device_type
|
||||
|
||||
# Attempt to load the device properties file:
|
||||
# same base path but PROPERTIES_SUFFIX instead of the original suffix.
|
||||
|
Loading…
Reference in New Issue
Block a user