From 7dce1bc3b9b413164552ceada23a7deda010f442 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Sun, 12 Dec 2021 16:52:35 -0800 Subject: [PATCH] The ability to create ISO images of various types (#520) * Better error handling * Ability to create ISO images of various types * Remove ISO v2 option, since I couldn't test that it works * Add help text * Fix typo --- src/web/file_cmds.py | 37 +++++++++++++++++++++++++----------- src/web/templates/index.html | 28 ++++++++++++++++++++++++--- src/web/web.py | 6 ++++-- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/web/file_cmds.py b/src/web/file_cmds.py index e561639c..35948a67 100644 --- a/src/web/file_cmds.py +++ b/src/web/file_cmds.py @@ -217,13 +217,13 @@ def unzip_file(file_name, member=False, members=False): return {"status": True, "msg": unzipped, "prop_flag": prop_flag} -def download_file_to_iso(url): +def download_file_to_iso(url, *iso_args): """ - Takes (int) scsi_id and (str) url + Takes (str) url and one or more (str) *iso_args Returns (dict) with (bool) status and (str) msg """ from time import time - from subprocess import run + from subprocess import run, CalledProcessError server_info = get_server_info() @@ -239,15 +239,30 @@ def download_file_to_iso(url): if not req_proc["status"]: return {"status": False, "msg": req_proc["msg"]} - iso_proc = run( - ["genisoimage", "-hfs", "-o", iso_filename, tmp_full_path], - capture_output=True, - check=True, - ) - if iso_proc.returncode != 0: - return {"status": False, "msg": iso_proc.stderr.decode("utf-8")} + try: + iso_proc = ( + run( + [ + "genisoimage", + *iso_args, + "-o", + iso_filename, + tmp_full_path, + ], + capture_output=True, + check=True, + ) + ) + except CalledProcessError as error: + logging.warning("Executed shell command: %s", " ".join(error.cmd)) + logging.warning("Got error: %s", error.stderr.decode("utf-8")) + return {"status": False, "msg": error.stderr.decode("utf-8")} - return {"status": True, "msg": iso_proc.stdout.decode("utf-8"), "file_name": iso_filename} + return { + "status": True, + "msg": f"Created CD-ROM ISO image with arguments \"" + " ".join(iso_args) + "\"", + "file_name": iso_filename, + } def download_to_dir(url, save_dir): diff --git a/src/web/templates/index.html b/src/web/templates/index.html index 9c2612fd..116f618a 100644 --- a/src/web/templates/index.html +++ b/src/web/templates/index.html @@ -436,11 +436,12 @@
- Download File and Create HFS CD (Macintosh) + Download File and Create CD-ROM ISO image
@@ -458,6 +459,27 @@ + + diff --git a/src/web/web.py b/src/web/web.py index 577068c2..cab74e65 100644 --- a/src/web/web.py +++ b/src/web/web.py @@ -770,10 +770,12 @@ def download_to_iso(): scsi_id = request.form.get("scsi_id") url = request.form.get("url") + iso_args = request.form.get("type").split() - process = download_file_to_iso(url) + process = download_file_to_iso(url, *iso_args) if process["status"]: - flash(f"Created CD-ROM image: {process['file_name']}") + flash(process["msg"]) + flash(f"Saved image as: {process['file_name']}") else: flash(f"Failed to create CD-ROM image from {url}", "error") flash(process["msg"], "error")