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
This commit is contained in:
Daniel Markstedt 2021-12-12 16:52:35 -08:00 committed by GitHub
parent aa0e5a287b
commit 7dce1bc3b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 16 deletions

View File

@ -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):

View File

@ -436,11 +436,12 @@
<details>
<summary class="heading">
Download File and Create HFS CD (Macintosh)
Download File and Create CD-ROM ISO image
</summary>
<ul>
<li>Given a URL this will download a file, create a HFS iso, and mount it on the SCSI ID given.</li>
<li>Requires a <a href="https://github.com/akuker/RASCSI/wiki/Drive-Setup#Mounting_CD_ISO_or_MO_images">compatible CD-ROM driver</a> installed on the target system.
<li>Given a URL this will download a file, create a CD-ROM image with the selected file system, and mount it on the SCSI ID given.</li>
<li>HFS is for Mac OS, Joliet for Windows, and Rock Ridge for POSIX.</li>
<li>On Mac OS, requires a <a href="https://github.com/akuker/RASCSI/wiki/Drive-Setup#Mounting_CD_ISO_or_MO_images">compatible CD-ROM driver</a> installed on the target system.
</li>
</ul>
</details>
@ -458,6 +459,27 @@
</select>
<label for="url">URL:</label>
<input name="url" placeholder="URL" required="" type="url">
<label for="type">Type:</label>
<select name="type">
<option value="-hfs">
HFS
</option>
<option value="-iso-level 1">
ISO-9660 Level 1
</option>
<option value="-iso-level 2">
ISO-9660 Level 2
</option>
<option value="-iso-level 3">
ISO-9660 Level 3
</option>
<option value="-J">
Joliet
</option>
<option value="-r">
Rock Ridge
</option>
</select>
<input type="submit" value="Download and Mount ISO" onclick="processNotify('Downloading File as ISO...')">
</form>
</td>

View File

@ -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")