forked from NOAA-CEFI-Portal/CEFI-info-hub-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tool_landing_page.py
71 lines (55 loc) · 2.1 KB
/
create_tool_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# This script run once creates tool landing pages from a model_list_dir/*.json file.
# import argparse
import json
import os
import shutil
import sys
from jinja2 import Environment, FileSystemLoader
# basic templating
# use conda web_templating. .. source activate web_templating
def write_html(template, configs, new_dir, modelname):
# root = os.path.dirname(os.path.abspath(__file__))
# docsdir = os.path.join(new_dir, 'deploy')
htmlname = modelname + '.html'
filename = os.path.join(new_dir, htmlname)
# if not os.path.exists(docsdir):
# os.mkdir(docsdir)
with open(filename, 'w') as fh:
fh.write(template.render(**configs))
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('tool_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, new_dir, modelname):
# filename = parse_args()
template = load_template()
write_html(template, configs, new_dir, modelname)
def run_all_files(list_of_models, folder_out, configdir):
for modelname in list_of_models:
print(modelname)
old_name = modelname + '.json'
configfile = os.path.join(configdir, old_name)
with open(configfile, "r") as read_file:
configjson = json.load(read_file)
new_dir = os.path.join(folder_out)
# Create target Directory if don't exist
if not os.path.exists(new_dir):
os.mkdir(new_dir)
write_templates(configjson, new_dir, modelname)
def main():
with open("Browse_config.json", "r") as read_file:
modellist_configjson = json.load(read_file)
list_of_models = modellist_configjson['list_of_models']
folder_out = 'deploy'
configdir = 'model_list_dir'
run_all_files(list_of_models, folder_out, configdir)
if __name__ == '__main__':
main()