diff --git a/dsp_permissions_scripts/template.py b/dsp_permissions_scripts/template.py index 6e8a0f5c..7d80a773 100644 --- a/dsp_permissions_scripts/template.py +++ b/dsp_permissions_scripts/template.py @@ -7,7 +7,7 @@ from dsp_permissions_scripts.models.scope import PUBLIC from dsp_permissions_scripts.utils.authentication import login from dsp_permissions_scripts.utils.doap_get import get_doaps_of_project -from dsp_permissions_scripts.utils.doap_serialize import serialize_project_doaps +from dsp_permissions_scripts.utils.doap_serialize import serialize_doaps_of_project from dsp_permissions_scripts.utils.doap_set import apply_updated_doaps_on_server from dsp_permissions_scripts.utils.oap import apply_updated_oaps_on_server from dsp_permissions_scripts.utils.oap_serialize import serialize_resource_oaps @@ -69,13 +69,13 @@ def update_doaps( shortcode=shortcode, token=token, ) - serialize_project_doaps( + serialize_doaps_of_project( project_doaps=project_doaps, shortcode=shortcode, mode="original", ) project_doaps_updated = modify_doaps(doaps=project_doaps) - serialize_project_doaps( + serialize_doaps_of_project( project_doaps=project_doaps, shortcode=shortcode, mode="modified", diff --git a/dsp_permissions_scripts/utils/doap_serialize.py b/dsp_permissions_scripts/utils/doap_serialize.py index c2515258..027c9eb9 100644 --- a/dsp_permissions_scripts/utils/doap_serialize.py +++ b/dsp_permissions_scripts/utils/doap_serialize.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import Literal -from dsp_permissions_scripts.models.doap import Doap +from dsp_permissions_scripts.models.doap import Doap, DoapTargetType def _get_file_path( @@ -12,16 +12,20 @@ def _get_file_path( return Path(f"project_data/{shortcode}/DOAPs_{mode}.json") -def serialize_project_doaps( +def serialize_doaps_of_project( project_doaps: list[Doap], shortcode: str, mode: Literal["original", "modified"], + target: DoapTargetType = DoapTargetType.ALL, ) -> None: - """Serialize the resource DOAPs to a JSON file.""" + """Serialize the DOAPs of a project to a JSON file.""" filepath = _get_file_path(shortcode, mode) filepath.parent.mkdir(parents=True, exist_ok=True) + explanation_string = f"Project {shortcode} has {len(project_doaps)} DOAPs" + if target != DoapTargetType.ALL: + explanation_string += f" which are related to a {target}" doaps_as_dicts = [doap.model_dump(exclude_none=True) for doap in project_doaps] - doaps_as_dict = {f"Project {shortcode} has {len(project_doaps)} DOAPs": doaps_as_dicts} + doaps_as_dict = {explanation_string: doaps_as_dicts} with open(filepath, mode="w", encoding="utf-8") as f: f.write(json.dumps(doaps_as_dict, ensure_ascii=False, indent=2)) @@ -30,7 +34,7 @@ def deserialize_project_doaps( shortcode: str, mode: Literal["original", "modified"], ) -> list[Doap]: - """Deserialize the resource DOAPs from a JSON file.""" + """Deserialize the DOAPs of a project from a JSON file.""" filepath = _get_file_path(shortcode, mode) with open(filepath, mode="r", encoding="utf-8") as f: doaps_as_dict = json.load(f)