Skip to content

Commit

Permalink
let custom result renderer print json line for catalog-translate
Browse files Browse the repository at this point in the history
  • Loading branch information
jsheunis committed Jul 14, 2023
1 parent c6a8c80 commit 57bf6b4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
16 changes: 9 additions & 7 deletions datalad_catalog/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,17 @@ class Get(ValidatedInterface):

@staticmethod
def custom_result_renderer(res, **kwargs):
"""This result renderer dumps the value of the 'output' key
"""This result renderer dumps the value of the 'output' key
in the result record in JSON-line format -- only if status==ok"""
ui = ui_switcher.ui
ui.message(json.dumps(
res.get('output'),
separators=(',', ':'),
indent=None,
cls=jsEncoder,
))
ui.message(
json.dumps(
res.get("output"),
separators=(",", ":"),
indent=None,
cls=jsEncoder,
)
)

@staticmethod
# generic handling of command results (logging, rendering, filtering, ...)
Expand Down
3 changes: 1 addition & 2 deletions datalad_catalog/tests/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def test_get_metadata(demo_catalog, test_data):
assert res[0]["output"] is not None
assert res[0]["output"][cnst.DATASET_ID] == ds_meta[cnst.DATASET_ID]
assert (
res[0]["output"][cnst.DATASET_VERSION]
== ds_meta[cnst.DATASET_VERSION]
res[0]["output"][cnst.DATASET_VERSION] == ds_meta[cnst.DATASET_VERSION]
)
# add file-level metadata
catalog_add(
Expand Down
16 changes: 14 additions & 2 deletions datalad_catalog/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ class MetaTranslate(ValidatedInterface):

_examples_ = []

@staticmethod
def custom_result_renderer(res, **kwargs):
"""This result renderer dumps the value of the 'output' key
in the result record in JSON-line format -- only if status==ok"""
ui = ui_switcher.ui
ui.message(
json.dumps(
res.get("translated_metadata"),
separators=(",", ":"),
indent=None,
cls=jsEncoder,
)
)

@staticmethod
# generic handling of command results (logging, rendering, filtering, ...)
@eval_results
Expand Down Expand Up @@ -197,8 +211,6 @@ def __call__(
message=("Metadata successfully translated"),
translated_metadata=translated_meta,
)
ui = ui_switcher.ui
ui.message(json.dumps(translated_meta, cls=jsEncoder))
except Exception as e:
yield get_status_dict(
**res_kwargs,
Expand Down

0 comments on commit 57bf6b4

Please sign in to comment.