use config in initialization
All checks were successful
Mypy / mypy (push) Successful in 45s
Pytest / pytest (3.12) (push) Successful in 49s
Pytest / pytest (3.13) (push) Successful in 48s
Pytest / pytest (3.14) (push) Successful in 47s
Ruff / ruff (push) Successful in 32s

This commit is contained in:
Justus Kuhlmann 2025-12-04 12:56:02 +01:00
commit 4b55227642
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

@ -36,7 +36,7 @@ def _create_db(db: str) -> None:
return return
def _create_config(path: str) -> None: def _create_config(path: str, tracker: str, cached: bool) -> ConfigParser:
""" """
Create the config file for backlogger. Create the config file for backlogger.
@ -44,32 +44,42 @@ def _create_config(path: str) -> None:
config = ConfigParser() config = ConfigParser()
config['core'] = { config['core'] = {
'version': '1.0', 'version': '1.0',
'db_path': os.path.join(path, 'backlogger.db'), 'tracker': tracker,
'projects_path': os.path.join(path, 'projects'), 'cached': str(cached),
'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',
} }
config['paths'] = {
'db': 'backlogger.db',
'projects_path': 'projects',
'archive_path': 'archive',
'toml_imports_path': 'toml_imports',
'import_scripts_path': 'import_scripts',
}
return config
def _write_config(path: str, config: ConfigParser) -> None:
"""
Write the config file to disk.
"""
with open(os.path.join(path, '.corrlib'), 'w') as configfile: with open(os.path.join(path, '.corrlib'), 'w') as configfile:
config.write(configfile) config.write(configfile)
return return
def create(path: str, tracker: str = 'datalad') -> None: def create(path: str, tracker: str = 'datalad', cached: bool = True) -> None:
""" """
Create folder of backlogs. Create folder of backlogs.
""" """
config = _create_config(path, tracker, cached)
init(path, tracker) init(path, tracker)
_create_db(os.path.join(path, 'backlogger.db')) _write_config(path, config)
os.chmod(os.path.join(path, 'backlogger.db'), 0o666) _create_db(os.path.join(path, config['paths']['db']))
_create_config(path) os.chmod(os.path.join(path, config['paths']['db']), 0o666)
os.makedirs(os.path.join(path, 'projects')) os.makedirs(os.path.join(path, config['paths']['projects_path']))
os.makedirs(os.path.join(path, 'archive')) os.makedirs(os.path.join(path, config['paths']['archive_path']))
os.makedirs(os.path.join(path, 'toml_imports')) os.makedirs(os.path.join(path, config['paths']['toml_imports_path']))
os.makedirs(os.path.join(path, 'import_scripts/template.py')) os.makedirs(os.path.join(path, config['paths']['import_scripts_path'], 'template.py'))
with open(os.path.join(path, ".gitignore"), "w") as fp: with open(os.path.join(path, ".gitignore"), "w") as fp:
fp.write(".cache") fp.write(".cache")
fp.close() fp.close()