From: Max Value Date: Wed, 13 May 2026 21:29:27 +0000 (+0100) Subject: Added DELTA_PATH envvar X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=refs%2Fheads%2Fmain;p=delta-velorum Added DELTA_PATH envvar sorry guys i folded --- diff --git a/argo/__init__.py b/argo/__init__.py index f3e03d6..02c66de 100644 --- a/argo/__init__.py +++ b/argo/__init__.py @@ -9,6 +9,8 @@ import os from .utils import deindex STAR = os.getenv("DELTA_VELORUM", "B") +PATH = os.getenv("DELTA_PATH") + import argo.admin as admin from argo.database.read import read_views as database_read_views @@ -18,9 +20,11 @@ socketio = SocketIO(app, logger=False, engineio_logger=False) auth = HTTPBasicAuth() CORS(app) +app.root_path = f"{PATH}/argo/" + # import authentication data -with open(f"{app.root_path}/../../secrets.json", "r", encoding="utf-8") as f: +with open(f"{PATH}/../secrets.json", "r", encoding="utf-8") as f: users = json.loads(f.read()) users = {k: generate_password_hash(v) for (k, v) in users.items()} @@ -61,9 +65,9 @@ app.route("/admin/", methods=["get", "post"])(auth.login_requ @app.route("/script/", methods=["get"]) def script(filename): - return send_from_directory(os.path.join(app.root_path, "build"), filename) + return send_from_directory(os.path.join(PATH, "argo", "build"), filename) @app.route("/db", methods=["get"]) @auth.login_required def download_db(): - return send_from_directory(f"{app.root_path}/../data", "main.db") + return send_from_directory(f"{PATH}/data", "main.db") diff --git a/argo/admin.py b/argo/admin.py index 65e4cb5..9a58ef7 100644 --- a/argo/admin.py +++ b/argo/admin.py @@ -12,8 +12,7 @@ from argo.database.read import read as database_read from argo import STAR def admin_main(): - from argo import app - assets = glob(os.path.join(app.root_path, "static", "media", "assets", "*")) + assets = glob(os.path.join(os.getenv("DELTA_PATH"), "argo", "static", "media", "assets", "*")) assets = [path.split("argo")[-1] for path in assets] return render_template( diff --git a/argo/database/__init__.py b/argo/database/__init__.py index e408c87..e7b5516 100644 --- a/argo/database/__init__.py +++ b/argo/database/__init__.py @@ -4,11 +4,14 @@ check if file exists and pragam check the database on init """ -from .utils import integrity_check, optimize import sqlite3 import os -assert os.path.exists("./data/main.db"), "Database missing" +PATH = f"{os.getenv('DELTA_PATH')}/data/main.db" + +from .utils import integrity_check, optimize + +assert os.path.exists(PATH), "Database missing" assert integrity_check(), "Database integrity error" optimize() diff --git a/argo/database/read.py b/argo/database/read.py index b180b39..7452b4c 100644 --- a/argo/database/read.py +++ b/argo/database/read.py @@ -1,12 +1,13 @@ import sqlite3 from .utils import list_all, list_views +from . import PATH def read_all_current(): tables = list_all() indexes = read_indexes() - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() data = {} @@ -30,7 +31,7 @@ def read(table): """ reads a table by name """ - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() cursor.execute(f"SELECT * FROM {table};") @@ -58,7 +59,7 @@ def read_views(table=None): return data def read_indexes(): - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() cursor.execute("SELECT * FROM indexes;") diff --git a/argo/database/utils.py b/argo/database/utils.py index 6866761..b9e3c1b 100644 --- a/argo/database/utils.py +++ b/argo/database/utils.py @@ -1,10 +1,12 @@ import sqlite3 +from . import PATH + def integrity_check(): """ check the database is ok and return true if it is """ - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() integrity = cursor.execute('PRAGMA integrity_check') @@ -14,7 +16,7 @@ def optimize(): """ check the database is ok and return true if it is """ - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() integrity = cursor.execute('PRAGMA optimize') @@ -22,7 +24,7 @@ def list_all(): """ get a list of all the tables and views in the database """ - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() cursor.execute("SELECT name FROM sqlite_master WHERE type IN ('table', 'view');") return [table[0] for table in cursor.fetchall()] @@ -31,7 +33,7 @@ def list_views(): """ get a list of all the views in the database """ - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() cursor.execute("SELECT name FROM sqlite_master WHERE type='view';") return [table[0] for table in cursor.fetchall()] diff --git a/argo/database/write.py b/argo/database/write.py index eea0126..36bef90 100644 --- a/argo/database/write.py +++ b/argo/database/write.py @@ -3,9 +3,11 @@ import sqlite3 from .utils import list_all from .read import read +from . import PATH + def write(data): - with sqlite3.connect("./data/main.db") as connection: + with sqlite3.connect(PATH) as connection: cursor = connection.cursor() for key in data: