From 057f214e33cb9046d622326423745cc3570944e7 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Thu, 4 Dec 2025 11:08:05 +0100 Subject: [PATCH] create config on init --- corrlib/initialization.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/corrlib/initialization.py b/corrlib/initialization.py index f6ef5aa..28cf4c7 100644 --- a/corrlib/initialization.py +++ b/corrlib/initialization.py @@ -1,6 +1,8 @@ +from configparser import ConfigParser import sqlite3 import datalad.api as dl import os +import tracker as tr def _create_db(db): @@ -34,19 +36,40 @@ def _create_db(db): conn.close() +def _create_config(path): + """ + 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) + + def create(path): """ Create folder of backlogs. """ dl.create(path) - _create_db(path + '/backlogger.db') - os.chmod(path + '/backlogger.db', 0o666) # why does this not work? - os.makedirs(path + '/projects') - os.makedirs(path + '/archive') - os.makedirs(path + '/toml_imports') - os.makedirs(path + '/import_scripts/template.py') - with open(path + "/.gitignore", "w") as fp: + _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() - dl.save(path, dataset=path, message="Initialize backlogger directory.") + tr.save(path, message="Initialized correlator library", dataset=path)