create and delete files
This commit is contained in:
33
src/backend/create_file.py
Normal file
33
src/backend/create_file.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from omegaconf import OmegaConf
|
||||
from src.backend.database import Database
|
||||
|
||||
db = Database()
|
||||
config = OmegaConf.load("config.yaml")
|
||||
|
||||
def recreateFile(name, app_id, filetype, open=True)->Path:
|
||||
"""
|
||||
recreateFile creates a file from the database and opens it in the respective program, if the open parameter is set to True.
|
||||
|
||||
Args:
|
||||
----
|
||||
- name (str): The filename selected by the user.
|
||||
- app_id (str): the id of the apparatus.
|
||||
- filetype (str): the extension of the file to be created.
|
||||
- open (bool, optional): Determines if the file should be opened. Defaults to True.
|
||||
|
||||
Returns:
|
||||
-------
|
||||
- Path: Absolute path to the file.
|
||||
"""
|
||||
path = db.recreateFile(name, app_id, filetype=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
|
||||
13
src/backend/delete_temp_contents.py
Normal file
13
src/backend/delete_temp_contents.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
from omegaconf import OmegaConf
|
||||
config = OmegaConf.load("config.yaml")
|
||||
|
||||
def delete_temp_contents():
|
||||
"""
|
||||
delete_temp_contents deletes the contents of the temp directory.
|
||||
"""
|
||||
for root, dirs, files in os.walk(config.database.tempdir):
|
||||
for file in files:
|
||||
os.remove(os.path.join(root, file))
|
||||
for dir in dirs:
|
||||
os.rmdir(os.path.join(root, dir))
|
||||
Reference in New Issue
Block a user