feat/minteg #39

Merged
jkuhl merged 6 commits from feat/minteg into develop 2026-05-06 09:37:36 +02:00
Showing only changes of commit 656f99a13c - Show all commits

add integrity check for the config-file

Justus Kuhlmann 2026-05-05 16:47:07 +02:00
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

@ -1,10 +1,12 @@
import datetime as dt
from pathlib import Path
from .tools import get_db_file
from .tools import get_db_file, CONFIG_FILENAME
import pandas as pd
import sqlite3
from .tracker import get
import pyerrors.input.json as pj
import os
from configparser import ConfigParser
from typing import Any
@ -41,7 +43,6 @@ def check_db_integrity(path: Path) -> None:
for _, result in results.iterrows():
if not has_valid_times(result):
raise ValueError(f"Result with id {result[id]} has wrong time signatures.")
print("DB:\t")
return
@ -67,7 +68,6 @@ def _check_db2paths(path: Path, meas_paths: list[str]) -> None:
for key in needed_data[file]:
if key not in filedict.keys():
raise ValueError(f"Did not find data for key {key} that should be in file {file}.")
print("Links:\t")
return
@ -79,9 +79,44 @@ def check_db_file_links(path: Path) -> None:
_check_db2paths(path, list(results))
def check_path_and_config(path: Path) -> None:
if not os.path.exists(path):
raise FileNotFoundError(f"Corrlib path {path} does not exist.")
config_path = path / CONFIG_FILENAME
if not os.path.exists(config_path):
raise FileNotFoundError(f"Configuration file {config_path} not found.")
def check_config_validity(path: Path) -> None:
config = ConfigParser()
config_path = path / CONFIG_FILENAME
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError("Configuration file not found.")
if config.has_section('core'):
core_opts = ['version', 'tracker', 'cached']
has_core_opts = [config.has_option('core', opt) for opt in core_opts]
if not all(has_core_opts):
raise ValueError("One of the options in the 'core' section ('version', 'tracker', 'cached') is missing.")
if config.has_section('paths'):
path_opts = ['db', 'projects_path', 'archive_path', 'toml_imports_path', 'import_scripts_path']
has_path_opts = [config.has_option('paths', opt) for opt in path_opts]
if not all(has_path_opts):
raise ValueError("One of the options in the 'path' section ('db', 'projects_path', 'archive_path', 'toml_imports_path', 'import_scripts_path') is missing.")
def full_integrity_check(path: Path) -> None:
check_path_and_config(path)
print("Path and config-file exist:\t")
check_config_validity(path)
print("Configuration is valid:\t")
check_db_integrity(path)
print("DB:\t")
check_db_file_links(path)
print("Links:\t")
print("Full:\t")