|
1 | 1 | from pathlib import Path |
2 | 2 |
|
3 | 3 | import ruamel.yaml |
| 4 | +from bidsschematools import render, schema |
4 | 5 | from jinja2 import Environment, FileSystemLoader, select_autoescape |
| 6 | +from rich import print |
5 | 7 |
|
6 | 8 | yaml = ruamel.yaml.YAML() |
7 | 9 | yaml.indent(mapping=2, sequence=4, offset=2) |
@@ -78,8 +80,51 @@ def generate_apps_table(): |
78 | 80 | return template.render(include=content, type=type) |
79 | 81 |
|
80 | 82 |
|
| 83 | +def generate_filename_templates(): |
| 84 | + """Create filename templates for all datatypes of all modalities.""" |
| 85 | + |
| 86 | + schema_obj = schema.load_schema() |
| 87 | + |
| 88 | + modalities = schema_obj.rules.modalities |
| 89 | + |
| 90 | + to_render = [ |
| 91 | + { |
| 92 | + "name": x, |
| 93 | + "description": schema_obj.objects.modalities[x]["description"], |
| 94 | + "datatypes": [ |
| 95 | + { |
| 96 | + "name": dt, |
| 97 | + "filenames": filename_template_for(schema_obj, dt), |
| 98 | + } |
| 99 | + for dt in modalities[x]["datatypes"] |
| 100 | + ], |
| 101 | + } |
| 102 | + for x in modalities |
| 103 | + ] |
| 104 | + |
| 105 | + env = return_jinja_env() |
| 106 | + template = env.get_template("filename_templates_md.jinja") |
| 107 | + return template.render(include=to_render) |
| 108 | + |
| 109 | + |
| 110 | +def filename_template_for(schema_obj, datatype): |
| 111 | + """Create filename templates for a single datatype.""" |
| 112 | + filenames = render.make_filename_template( |
| 113 | + dstype="raw", |
| 114 | + schema=schema_obj, |
| 115 | + src_path=Path("https://bids-specification.readthedocs.io/en/latest/"), |
| 116 | + pdf_format=False, |
| 117 | + datatypes=[datatype], |
| 118 | + ) |
| 119 | + filenames = filenames.replace( |
| 120 | + "../../..", |
| 121 | + "https://bids-specification.readthedocs.io/en/latest", |
| 122 | + ) |
| 123 | + return filenames |
| 124 | + |
| 125 | + |
81 | 126 | def main(): |
82 | | - print(generate_converter_table(file="converters.yml", data_type="EEG")) |
| 127 | + print(generate_filename_templates()) |
83 | 128 |
|
84 | 129 |
|
85 | 130 | if __name__ == "__main__": |
|
0 commit comments