Skip to content

Commit

Permalink
add --remove-archive to experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Jul 24, 2024
1 parent f247b8c commit c849272
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/anemoi/registry/commands/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions src/anemoi/registry/entry/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c849272

Please sign in to comment.