From 8a25ba1da3b51622a16f907172efff1288befe08 Mon Sep 17 00:00:00 2001 From: Andrew Olsen Date: Fri, 10 Jun 2022 13:08:07 +1200 Subject: [PATCH] Add --with-dataset-types to `kart meta get` Simply adds two fields to each datasets output: "datasetType" and "version". Most existing datasets will be ("table", 3). Experimental point cloud datasets are ("point-cloud", 1) --- kart/meta.py | 13 ++++++++++++- tests/test_meta.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/kart/meta.py b/kart/meta.py index a97eee770..4c1e549d9 100644 --- a/kart/meta.py +++ b/kart/meta.py @@ -53,10 +53,15 @@ def meta(ctx, **kwargs): help="[deprecated] How to format the JSON output. Only used with -o json", ) @click.option("--ref", default="HEAD") +@click.option( + "--with-dataset-types", + is_flag=True, + help="When set, includes the dataset type and version as pseudo meta-items (these cannot be updated).", +) @click.argument("dataset", required=False) @click.argument("keys", required=False, nargs=-1) @click.pass_context -def meta_get(ctx, output_format, json_style, ref, dataset, keys): +def meta_get(ctx, output_format, json_style, ref, with_dataset_types, dataset, keys): """ Prints the value of meta keys. @@ -80,6 +85,12 @@ def meta_get(ctx, output_format, json_style, ref, dataset, keys): all_items[ds.path] = get_meta_items(ds, keys) else: all_items[ds.path] = ds.meta_items() + if with_dataset_types: + all_items[ds.path] = { + "datasetType": ds.DATASET_TYPE, + "version": ds.VERSION, + **all_items[ds.path], + } output_type, fmt = parse_output_format(output_format, json_style) diff --git a/tests/test_meta.py b/tests/test_meta.py index 3ef884ef5..d6f2bc667 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -22,9 +22,6 @@ def test_errors(self, data_archive_readonly, cli_runner): @pytest.mark.parametrize("output_format", ("text", "json")) def test_all(self, output_format, data_archive_readonly, cli_runner): - # All datasets now support getting metadata in either V1 or V2 format, - # but if you don't specify a particular item, they will show all V2 items - - # these are more self-explanatory to an end-user. with data_archive_readonly("points"): r = cli_runner.invoke( ["meta", "get", "nz_pa_points_topo_150k", "-o", output_format] @@ -44,6 +41,38 @@ def test_all(self, output_format, data_archive_readonly, cli_runner): assert output["schema.json"] assert output["crs/EPSG:4326.wkt"] + @pytest.mark.parametrize("output_format", ("text", "json")) + def test_with_dataset_types(self, output_format, data_archive_readonly, cli_runner): + with data_archive_readonly("points"): + r = cli_runner.invoke( + [ + "meta", + "get", + "nz_pa_points_topo_150k", + "--with-dataset-types", + "-o", + output_format, + ] + ) + assert r.exit_code == 0, r + if output_format == "text": + assert "datasetType" in r.stdout + assert "version" in r.stdout + assert "title" in r.stdout + assert EXPECTED_TITLE in r.stdout + assert "description" in r.stdout + assert "schema.json" in r.stdout + assert "crs/EPSG:4326.wkt" in r.stdout + else: + output = json.loads(r.stdout) + output = output["nz_pa_points_topo_150k"] + assert output["datasetType"] == "table" + assert output["version"] == 3 + assert output["title"] == EXPECTED_TITLE + assert output["description"] + assert output["schema.json"] + assert output["crs/EPSG:4326.wkt"] + @pytest.mark.parametrize("output_format", ("text", "json")) def test_keys(self, output_format, data_archive_readonly, cli_runner): with data_archive_readonly("points"):