feat: create config class to replace use of config file in application
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user