From e0f5a7e17c9bdbbc9c52783078a24c737b42b163 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Wed, 13 Oct 2021 18:51:45 -0700 Subject: [PATCH] Change properties file name pattern to include the original file ending; other cleanup (#325) --- src/web/file_cmds.py | 12 ++++++-- src/web/templates/index.html | 2 +- src/web/web.py | 59 ++++++------------------------------ 3 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py index 4a0ec87e..30b8ddf0 100644 --- a/src/web/file_cmds.py +++ b/src/web/file_cmds.py @@ -68,13 +68,21 @@ def list_images(): files = [] for f in result.image_files_info.image_files: # Add flag for whether an image file has an associated *.properties file - if PurePath(f.name).stem in prop_files: + if f.name in prop_files: prop = True else: prop = False size_mb = "{:,.1f}".format(f.size / 1024 / 1024) dtype = proto.PbDeviceType.Name(f.type) - files.append({"name": f.name, "size": f.size, "size_mb": size_mb, "detected_type": dtype, "prop": prop}) + files.append( + { + "name": f.name, + "size": f.size, + "size_mb": size_mb, + "detected_type": dtype, + "prop": prop, + } + ) return {"status": result.status, "msg": result.msg, "files": files} diff --git a/src/web/templates/index.html b/src/web/templates/index.html index b57cf909..3bb5fd64 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -333,7 +333,7 @@ -

Ceate a named disk image that mimics real-life drives

+

Create a named disk image that mimics real-life drives


diff --git a/src/web/web.py b/src/web/web.py index 759bcf69..fcc4e46c 100644 --- a/src/web/web.py +++ b/src/web/web.py @@ -192,16 +192,15 @@ def drive_create(): return redirect(url_for("index")) # Creating the drive properties file - from pathlib import Path - file_name = str(Path(file_name).stem) + "." + PROPERTIES_SUFFIX + prop_file_name = f"{file_name}.{file_type}.{PROPERTIES_SUFFIX}" properties = {"vendor": vendor, "product": product, \ "revision": revision, "block_size": block_size} - process = write_drive_properties(file_name, properties) + process = write_drive_properties(prop_file_name, properties) if process["status"] == True: - flash(f"Drive properties file {file_name} created") + flash(f"Drive properties file {prop_file_name} created") return redirect(url_for("index")) else: - flash(f"Failed to create drive properties file {file_name}", "error") + flash(f"Failed to create drive properties file {prop_file_name}", "error") return redirect(url_for("index")) @@ -347,12 +346,11 @@ def attach(): expected_block_size = 256 # Attempt to load the device properties file: - # same base path but PROPERTIES_SUFFIX instead of the original suffix. + # same base path but with PROPERTIES_SUFFIX appended from pathlib import Path - file_name_base = str(Path(file_name).stem) - drive_properties = Path(cfg_dir + file_name_base + "." + PROPERTIES_SUFFIX) - if drive_properties.is_file(): - process = read_drive_properties(str(drive_properties)) + drive_properties = f"{cfg_dir}{file_name}.{PROPERTIES_SUFFIX}" + if Path(drive_properties).is_file(): + process = read_drive_properties(drive_properties) if process["status"] == False: flash(f"Failed to load the device properties \ file {file_name_base}.{PROPERTIES_SUFFIX}", "error") @@ -577,42 +575,6 @@ def create_file(): return redirect(url_for("index")) -@app.route("/files/pad", methods=["POST"]) -def image_padding(): - image = request.form.get("image") - multiple = request.form.get("multiple") - - if not image: - flash(f"No file selected!", "error") - return redirect(url_for("index")) - - file, size = image.split(",") - - if not int(size) % int(multiple): - flash(f"{file} does not need to be padded!", "error") - return redirect(url_for("index")) - else: - target_size = int(size) - (int(size) % int(multiple)) + int(multiple) - - server_info = get_server_info() - - from pathlib import PurePath - padded_image = server_info["image_dir"] + str(PurePath(file).stem) + \ - "_padded" + str(PurePath(file).suffix) - from shutil import copyfile - copyfile(server_info["image_dir"] + file, padded_image) - - process = pad_image(padded_image, target_size) - if process["status"] == True: - flash(f"Added " + str(target_size - int(size)) + " bytes to " + padded_image + "!") - flash(process["msg"]) - return redirect(url_for("index")) - else: - flash(f"Failed to pad image!", "error") - flash(process["msg"], "error") - return redirect(url_for("index")) - - @app.route("/files/download", methods=["POST"]) def download(): image = request.form.get("image") @@ -653,10 +615,9 @@ def delete(): @app.route("/files/prop", methods=["POST"]) def show_properties(): file_name = request.form.get("image") - from pathlib import PurePath - file_name = str(PurePath(file_name).stem) + "." + PROPERTIES_SUFFIX + file_path = f"{cfg_dir}{file_name}.{PROPERTIES_SUFFIX}" - process = read_drive_properties(cfg_dir + file_name) + process = read_drive_properties(file_path) prop = process["conf"] if process["status"]: