import of non-datalad projects

This commit is contained in:
Justus Kuhlmann 2024-08-13 16:20:08 +00:00
parent 496724091d
commit ec63662359
2 changed files with 32 additions and 16 deletions

View file

@ -3,12 +3,12 @@ import datalad.api as dl
import os
def _create_db(path):
def _create_db(db):
"""
Create the database file and the table.
"""
conn = sqlite3.connect(path)
conn = sqlite3.connect(db)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS backlogs
(id INTEGER PRIMARY KEY,
@ -38,9 +38,8 @@ def create(path):
"""
dl.create(path)
_create_db(path + '/backlogger.db')
os.chmod(path + '/backlogger.db', 0o666)
os.chmod(path + '/backlogger.db', 0o666) # why does this not work?
os.makedirs(path + '/projects')
os.makedirs(path + '/projects/tmp')
os.makedirs(path + '/archive')
os.makedirs(path + '/import_scripts/template.py')
dl.save(path, dataset=path, message="Initialize backlogger directory.")

View file

@ -1,7 +1,9 @@
import sqlite3
import datalad.api as dl
import datalad.config as dlc
import os
from .git_tools import move_submodule
import shutil
def create_project(path, uuid, aliases=None, code=None):
@ -32,7 +34,7 @@ def create_project(path, uuid, aliases=None, code=None):
dl.save(path + "/backlogger.db", message="Added entry for project " + uuid + " to database", dataset=path)
def import_project(url, path, aliases=None, code=None):
def import_project(path, url, aliases=None, code=None, isDataset=True):
"""
Parameters
----------
@ -41,25 +43,40 @@ def import_project(url, path, aliases=None, code=None):
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
aliases: list[str]
Custom name of the project, alias of the project.
code: str
Code that was used to create the measurements.
Import a datalad dataset into the backlogger.
Parameters
----------
path: str
The path to the backlogger directory.
url: str
The url of the project to import. This can be any url that datalad can handle.
Also supported are non-datalad datasets, which will be converted to datalad datasets,
in order to receive a uuid and have a consistent interface.
"""
# install in tmp to find uuid
tmp_path = path + '/projects/tmp'
if not isDataset:
dl.create(path + '/projects/tmp', dataset=path)
shutil.copytree(url + "/*", path + '/projects/tmp/')
dl.save(path + '/projects/tmp', dataset=path)
else:
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
conf = dlc.ConfigManager(tmp_path)
uuid = conf.get("datalad.dataset.id")
if not uuid:
raise ValueError("The dataset does not have a uuid!")
dl.unlock(path + "/backlogger.db", dataset=path)
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)
# make this more concrete
dl.save([path + "/backlogger.db", 'projects/' + uuid], message="Import project from " + url, dataset=path)
return uuid