Skip to content

Commit

Permalink
repository: allow description '.json' file for local resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lordfolken committed Oct 23, 2023
1 parent d0dd22e commit fb7ba6f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions script/build/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit fb7ba6f

Please sign in to comment.