fix path decoding
This commit is contained in:
@@ -19,9 +19,11 @@ from src.backend.db import (
|
||||
CREATE_TABLE_SUBJECTS,
|
||||
CREATE_TABLE_USER,
|
||||
)
|
||||
from pathlib import Path
|
||||
from src.errors import AppPresentError, NoResultError
|
||||
from src.logic import ApparatData, BookData, Prof, Apparat, ELSA
|
||||
from src.logic.constants import SEMAP_MEDIA_ACCOUNTS
|
||||
from src.utils.blob import create_blob
|
||||
from .semester import Semester
|
||||
from string import ascii_lowercase as lower, digits, punctuation
|
||||
import loguru
|
||||
@@ -29,7 +31,7 @@ import sys
|
||||
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add(sys.stdout)
|
||||
log.add(sys.stdout, level="INFO")
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
|
||||
@@ -44,7 +46,7 @@ class Database:
|
||||
Initialize the database and create the tables if they do not exist.
|
||||
"""
|
||||
|
||||
def __init__(self, db_path: str = None):
|
||||
def __init__(self, db_path: Path = None):
|
||||
"""
|
||||
Default constructor for the database class
|
||||
|
||||
@@ -52,17 +54,17 @@ class Database:
|
||||
db_path (str, optional): Optional Path for testing / specific purposes. Defaults to None.
|
||||
"""
|
||||
if db_path is None:
|
||||
self.db_path = self.database.path + self.database.name
|
||||
self.db_path = self.db_path.replace("~", str(Path.home()))
|
||||
self.db_path = Path(self.database.path.expanduser(), self.database.name)
|
||||
# self.db_path = self.db_path.replace("~", str(Path.home()))
|
||||
log.debug(self.db_path)
|
||||
else:
|
||||
self.db_path = db_path
|
||||
self.checkDatabaseStatus()
|
||||
|
||||
def checkDatabaseStatus(self):
|
||||
path = self.database.path
|
||||
path = path.replace("~", str(Path.home()))
|
||||
path = os.path.abspath(path)
|
||||
path = self.database.path.expanduser()
|
||||
# path = path.replace("~", str(Path.home()))
|
||||
# path = os.path.abspath(path)
|
||||
if not os.path.exists(path):
|
||||
# create path
|
||||
# log.debug(path)
|
||||
@@ -503,11 +505,9 @@ class Database:
|
||||
str: The filename of the recreated file
|
||||
"""
|
||||
blob = self.getBlob(filename, app_id)
|
||||
tempdir = self.database.temp
|
||||
tempdir = tempdir.replace("~", str(Path.home()))
|
||||
tempdir_path = Path(tempdir)
|
||||
if not os.path.exists(tempdir_path):
|
||||
os.mkdir(tempdir_path)
|
||||
tempdir = self.database.temp.expanduser()
|
||||
if not tempdir.exists():
|
||||
tempdir.mkdir(parents=True, exist_ok=True)
|
||||
file = tempfile.NamedTemporaryFile(
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
@@ -1463,11 +1463,10 @@ class Database:
|
||||
"SELECT fileblob FROM elsa_files WHERE filename=?", (filename,), one=True
|
||||
)[0]
|
||||
# log.debug(blob)
|
||||
tempdir = self.database.temp
|
||||
tempdir = tempdir.replace("~", str(Path.home()))
|
||||
tempdir_path = Path(tempdir)
|
||||
if not os.path.exists(tempdir_path):
|
||||
os.mkdir(tempdir_path)
|
||||
tempdir = self.database.temp.expanduser()
|
||||
if not tempdir.exists():
|
||||
tempdir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
file = tempfile.NamedTemporaryFile(
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
|
||||
@@ -9,10 +9,7 @@ def delete_temp_contents():
|
||||
"""
|
||||
delete_temp_contents deletes the contents of the temp directory.
|
||||
"""
|
||||
path = database.temp
|
||||
path = path.replace("~", str(Path.home()))
|
||||
path = Path(path)
|
||||
path = path.resolve()
|
||||
path = database.temp.expanduser()
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
os.remove(os.path.join(root, file))
|
||||
|
||||
Reference in New Issue
Block a user