feat/path_check #40
3 changed files with 40 additions and 5 deletions
add checks of the format of the paths in the database
commit
4c4a5fd670
|
|
@ -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:")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue