Merge pull request #883 from akuker/rdmark-generalize-properties

Allow for generating properties files in the Create Image UI
This commit is contained in:
Daniel Markstedt 2022-10-02 09:49:49 -07:00 committed by GitHub
commit 2dae021cdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View File

@ -589,6 +589,17 @@
</select> </select>
<label for="size">{{ _("Size:") }}</label> <label for="size">{{ _("Size:") }}</label>
<input name="size" type="number" placeholder="{{ _("MiB") }}" min="1" max="262144" required> <input name="size" type="number" placeholder="{{ _("MiB") }}" min="1" max="262144" required>
<label for="drive_name">{{ _("Masquerade as:") }}</label>
<select name="drive_name">
<option value="">
{{ _("None") }}
</option>
{% for drive in drive_properties["hd_conf"] | sort(attribute='name') %}
<option value="{{ drive.name }}">
{{ drive.name }}
</option>
{% endfor %}
</select>
<input type="submit" value="{{ _("Create") }}"> <input type="submit" value="{{ _("Create") }}">
</form> </form>
</td> </td>

View File

@ -876,17 +876,33 @@ def create_file():
file_name = request.form.get("file_name") file_name = request.form.get("file_name")
size = (int(request.form.get("size")) * 1024 * 1024) size = (int(request.form.get("size")) * 1024 * 1024)
file_type = request.form.get("type") file_type = request.form.get("type")
drive_name = request.form.get("drive_name")
full_file_name = file_name + "." + file_type full_file_name = file_name + "." + file_type
process = file_cmd.create_new_image(file_name, file_type, size) process = file_cmd.create_new_image(file_name, file_type, size)
if process["status"]: if not process["status"]:
return response( return response(error=True, message=process["msg"])
status_code=201,
message=_("Image file created: %(file_name)s", file_name=full_file_name),
image=full_file_name,
)
return response(error=True, message=process["msg"]) # Creating the drive properties file, if one is chosen
if drive_name:
drive_props = None
for drive in APP.config["RASCSI_DRIVE_PROPERTIES"]:
if drive["name"] == drive_name:
drive_props = drive
break
properties = {
"vendor": drive_props["vendor"],
"product": drive_props["product"],
"revision": drive_props["revision"],
"block_size": drive_props["block_size"],
}
prop_file_name = f"{full_file_name}.{PROPERTIES_SUFFIX}"
process = file_cmd.write_drive_properties(prop_file_name, properties)
process = ReturnCodeMapper.add_msg(process)
if not process["status"]:
return response(error=True, message=process["msg"])
return response(message=_("Image file created: %(file_name)s", file_name=full_file_name))
@APP.route("/files/download", methods=["POST"]) @APP.route("/files/download", methods=["POST"])