corrlib/corrlib/initialization.py
Justus Kuhlmann 38d00316e1
Some checks failed
Mypy / mypy (push) Failing after 44s
Pytest / pytest (3.12) (push) Failing after 47s
Pytest / pytest (3.13) (push) Failing after 46s
Pytest / pytest (3.14) (push) Failing after 46s
Ruff / ruff (push) Failing after 34s
remove duplicate method
2025-12-04 11:33:29 +01:00

78 lines
2.3 KiB
Python

from configparser import ConfigParser
import sqlite3
import datalad.api as dl
import os
from .tracker import save
def _create_db(db: str) -> None:
"""
Create the database file and the table.
"""
conn = sqlite3.connect(db)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS backlogs
(id INTEGER PRIMARY KEY,
name TEXT,
ensemble TEXT,
code TEXT,
path TEXT,
project TEXT,
customTags TEXT,
parameters TEXT,
parameter_file TEXT,
created_at TEXT,
updated_at TEXT)''')
c.execute('''CREATE TABLE IF NOT EXISTS projects
(id TEXT PRIMARY KEY,
aliases TEXT,
customTags TEXT,
owner TEXT,
code TEXT,
created_at TEXT,
updated_at TEXT)''')
conn.commit()
conn.close()
return
def _create_config(path: str) -> None:
"""
Create the config file for backlogger.
"""
config = ConfigParser()
config['core'] = {
'version': '1.0',
'db_path': os.path.join(path, 'backlogger.db'),
'projects_path': os.path.join(path, 'projects'),
'archive_path': os.path.join(path, 'archive'),
'toml_imports_path': os.path.join(path, 'toml_imports'),
'import_scripts_path': os.path.join(path, 'import_scripts'),
'tracker': 'datalad',
'cached': True,
}
with open(os.path.join(path, '.corrlib'), 'w') as configfile:
config.write(configfile)
return
def create(path: str) -> None:
"""
Create folder of backlogs.
"""
dl.create(path)
_create_db(os.path.join(path, 'backlogger.db'))
os.chmod(os.path.join(path, 'backlogger.db'), 0o666) # why does this not work?
_create_config(path)
os.makedirs(os.path.join(path, 'projects'))
os.makedirs(os.path.join(path, 'archive'))
os.makedirs(os.path.join(path, 'toml_imports'))
os.makedirs(os.path.join(path, 'import_scripts/template.py'))
with open(os.path.join(path, ".gitignore"), "w") as fp:
fp.write(".cache")
fp.close()
save(path, message="Initialized correlator library", dataset=path)
return