Skip to content

Commit

Permalink
add script bfabric_save_resource_description.py
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Dec 10, 2024
1 parent 37256ea commit 5a27cad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ instead a separate Python package with its individual changelog.

- Relationship: `ExternalJob.executable`
- (experimental) EntityLookupCache that allows to cache entity lookups in a script to avoid redundant requests.
- Specific use case script: bfabric_save_resource_description.py (the functionality will be available in a future CLI).

### Fixed

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Repository = "https://github.com/fgcz/bfabricPy"
"bfabric_save_workunit_attribute.py" = "bfabric_scripts.bfabric_save_workunit_attribute:main"
"bfabric_save_workflowstep.py" = "bfabric_scripts.bfabric_save_workflowstep:main"
"bfabric_slurm_queue_status.py" = "bfabric_scripts.bfabric_slurm_queue_status:main"
"bfabric_save_resource_description.py" = "bfabric_scripts.bfabric_save_resource_description:main"

[tool.setuptools.package-data]
"*" = ["py.typed"]
Expand Down
28 changes: 28 additions & 0 deletions src/bfabric_scripts/bfabric_save_resource_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import argparse
from pathlib import Path

from rich.pretty import pprint

from bfabric import Bfabric
from bfabric.cli_formatting import setup_script_logging


def save_resource_description(client: Bfabric, id: int, description_file: Path) -> None:
description = description_file.read_text()
obj = {"id": id, "description": description}
response = client.save(endpoint="resource", obj=obj)
pprint(response[0], indent_guides=False)


def main() -> None:
setup_script_logging()
parser = argparse.ArgumentParser()
parser.add_argument("id", type=int)
parser.add_argument("description_file", type=Path)
client = Bfabric.from_config()
args = parser.parse_args()
save_resource_description(client=client, **vars(args))


if __name__ == "__main__":
main()

0 comments on commit 5a27cad

Please sign in to comment.