feat/path_check #40

Merged
jkuhl merged 9 commits from feat/path_check into develop 2026-05-07 08:54:52 +02:00
3 changed files with 40 additions and 5 deletions
Showing only changes of commit 4c4a5fd670 - Show all commits

add checks of the format of the paths in the database
Some checks failed
Ruff / ruff (push) Waiting to run
Mypy / mypy (push) Failing after 1m9s
Pytest / pytest (3.12) (push) Failing after 1m13s
Pytest / pytest (3.13) (push) Has been cancelled
Pytest / pytest (3.14) (push) Has been cancelled

Justus Kuhlmann 2026-05-06 18:02:25 +02:00
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6

View file

@ -4,7 +4,7 @@ from corrlib import __app_name__
from .initialization import create
from .toml import import_tomls, update_project, reimport_project
from .find import find_record, list_projects
from .find import find_record, list_projects, list_ensembles
from .tools import str2list
from .main import update_aliases
from .meas_io import drop_cache as mio_drop_cache
@ -56,9 +56,9 @@ def lister(
"""
if entities in ['ensembles', 'Ensembles','ENSEMBLES']:
print("Ensembles:")
for item in os.listdir(path / "archive"):
if os.path.isdir(path / "archive" / item):
print(item)
results = list_ensembles(path)
for e in results:
print(e)
elif entities == 'projects':
results = list_projects(path)
print("Projects:")

View file

@ -382,3 +382,10 @@ def list_projects(path: Path) -> list[tuple[str, str]]:
conn.close()
return results
def list_ensembles(path: Path) -> list[str]:
res = []
for item in os.listdir(path / "archive"):
if os.path.isdir(path / "archive" / item):
res.append(item)
return res

View file

@ -7,7 +7,7 @@ from .tracker import get
import pyerrors.input.json as pj
import os
from configparser import ConfigParser
from .find import list_ensembles, list_projects
from typing import Any
@ -64,6 +64,31 @@ def are_keys_unique(db: Path, table: str, col: str) -> bool:
return bool(results[0] == results[1])
def check_path_format(result: pd.Series, ensembles: list[str], projects: list[str]) -> None:
"""
Check whether the path of the given result has the right format.
Parameters
----------
result: pd.Series
The result to be checked.
"""
p = result['path']
if not p.startswith('archive'):
raise ValueError(f'The path {p} does not start correctly')
meas_key = p.split('::')[1]
ensemble = p.split('/')[1]
project = p.split('/')[2].split('::')[0]
if not len(meas_key) == 64:
raise ValueError(f'meas_key of {p} is scrambled')
if ensemble not in ensembles:
raise ValueError(f'meas_key of {p} points to an unknown ensemble')
if project not in projects:
raise ValueError(f'meas_key of {p} points to an unknown project id')
def check_db_integrity(path: Path) -> None:
"""
Check intergrity of the database by checking the uniqueness of the record keys used to load the records
@ -82,10 +107,13 @@ def check_db_integrity(path: Path) -> None:
search_expr = "SELECT * FROM 'backlogs'"
conn = sqlite3.connect(path / db)
results = pd.read_sql(search_expr, conn)
ensembles = list_ensembles(path)
projects = [p[0] for p in list_projects(path)]
for _, result in results.iterrows():
if not has_valid_times(result):
raise ValueError(f"Result with id {result[id]} has wrong time signatures.")
check_path_format(result, ensembles, projects)
return