-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_catalog_landing_page.py
56 lines (50 loc) · 2.04 KB
/
create_catalog_landing_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# This script run once creates a catalog landing page based on the *_config.json file
# reference when called. E.g., python create_catalog_landing_page.py EcoSys_config.json
from jinja2 import Environment, FileSystemLoader
# import argparse
import json
import os
import shutil
import sys
#basic templating
# use conda web_templating. .. source activate web_templating
def write_html_index(template, configs, org_config):
root = os.path.dirname(os.path.abspath(__file__))
#root = path to output directory
filename = os.path.join(root, 'deploy', 'index.html')
with open(filename, 'w') as fh:
fh.write(template.render(configs = configs, org_config = org_config))
def load_template():
root = os.path.dirname(os.path.abspath(__file__))
templates_dir = os.path.join(root, 'templates')
env = Environment( loader = FileSystemLoader(templates_dir) )
template = env.get_template('catalog_landing_page.html')
return template
# def parse_args():
# parser = argparse.ArgumentParser()
# parser.add_argument('files')
# args = parser.parse_args()
# filename = args.files;
# return filename
def write_templates(configs, org_config):
# filename = parse_args()
template = load_template()
write_html_index(template, configs, org_config)
def main(org_config, model_config):
allthemodels = {}
for f in model_config['list_of_models']:
old_name = f +'.json'
#print(os.getcwd())
filename = os.path.join(model_config['location_of_model_list'], old_name)
with open(filename) as ff:
allthemodels[f] = json.load(ff)
#print(allthemodels[f])
write_templates(allthemodels, org_config)
if __name__ == '__main__':
org_config_file = sys.argv[1]; # use this approach if we need to generate multiple files
with open(org_config_file) as f:
org_config = json.load(f)
with open("models_all.json") as f:
model_config = json.load(f)
model_config['list_of_models'].sort(key=lambda x: x.lower())
main(org_config, model_config)