From 785357475db3604de29f33f43cc13da76a7e1ef0 Mon Sep 17 00:00:00 2001 From: aronwk-aaron Date: Sat, 17 Dec 2022 01:47:10 -0600 Subject: [PATCH] use cache more modified files so that the client dir never has to be written to --- app/__init__.py | 18 ++++++++++++++++++ app/luclient.py | 8 ++++---- app/properties.py | 2 +- app/pylddlib.py | 4 ++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e1444d1..0462f91 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -11,6 +11,7 @@ from flask_user import user_registered, current_user, user_logged_in from flask_wtf.csrf import CSRFProtect from flask_apscheduler import APScheduler from app.luclient import register_luclient_jinja_helpers +import pathlib from app.commands import ( init_db, @@ -101,6 +102,15 @@ def create_app(): register_blueprints(app) register_luclient_jinja_helpers(app) + # Extract the brickdb if it's not already extracted + materials = pathlib.Path(f'{app.config["CACHE_LOCATION"]}Materials.xml') + if not materials.is_file(): + from zipfile import ZipFile + with ZipFile(f"{app.config['CLIENT_LOCATION']}res/brickdb.zip","r") as zip_ref: + zip_ref.extractall(app.config["CACHE_LOCATION"]) + from shutil import copytree + copytree(f"{app.config['CLIENT_LOCATION']}res/brickprimitives", f"{app.config['CACHE_LOCATION']}brickprimitives") + return app @@ -269,6 +279,7 @@ def register_settings(app): 'USER_EMAIL_SENDER_EMAIL', app.config['USER_EMAIL_SENDER_EMAIL'] ) + if "ENABLE_CHAR_XML_UPLOAD" not in app.config: app.config['ENABLE_CHAR_XML_UPLOAD'] = False app.config['ENABLE_CHAR_XML_UPLOAD'] = os.getenv( @@ -290,6 +301,13 @@ def register_settings(app): app.config['CD_SQLITE_LOCATION'] ) + if "CACHE_LOCATION" not in app.config: + app.config['CACHE_LOCATION'] = 'app/cache/' + app.config['CACHE_LOCATION'] = os.getenv( + 'CACHE_LOCATION', + app.config['CACHE_LOCATION'] + ) + def gm_level(gm_level): diff --git a/app/luclient.py b/app/luclient.py index 416d6f6..c57e664 100644 --- a/app/luclient.py +++ b/app/luclient.py @@ -42,7 +42,7 @@ def get_dds_as_png(filename): with image.Image(filename=path) as img: img.compression = "no" - img.save(filename='app/cache/' + filename.split('.')[0] + '.png') + img.save(filename=current_app.config["CACHE_LOCATION"] + filename.split('.')[0] + '.png') return send_file(cache) @@ -90,7 +90,7 @@ def get_icon_lot(id): else: return redirect(url_for('luclient.unknown')) - cache = f'app/cache/{filename.split(".")[0]}.png' + cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png' if not os.path.exists(cache): root = f"{current_app.config['CLIENT_LOCATION']}res/" @@ -117,7 +117,7 @@ def get_icon_iconid(id): filename = filename.replace("..\\", "").replace("\\", "/") - cache = f'app/cache/{filename.split(".")[0]}.png' + cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png' if not os.path.exists(cache): root = f"{current_app.config['CLIENT_LOCATION']}res/" @@ -174,7 +174,7 @@ def dir_listing(req_path): def unknown(): filename = "textures/ui/inventory/unknown.dds" - cache = f'app/cache/{filename.split(".")[0]}.png' + cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png' if not os.path.exists(cache): root = f"{current_app.config['CLIENT_LOCATION']}res/" diff --git a/app/properties.py b/app/properties.py index 531d85c..3b03d5a 100644 --- a/app/properties.py +++ b/app/properties.py @@ -460,7 +460,7 @@ def prebuilt(content, file_format, lod): # else we handle getting the files for lddviewer elif file_format in ["obj", "mtl"]: # check to see if the file exists - cache = pathlib.Path(f'app/cache/BrickModels/{filename}.lod{lod}.{file_format}') + cache = pathlib.Path(f'{current_app.config["CACHE_LOCATION"]}BrickModels/{filename}.lod{lod}.{file_format}') if not cache.is_file(): # if not make it an store it for later cache.parent.mkdir(parents=True, exist_ok=True) diff --git a/app/pylddlib.py b/app/pylddlib.py index b46618a..43f5a1b 100644 --- a/app/pylddlib.py +++ b/app/pylddlib.py @@ -969,8 +969,8 @@ def main(lxf_filename, obj_filename, lod="2"): GEOMETRIEPATH = GEOMETRIEPATH + f"LOD{lod}/" converter = Converter() # print("Found DB folder. Will use this instead of db.lif!") - setDBFolderVars(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/", lod=lod) - converter.LoadDBFolder(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/") + setDBFolderVars(dbfolderlocation=f"{current_app.config['CACHE_LOCATION']}", lod=lod) + converter.LoadDBFolder(dbfolderlocation=f"{current_app.config['CACHE_LOCATION']}") converter.LoadScene(filename=lxf_filename) converter.Export(filename=obj_filename)