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