refactor/data_backend #12

Merged
jkuhl merged 36 commits from refactor/data_backend into develop 2025-12-04 15:47:45 +01:00
Showing only changes of commit 4b55227642 - Show all commits

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

Justus Kuhlmann 2025-12-04 12:56:02 +01:00
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

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