From c84927260c0db751d173d3c1649e9230cdf1aa8f Mon Sep 17 00:00:00 2001 From: Florian Pinault Date: Wed, 24 Jul 2024 11:51:09 +0200 Subject: [PATCH] add --remove-archive to experiments --- src/anemoi/registry/commands/experiments.py | 17 ++++++++--------- src/anemoi/registry/entry/experiment.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/anemoi/registry/commands/experiments.py b/src/anemoi/registry/commands/experiments.py index 4babb1b..3cddabd 100644 --- a/src/anemoi/registry/commands/experiments.py +++ b/src/anemoi/registry/commands/experiments.py @@ -65,12 +65,16 @@ def add_arguments(self, command_parser): command_parser.add_argument( "--get-archive", help="Output file to save the archive metadata file from the catalogue." ) + command_parser.add_argument( + "--remove-archive", help="Remove the archive metadata file from the catalogue.", action="store_true" + ) command_parser.add_argument( "--archive-platform", - help="Archive platform. Only relevant for --set-archive and --get-archive.", + help="Archive platform. Only relevant for --set-archive and --get-archive and --remove-archive.", ) command_parser.add_argument( - "--run-number", help="The run number of the experiment. Relevant --set-archive and --get-archive." + "--run-number", + help="The run number of the experiment. Relevant --set-archive and --get-archive and --remove-archive.", ) command_parser.add_argument( "--archive-extra-metadata", help="Extra metadata. A list of key=value pairs.", nargs="+", default={} @@ -100,13 +104,8 @@ def _run(self, entry, args): overwrite=args.overwrite, extras=args.archive_extra_metadata, ) - self.process_task( - entry, - args, - "get_archive", - run_number=args.run_number, - platform=args.archive_platform, - ) + self.process_task(entry, args, "get_archive", run_number=args.run_number, platform=args.archive_platform) + self.process_task(entry, args, "remove_archive", run_number=args.run_number, platform=args.archive_platform) if args.url: print(entry.url) diff --git a/src/anemoi/registry/entry/experiment.py b/src/anemoi/registry/entry/experiment.py index df24b5e..1630efa 100644 --- a/src/anemoi/registry/entry/experiment.py +++ b/src/anemoi/registry/entry/experiment.py @@ -122,6 +122,17 @@ def set_archive(self, path, platform, run_number, overwrite=True, extras={}): self.rest_item.patch([{"op": "add", "path": f"/runs/{run_number}/archives/{platform}", "value": dic}]) + def remove_archive(self, platform, run_number): + if run_number is None: + raise ValueError("run_number must be set") + run_number = str(run_number) + + if platform is None: + raise ValueError("platform must be set") + + LOG.info(f"Removing archive for run {run_number} and platform {platform}") + self.rest_item.patch([{"op": "remove", "path": f"/runs/{run_number}/archives/{platform}"}]) + def get_archive(self, path, *, platform, run_number): if os.path.exists(path): raise FileExistsError(f"Path {path} already exists")