bug fixes around owners and tags

This commit is contained in:
Justus Kuhlmann 2025-03-31 13:59:19 +00:00
parent bd1468ad8f
commit dbd493921f

View file

@ -6,9 +6,10 @@ from .git_tools import move_submodule
import shutil
from .find import _project_lookup_by_id
from .tools import list2str, str2list
from typing import Union
def create_project(path, uuid, aliases=None, code=None):
def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Union[str, None]=None, aliases: Union[str, None]=None, code: Union[str, None]=None):
"""
Create a new project entry in the database.
@ -30,9 +31,13 @@ def create_project(path, uuid, aliases=None, code=None):
raise ValueError("Project already imported, use update_project() instead.")
dl.unlock(path + "/backlogger.db", dataset=path)
alias_str = None
if aliases is not None:
alias_str = list2str(aliases)
c.execute("INSERT INTO projects (id, aliases, code, created_at, updated_at) VALUES (?, ?, ?, datetime('now'), datetime('now'))", (uuid, alias_str, code))
tag_str = None
if tags is not None:
tag_str = list2str(tags)
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()
dl.save(path + "/backlogger.db", message="Added entry for project " + uuid + " to database", dataset=path)
@ -47,7 +52,7 @@ def update_project_data(db, uuid, prop, value = None):
return
def import_project(path, url, aliases=None, code=None, isDataset=True):
def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Union[str, None]=None, aliases: Union[str, None]=None, code: Union[str, None]=None, isDataset: bool=True):
"""
Parameters
----------
@ -87,12 +92,14 @@ def import_project(path, url, aliases=None, code=None, isDataset=True):
raise ValueError("The dataset does not have a uuid!")
if not os.path.exists(path + "/projects/" + uuid):
dl.unlock(path + "/backlogger.db", dataset=path)
create_project(path, uuid, aliases, code)
create_project(path, uuid, owner, tags, aliases, code)
move_submodule(path, 'projects/tmp', 'projects/' + uuid)
os.mkdir(path + '/import_scripts/' + uuid)
dl.save([path + "/backlogger.db", path + '/projects/' + uuid], message="Import project from " + url, dataset=path)
else:
known_data = _project_lookup_by_id(uuid)[0]
dl.drop(tmp_path, reckless='kill')
shutil.rmtree(tmp_path)
known_data = _project_lookup_by_id(path + "/backlogger.db", uuid)[0]
known_aliases = known_data[1]
if known_aliases is None:
print(f"Project {uuid} is already imported, no known aliases.")
@ -108,5 +115,6 @@ def import_project(path, url, aliases=None, code=None, isDataset=True):
if not len(new_alias_list) == len(known_alias_list):
alias_str = list2str(new_alias_list)
update_project_data(path, uuid, "aliases", alias_str)
# make this more concrete
return uuid