-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#79] adding a new script to generate markdown files for metadata mod…
…els in hsmodels
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
docs/metadata/generate_hsmodels_aggregations_metadata_markdown.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import jsonschema2md | ||
import json | ||
|
||
from hsmodels.schemas.resource import ResourceMetadata | ||
from hsmodels.schemas.aggregations import ( | ||
FileSetMetadata, | ||
GeographicRasterMetadata, | ||
GeographicFeatureMetadata, | ||
MultidimensionalMetadata, | ||
ReferencedTimeSeriesMetadata, | ||
SingleFileMetadata, | ||
TimeSeriesMetadata, | ||
ModelInstanceMetadata, | ||
ModelProgramMetadata, | ||
CSVFileMetadata | ||
) | ||
|
||
aggregation_models = [ | ||
ResourceMetadata, | ||
FileSetMetadata, | ||
GeographicRasterMetadata, | ||
GeographicFeatureMetadata, | ||
MultidimensionalMetadata, | ||
ReferencedTimeSeriesMetadata, | ||
SingleFileMetadata, | ||
TimeSeriesMetadata, | ||
ModelInstanceMetadata, | ||
ModelProgramMetadata, | ||
CSVFileMetadata | ||
] | ||
|
||
|
||
def write_md(model): | ||
sj_rm = model.schema_json(indent=4) | ||
sj_rm = sj_rm.replace("$defs", "definitions") | ||
parser = jsonschema2md.Parser() | ||
parser.tab_size = 4 | ||
md_lines = parser.parse_schema(json.loads(sj_rm)) | ||
|
||
filename = model.__name__ + ".md" | ||
with open(os.path.join(filename), "w") as f: | ||
f.writelines(md_lines) | ||
|
||
|
||
for aggr_model in aggregation_models: | ||
write_md(aggr_model) |