can now read and write simple sfcf measurements

This commit is contained in:
Justus Kuhlmann 2024-06-19 12:55:42 +00:00
parent 5ec34ad98b
commit c3aa7577fb
7 changed files with 408 additions and 0 deletions

65
backlogger/main.py Normal file
View file

@ -0,0 +1,65 @@
import sqlite3
import datalad.api as dl
import os
from .git_tools import move_submodule
def create_project(path, uuid, aliases=None, code=None):
"""
Create a new project entry in the database.
Parameters
----------
path: str
The path to the backlogger folder.
uuid: str
The uuid of the project.
name: str (optional)
Costum name for the project (e.g. 'cA determination on exponential clover').
code: str (optional)
The code that was used to create the measurements.
"""
conn = sqlite3.connect(path + "/backlogger.db")
c = conn.cursor()
known_projects = c.execute("SELECT * FROM projects WHERE id=?", (uuid,))
if known_projects.fetchone():
raise ValueError("Project already imported, use update_project() instead.")
dl.unlock(path + "/backlogger.db", dataset=path)
c.execute("INSERT INTO projects (id, aliases, code, created_at, updated_at) VALUES (?, ?, ?, datetime('now'), datetime('now'))", (uuid, aliases, code))
conn.commit()
conn.close()
dl.save(path + "/backlogger.db", message="Added entry for project " + uuid + " to database", dataset=path)
def import_project(url, path, aliases=None, code=None):
"""
Parameters
----------
url: str
The url of the project to import. This can be any url that datalad can handle.
path: str
The path to the backlogger folder.
name: str
Custom name of the project, alias of the project.
code: str
Code that was used to create the measurements.
"""
# install in tmp to find uuid
tmp_path = path + '/projects/tmp'
dl.install(path=tmp_path, source=url, dataset=path)
with open(tmp_path + "/.datalad/config") as fp:
for line in fp:
if line.startswith("\tid"):
uuid = line.split()[2]
break
create_project(path, uuid, aliases, code)
move_submodule(path, 'projects/tmp', 'projects/' + uuid)
os.mkdir(path + '/projects/tmp')
os.mkdir(path + '/import_scripts/' + uuid)
dl.save(path, message="Import project from " + url, dataset=path)
return uuid