mirror of
https://github.com/akuker/RASCSI.git
synced 2025-03-29 14:31:33 +00:00
Use native unzip instead of python zipfile lib for better performance
This commit is contained in:
parent
c9c97baa3c
commit
b73ef29f06
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
from ractl_cmds import (
|
||||
@ -63,20 +62,23 @@ def delete_file(file_name):
|
||||
|
||||
|
||||
def unzip_file(file_name):
|
||||
from zipfile import ZipFile, is_zipfile
|
||||
from subprocess import run
|
||||
|
||||
if is_zipfile(file_name):
|
||||
with zipfile.ZipFile(base_dir + file_name, "r") as zip_ref:
|
||||
zip_ref.extractall(base_dir)
|
||||
return {"status": True, "msg": f"{file_name} unzipped"}
|
||||
else:
|
||||
return {"status": False, "msg": f"{file_name} is not a zip file"}
|
||||
unzip_proc = run(
|
||||
["unzip", "-d", base_dir, "-o", "-j", base_dir + file_name], capture_output=True
|
||||
)
|
||||
if unzip_proc.returncode != 0:
|
||||
logging.warning(f"Unzipping failed: {unzip_proc}")
|
||||
return {"status": False, "msg": unzip_proc}
|
||||
|
||||
return {"status": True, "msg": f"{file_name} unzipped"}
|
||||
|
||||
|
||||
def download_file_to_iso(scsi_id, url):
|
||||
import urllib.request
|
||||
import urllib.error as error
|
||||
import time
|
||||
from subprocess import run
|
||||
|
||||
file_name = url.split("/")[-1]
|
||||
tmp_ts = int(time.time())
|
||||
@ -94,7 +96,7 @@ def download_file_to_iso(scsi_id, url):
|
||||
return {"status": False, "msg": "Error loading the URL"}
|
||||
|
||||
# iso_filename = make_cd(tmp_full_path, None, None) # not working yet
|
||||
iso_proc = subprocess.run(
|
||||
iso_proc = run(
|
||||
["genisoimage", "-hfs", "-o", iso_filename, tmp_full_path], capture_output=True
|
||||
)
|
||||
if iso_proc.returncode != 0:
|
||||
|
@ -522,14 +522,14 @@ def upload_file():
|
||||
return make_response(("Transferred file corrupted!", 500))
|
||||
else:
|
||||
log.info(f"File {file.filename} has been uploaded successfully")
|
||||
if filename.lower().endswith(".zip"):
|
||||
unzip_file(filename)
|
||||
else:
|
||||
log.debug(f"Chunk {current_chunk + 1} of {total_chunks} "
|
||||
f"for file {file.filename} completed.")
|
||||
|
||||
if unzip_file(filename):
|
||||
return make_response(("File upload and unzip successful!", 200))
|
||||
else:
|
||||
return make_response(("File upload successful!", 200))
|
||||
|
||||
return make_response(("File upload successful!", 200))
|
||||
|
||||
|
||||
@app.route("/files/create", methods=["POST"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user