From fb7ba6f0b763cacc248475c11e6528cc3c824250 Mon Sep 17 00:00:00 2001 From: Philipp Wollschlegel Date: Mon, 23 Oct 2023 22:49:56 +0200 Subject: [PATCH] repository: allow description '.json' file for local resources --- script/build/repository.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/script/build/repository.py b/script/build/repository.py index 40779f40..f8038721 100755 --- a/script/build/repository.py +++ b/script/build/repository.py @@ -47,12 +47,16 @@ def generate_content(data_dir: Path, url: str) -> str: for geo in sorted(xcs_type.iterdir()): rv += f"\n# Data location: {data_dir.name}, type: {xcs_type.name}, geography: {geo.name}.\n" for datafile in sorted(geo.iterdir()): - rv += f""" + if not datafile.name.lower().endswith(".json"): + rv += f""" name={datafile.name} uri={url + str(datafile.relative_to(data_dir))} type={xcs_type.name} area={guess_area(datafile.stem)} update={git_commit_datetime(datafile).date().isoformat()} +""" + if json_description(datafile): + rv += f"""description={json_description(datafile)} """ return rv @@ -132,9 +136,14 @@ def json_uri(json_filename: Path) -> str: def json_description(json_filename: Path) -> str: """Return the value of json_filename's "description" key.""" - data = json.load(json_filename.open()) - if "description" in data: - return data["description"] + if not json_filename.suffix.lower() == ".json": + json_filename = json_filename.with_suffix(".json") + + if json_filename.exists(): + data = json.load(json_filename.open()) + return data.get("description") + else: + return str("") def generate_remote(data_dir: Path) -> str: @@ -147,12 +156,11 @@ def generate_remote(data_dir: Path) -> str: rv += f""" name={datafile.stem} uri={json_uri(datafile)} -description={json_description(datafile)} type={xcs_type.name} area={guess_area(datafile.stem)} update={git_commit_datetime(datafile).date().isoformat()} """ - if json_description(datafile) != None: + if json_description(datafile): rv += f"""description={json_description(datafile)} """ return rv