mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-21 02:17:25 +00:00
Tentative Web UI for the Printer device. (#676)
* Tentative Web UI for the Printer device. * timeout must be a positive value * Change the attach device class method to accept a dict with arbitrary key value pairs of parameters to be passed to the protobuf interface, rather than hard coded ones. Also renames the RaCtlCmds.attach_image() class method to attach_device(). * Make download_to_iso() use the new attach interface. * Dynamically get the form items for support devices. * Change the data structure returned by RaCtlCmds.get_device_types() to a dict, which contains the supported parameters and their default values. Leverage this data in the web ui to derive the form fields from the capabilities of rascsi. * Tweak UI labels. * Update FileCmds.read_config() to work with the new RaCtlCmds.attach_device() method. * Check for numeric value. * Streamline the UI for support devices. * Handle support devices better by the oled screen. * Clean up html. * Dynamically adjust form field size based on data length.
This commit is contained in:
@@ -8,7 +8,7 @@ WORK_DIR = getcwd()
|
||||
|
||||
REMOVABLE_DEVICE_TYPES = ("SCCD", "SCRM", "SCMO")
|
||||
NETWORK_DEVICE_TYPES = ("SCDP", "SCBR")
|
||||
SUPPORT_DEVICE_TYPES = ("SCHS", )
|
||||
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])
|
||||
|
||||
@@ -450,17 +450,16 @@ class FileCmds:
|
||||
for row in config["devices"]:
|
||||
kwargs = {
|
||||
"device_type": row["device_type"],
|
||||
"image": row["image"],
|
||||
"unit": int(row["unit"]),
|
||||
"vendor": row["vendor"],
|
||||
"product": row["product"],
|
||||
"revision": row["revision"],
|
||||
"block_size": row["block_size"],
|
||||
"params": dict(row["params"]),
|
||||
}
|
||||
params = dict(row["params"])
|
||||
for param in params.keys():
|
||||
kwargs[param] = params[param]
|
||||
self.ractl.attach_image(row["id"], **kwargs)
|
||||
if row["image"]:
|
||||
kwargs["params"]["file"] = row["image"]
|
||||
self.ractl.attach_device(row["id"], **kwargs)
|
||||
# The config file format in RaSCSI 21.10 is using a list data type at the top level.
|
||||
# If future config file formats return to the list data type,
|
||||
# introduce more sophisticated format detection logic here.
|
||||
@@ -470,17 +469,17 @@ class FileCmds:
|
||||
kwargs = {
|
||||
"device_type": row["device_type"],
|
||||
"image": row["image"],
|
||||
# "un" for backwards compatibility
|
||||
"unit": int(row["un"]),
|
||||
"vendor": row["vendor"],
|
||||
"product": row["product"],
|
||||
"revision": row["revision"],
|
||||
"block_size": row["block_size"],
|
||||
"params": dict(row["params"]),
|
||||
}
|
||||
params = dict(row["params"])
|
||||
for param in params.keys():
|
||||
kwargs[param] = params[param]
|
||||
self.ractl.attach_image(row["id"], **kwargs)
|
||||
if row["image"]:
|
||||
kwargs["params"]["file"] = row["image"]
|
||||
self.ractl.attach_device(row["id"], **kwargs)
|
||||
logging.warning("%s is in an obsolete config file format", file_name)
|
||||
else:
|
||||
return {"status": False,
|
||||
"return_code": ReturnCodes.READCONFIG_INVALID_CONFIG_FILE_FORMAT}
|
||||
|
||||
@@ -125,7 +125,8 @@ class RaCtlCmds:
|
||||
Sends a DEVICE_TYPES_INFO command to the server.
|
||||
Returns a dict with:
|
||||
- (bool) status
|
||||
- (list) of (str) device_types (device types that RaSCSI supports, ex. SCHD, SCCD, etc)
|
||||
- (dict) device_types, where keys are the four letter device type acronym,
|
||||
and the value is a (dict) of supported parameters and their default values.
|
||||
"""
|
||||
command = proto.PbCommand()
|
||||
command.operation = proto.PbOperation.DEVICE_TYPES_INFO
|
||||
@@ -135,9 +136,13 @@ class RaCtlCmds:
|
||||
data = self.sock_cmd.send_pb_command(command.SerializeToString())
|
||||
result = proto.PbResult()
|
||||
result.ParseFromString(data)
|
||||
device_types = []
|
||||
for prop in result.device_types_info.properties:
|
||||
device_types.append(proto.PbDeviceType.Name(prop.type))
|
||||
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
|
||||
return {"status": result.status, "device_types": device_types}
|
||||
|
||||
def get_image_files_info(self):
|
||||
@@ -167,7 +172,7 @@ class RaCtlCmds:
|
||||
"scan_depth": scan_depth,
|
||||
}
|
||||
|
||||
def attach_image(self, scsi_id, **kwargs):
|
||||
def attach_device(self, scsi_id, **kwargs):
|
||||
"""
|
||||
Takes (int) scsi_id and kwargs containing 0 or more device properties
|
||||
|
||||
@@ -185,14 +190,15 @@ class RaCtlCmds:
|
||||
devices.id = int(scsi_id)
|
||||
|
||||
if "device_type" in kwargs.keys():
|
||||
if kwargs["device_type"] not in [None, ""]:
|
||||
if kwargs["device_type"]:
|
||||
devices.type = proto.PbDeviceType.Value(str(kwargs["device_type"]))
|
||||
if "unit" in kwargs.keys():
|
||||
if kwargs["unit"] not in [None, ""]:
|
||||
if kwargs["unit"]:
|
||||
devices.unit = kwargs["unit"]
|
||||
if "image" in kwargs.keys():
|
||||
if kwargs["image"] not in [None, ""]:
|
||||
devices.params["file"] = kwargs["image"]
|
||||
if "params" in kwargs.keys():
|
||||
if isinstance(kwargs["params"], dict):
|
||||
for param in kwargs["params"]:
|
||||
devices.params[param] = kwargs["params"][param]
|
||||
|
||||
# Handling the inserting of media into an attached removable type device
|
||||
device_type = kwargs.get("device_type", None)
|
||||
@@ -214,23 +220,21 @@ class RaCtlCmds:
|
||||
"parameters": parameters,
|
||||
}
|
||||
command.operation = proto.PbOperation.INSERT
|
||||
|
||||
# Handling attaching a new device
|
||||
else:
|
||||
command.operation = proto.PbOperation.ATTACH
|
||||
if "interfaces" in kwargs.keys():
|
||||
if kwargs["interfaces"] not in [None, ""]:
|
||||
devices.params["interfaces"] = kwargs["interfaces"]
|
||||
if "vendor" in kwargs.keys():
|
||||
if kwargs["vendor"] is not None:
|
||||
if kwargs["vendor"]:
|
||||
devices.vendor = kwargs["vendor"]
|
||||
if "product" in kwargs.keys():
|
||||
if kwargs["product"] is not None:
|
||||
if kwargs["product"]:
|
||||
devices.product = kwargs["product"]
|
||||
if "revision" in kwargs.keys():
|
||||
if kwargs["revision"] is not None:
|
||||
if kwargs["revision"]:
|
||||
devices.revision = kwargs["revision"]
|
||||
if "block_size" in kwargs.keys():
|
||||
if kwargs["block_size"] not in [None, ""]:
|
||||
if kwargs["block_size"]:
|
||||
devices.block_size = int(kwargs["block_size"])
|
||||
|
||||
command.devices.append(devices)
|
||||
|
||||
Reference in New Issue
Block a user