feat: create config class to replace use of config file in application

This commit is contained in:
WorldTeacher
2024-10-29 16:07:30 +01:00
parent 2137799f9b
commit f3eed7486d
13 changed files with 224 additions and 111 deletions

View File

@@ -2,12 +2,10 @@ import os
from pathlib import Path
from icecream import ic
from omegaconf import OmegaConf
from src.backend.database import Database
db = Database()
config = OmegaConf.load("config.yaml")
def recreateFile(name, app_id, filetype, open=True) -> Path:

View File

@@ -3,6 +3,7 @@ import inspect
import sqlite3 as sql
import tempfile
from pathlib import Path
from src import database
from typing import Any, Dict, List, Optional, Tuple, Union
# from icecream import ic
from omegaconf import OmegaConf
@@ -28,7 +29,7 @@ from src.utils import create_blob, dump_pickle, load_pickle
from .semester import generateSemesterByDate
from icecream import ic
config = OmegaConf.load("config.yaml")
ascii_lowercase = "abcdefghijklmnopqrstuvwxyz0123456789)"
caller_frame = inspect.stack()[1]
# get the line that called the function
@@ -54,14 +55,14 @@ class Database:
self.name = script_name
self.logger = MyLogger(name)
if db_path is None:
self.db_path = config.database.path + config.database.name
self.db_path = database.path + database.name
self.db_path = self.db_path.replace("~", str(Path.home()))
else:
self.db_path = db_path
self.checkDatabaseStatus()
def checkDatabaseStatus(self):
path = config.database.path
path = database.path
path = path.replace("~", str(Path.home()))
# print(path)
path = os.path.abspath(path)
@@ -507,7 +508,7 @@ class Database:
str: The filename of the recreated file
"""
blob = self.getBlob(filename, app_id)
tempdir = config.database.tempdir
tempdir = database.tempdir
tempdir = tempdir.replace("~", str(Path.home()))
tempdir_path = Path(tempdir)
if not os.path.exists(tempdir_path):
@@ -1414,7 +1415,7 @@ class Database:
"SELECT fileblob FROM elsa_files WHERE filename=?", (filename,), one=True
)[0]
# print(blob)
tempdir = config.database.tempdir
tempdir = database.tempdir
tempdir = tempdir.replace("~", str(Path.home()))
tempdir_path = Path(tempdir)
if not os.path.exists(tempdir_path):

View File

@@ -1,16 +1,14 @@
import os
from pathlib import Path
from src import database
from omegaconf import OmegaConf
config = OmegaConf.load("config.yaml")
def delete_temp_contents():
"""
delete_temp_contents deletes the contents of the temp directory.
"""
path = config.database.tempdir
path = database.tempdir
path = path.replace("~", str(Path.home()))
path = Path(path)
path = path.resolve()