Increased flexibility and folder obscuring.

This commit is contained in:
lwark
2024-07-26 08:17:03 -05:00
parent 2a34f855aa
commit 428e47859c
5 changed files with 47 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
## 202407.04
- Added support for postgresql databases (auto backup not functional).
- Improved portability and folder obscuring.
## 202407.02

6
src/config.yml Normal file
View File

@@ -0,0 +1,6 @@
directory_path: null
database_path: null
database_schema: sqlite
database_user: null
database_password: null
database_name: null

View File

@@ -472,7 +472,10 @@ class BasicSubmission(BaseClass):
except:
logger.warning(f"Couldn't drop '{item}' column from submissionsheet df.")
if chronologic:
try:
df.sort_values(by="id", axis=0, inplace=True, ascending=False)
except KeyError:
logger.error("No column named 'id'")
# NOTE: Human friendly column labels
df.columns = [item.replace("_", " ").title() for item in df.columns]
return df

View File

@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import QMainWindow, QFileDialog
logger = logging.getLogger(f"submissions.{__name__}")
def select_open_file(obj:QMainWindow, file_extension:str) -> Path:
def select_open_file(obj: QMainWindow, file_extension: str | None = None) -> Path:
"""
File dialog to select a file to read from
@@ -26,7 +26,11 @@ def select_open_file(obj:QMainWindow, file_extension:str) -> Path:
home_dir = Path.home().resolve().__str__()
except AttributeError:
home_dir = obj.app.last_dir.resolve().__str__()
fname = Path(QFileDialog.getOpenFileName(obj, 'Open file', home_dir, filter = f"{file_extension}(*.{file_extension})")[0])
if file_extension is None:
fname = Path(QFileDialog.getExistingDirectory(obj, "Open Folder", home_dir))
else:
fname = Path(
QFileDialog.getOpenFileName(obj, 'Open file', home_dir, filter=f"{file_extension}(*.{file_extension})")[0])
obj.last_dir = fname.parent
return fname

View File

@@ -25,6 +25,8 @@ from openpyxl.worksheet.worksheet import Worksheet
from PyQt6.QtPrintSupport import QPrinter
from __init__ import project_path
from configparser import ConfigParser
from tkinter import Tk # from tkinter import Tk for Python 3.x
from tkinter.filedialog import askdirectory
logger = logging.getLogger(f"submissions.{__name__}")
@@ -261,14 +263,14 @@ class Settings(BaseSettings, extra="allow"):
@classmethod
def ensure_directory_exists(cls, value):
if value is None:
print("No value for dir path")
# print("No value for dir path")
if check_if_app():
alembic_path = Path(sys._MEIPASS).joinpath("files", "alembic.ini")
else:
alembic_path = project_path.joinpath("alembic.ini")
print(f"Getting alembic path: {alembic_path}")
value = cls.get_alembic_db_path(alembic_path=alembic_path)
print(f"Using {value}")
# print(f"Getting alembic path: {alembic_path}")
value = cls.get_alembic_db_path(alembic_path=alembic_path).parent
# print(f"Using {value}")
if isinstance(value, str):
value = Path(value)
try:
@@ -276,11 +278,12 @@ class Settings(BaseSettings, extra="allow"):
except AttributeError:
check = False
if not check:
print(f"No directory found, using Documents/submissions")
value = Path.home().joinpath("Documents", "submissions")
value.mkdir()
# metadata.directory_path = value
print(f"Final return of directory_path: {value}")
# print(f"No directory found, using Documents/submissions")
# value = Path.home().joinpath("Documents", "submissions")
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
value = Path(askdirectory(title="Select directory for DB storage")) # show an "Open" dialog box and return the path to the selected file
value.mkdir(exist_ok=True)
# print(f"Final return of directory_path: {value}")
return value
@field_validator('database_path', mode="before")
@@ -357,6 +360,18 @@ class Settings(BaseSettings, extra="allow"):
if value is None:
return package
@field_validator('database_name', mode='before')
@classmethod
def get_database_name(cls, value, values):
if value is None:
if check_if_app():
alembic_path = Path(sys._MEIPASS).joinpath("files", "alembic.ini")
else:
alembic_path = project_path.joinpath("alembic.ini")
# print(f"Getting alembic path: {alembic_path}")
value = cls.get_alembic_db_path(alembic_path=alembic_path).stem
return value
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -389,13 +404,13 @@ class Settings(BaseSettings, extra="allow"):
c = ConfigParser()
c.read(alembic_path)
path = c['alembic']['sqlalchemy.url'].replace("sqlite:///", "")
return Path(path).parent
return Path(path)
def save(self, settings_path:Path):
if not settings_path.exists():
dicto = {}
for k,v in self.__dict__.items():
if k in ['package', 'database_session']:
if k in ['package', 'database_session', 'submission_types']:
continue
match v:
case Path():