implement dynamic db name from config
Some checks failed
Ruff / ruff (push) Waiting to run
Mypy / mypy (push) Failing after 44s
Pytest / pytest (3.12) (push) Successful in 50s
Pytest / pytest (3.13) (push) Has been cancelled
Pytest / pytest (3.14) (push) Has been cancelled

This commit is contained in:
Justus Kuhlmann 2025-12-04 14:31:53 +01:00
commit 0626b34337
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
5 changed files with 60 additions and 27 deletions

View file

@ -5,7 +5,7 @@ import os
from .git_tools import move_submodule
import shutil
from .find import _project_lookup_by_id
from .tools import list2str, str2list
from .tools import list2str, str2list, get_db_file
from .tracker import get, save
from typing import Union, Optional
@ -25,8 +25,9 @@ def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Uni
code: str (optional)
The code that was used to create the measurements.
"""
db = path + "/backlogger.db"
get(path, "backlogger.db")
db_file = get_db_file(path)
db = os.path.join(path, db_file)
get(path, db_file)
conn = sqlite3.connect(db)
c = conn.cursor()
known_projects = c.execute("SELECT * FROM projects WHERE id=?", (uuid,))
@ -43,12 +44,13 @@ def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Uni
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))", (uuid, alias_str, tag_str, owner, code))
conn.commit()
conn.close()
save(path, message="Added entry for project " + uuid + " to database", files=["backlogger.db"])
save(path, message="Added entry for project " + uuid + " to database", files=[db_file])
def update_project_data(path: str, uuid: str, prop: str, value: Union[str, None] = None) -> None:
get(path, "backlogger.db")
conn = sqlite3.connect(os.path.join(path, "backlogger.db"))
db_file = get_db_file(path)
get(path, db_file)
conn = sqlite3.connect(os.path.join(path, db_file))
c = conn.cursor()
c.execute(f"UPDATE projects SET '{prop}' = '{value}' WHERE id == '{uuid}'")
conn.commit()
@ -57,8 +59,8 @@ def update_project_data(path: str, uuid: str, prop: str, value: Union[str, None]
def update_aliases(path: str, uuid: str, aliases: list[str]) -> None:
db = os.path.join(path, "backlogger.db")
get(path, "backlogger.db")
db_file = get_db_file(path)
get(path, db_file)
known_data = _project_lookup_by_id(db, uuid)[0]
known_aliases = known_data[1]
@ -77,9 +79,10 @@ def update_aliases(path: str, uuid: str, aliases: list[str]) -> None:
if not len(new_alias_list) == len(known_alias_list):
alias_str = list2str(new_alias_list)
db = os.path.join(path, db_file)
dl.unlock(db, dataset=path)
update_project_data(path, uuid, "aliases", alias_str)
save(path, message="Updated aliases for project " + uuid, files=["backlogger.db"])
save(path, message="Updated aliases for project " + uuid, files=[db_file])
return
@ -122,13 +125,14 @@ def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Opti
if not uuid:
raise ValueError("The dataset does not have a uuid!")
if not os.path.exists(path + "/projects/" + uuid):
db = path + "/backlogger.db"
get(path, "backlogger.db")
db_file = get_db_file(path)
db = os.path.join(path, db_file)
get(path, db_file)
dl.unlock(db, dataset=path)
create_project(path, uuid, owner, tags, aliases, code)
move_submodule(path, 'projects/tmp', 'projects/' + uuid)
os.mkdir(path + '/import_scripts/' + uuid)
save(path, message="Import project from " + url, files=['projects/' + uuid, 'backlogger.db'])
save(path, message="Import project from " + url, files=['projects/' + uuid, db_file])
else:
dl.drop(tmp_path, reckless='kill')
shutil.rmtree(tmp_path)