use pathlib.Path for directories and files
This commit is contained in:
parent
110ddaf3a1
commit
8162758cec
13 changed files with 137 additions and 125 deletions
|
|
@ -7,9 +7,10 @@ from .input.implementations import codes
|
|||
from .tools import k2m, get_db_file
|
||||
from .tracker import get
|
||||
from typing import Any, Optional
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _project_lookup_by_alias(db: str, alias: str) -> str:
|
||||
def _project_lookup_by_alias(db: Path, alias: str) -> str:
|
||||
"""
|
||||
Lookup a projects UUID by its (human-readable) alias.
|
||||
|
||||
|
|
@ -37,7 +38,7 @@ def _project_lookup_by_alias(db: str, alias: str) -> str:
|
|||
return str(results[0][0])
|
||||
|
||||
|
||||
def _project_lookup_by_id(db: str, uuid: str) -> list[tuple[str, str]]:
|
||||
def _project_lookup_by_id(db: Path, uuid: str) -> list[tuple[str, str]]:
|
||||
"""
|
||||
Return the project information available in the database by UUID.
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ def _project_lookup_by_id(db: str, uuid: str) -> list[tuple[str, str]]:
|
|||
return results
|
||||
|
||||
|
||||
def _db_lookup(db: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
def _db_lookup(db: Path, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[Any]=None, updated_before: Optional[Any]=None, updated_after: Optional[Any]=None) -> pd.DataFrame:
|
||||
"""
|
||||
Look up a correlator record in the database by the data given to the method.
|
||||
|
|
@ -228,10 +229,10 @@ def sfcf_filter(results: pd.DataFrame, **kwargs: Any) -> pd.DataFrame:
|
|||
return results.drop(drops)
|
||||
|
||||
|
||||
def find_record(path: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
def find_record(path: Path, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[str]=None, updated_before: Optional[str]=None, updated_after: Optional[str]=None, revision: Optional[str]=None, **kwargs: Any) -> pd.DataFrame:
|
||||
db_file = get_db_file(path)
|
||||
db = os.path.join(path, db_file)
|
||||
db = path / db_file
|
||||
if code not in codes:
|
||||
raise ValueError("Code " + code + "unknown, take one of the following:" + ", ".join(codes))
|
||||
get(path, db_file)
|
||||
|
|
@ -246,7 +247,7 @@ def find_record(path: str, ensemble: str, correlator_name: str, code: str, proje
|
|||
return results.reset_index()
|
||||
|
||||
|
||||
def find_project(path: str, name: str) -> str:
|
||||
def find_project(path: Path, name: str) -> str:
|
||||
"""
|
||||
Find a project by it's human readable name.
|
||||
|
||||
|
|
@ -264,10 +265,10 @@ def find_project(path: str, name: str) -> str:
|
|||
"""
|
||||
db_file = get_db_file(path)
|
||||
get(path, db_file)
|
||||
return _project_lookup_by_alias(os.path.join(path, db_file), name)
|
||||
return _project_lookup_by_alias(path / db_file, name)
|
||||
|
||||
|
||||
def list_projects(path: str) -> list[tuple[str, str]]:
|
||||
def list_projects(path: Path) -> list[tuple[str, str]]:
|
||||
"""
|
||||
List all projects known to the library.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue