add elsa function to recreate the file

This commit is contained in:
WorldTeacher
2024-05-24 10:08:37 +02:00
parent f204ed2b30
commit 874c871923

View File

@@ -1,6 +1,7 @@
import os import os
from pathlib import Path from pathlib import Path
from icecream import ic
from omegaconf import OmegaConf from omegaconf import OmegaConf
from src.backend.database import Database from src.backend.database import Database
@@ -34,3 +35,32 @@ def recreateFile(name, app_id, filetype, open=True) -> Path:
path = path.resolve() path = path.resolve()
os.system(f"open {path}") os.system(f"open {path}")
return path return path
def recreateElsaFile(filename: str, filetype: str, open=True) -> Path:
"""
recreateElsaFile creates a file from the database and opens it in the respective program, if the open parameter is set to True.
Args:
----
- filename (str): The filename selected by the user.
- open (bool, optional): Determines if the file should be opened. Defaults to True.
Returns:
-------
- Path: Absolute path to the file.
"""
if filename.startswith("(") and filename.endswith(")"):
filename = str(filename[1:-1].replace("'", ""))
if not isinstance(filename, str):
raise ValueError("filename must be a string")
path = db.recreateElsaFile(filename, filetype)
path = Path(path)
if open:
if os.getenv("OS") == "Windows_NT":
path = path.resolve()
os.startfile(path)
else:
path = path.resolve()
os.system(f"open {path}")
return path