forked from web/portal
47 lines
1.3 KiB
Python
Executable File
47 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import codecs
|
|
import os
|
|
from distutils.dir_util import copy_tree
|
|
import sys
|
|
from string import Template
|
|
|
|
from ruamel.yaml import YAML
|
|
|
|
__location__ = os.path.realpath(os.path.dirname(__file__))
|
|
static_folder = os.path.join(__location__, 'static')
|
|
content_folder = os.path.join(__location__, 'content')
|
|
output_folder = os.path.join(__location__, 'dist')
|
|
|
|
config_file = sys.argv[1]
|
|
|
|
yaml = YAML(typ='safe')
|
|
|
|
with codecs.open(config_file, 'r', encoding='utf-8') as stream:
|
|
try:
|
|
config = yaml.load(stream)
|
|
except yaml.YAMLError as exc:
|
|
print(exc)
|
|
exit(1)
|
|
|
|
template_item_text = codecs.open(os.path.join(content_folder, 'item.tmpl.html'), 'r',
|
|
encoding='utf-8').read()
|
|
template_item = Template(template_item_text)
|
|
|
|
items = ''
|
|
|
|
for config_item in config['items']:
|
|
items += template_item.substitute(config_item)
|
|
|
|
template_page_text = codecs.open(os.path.join(content_folder, 'index.tmpl.html'), 'r', encoding='utf-8').read()
|
|
template_page = Template(template_page_text)
|
|
outcome = template_page.substitute(items=items)
|
|
|
|
os.makedirs(output_folder, exist_ok=True)
|
|
|
|
outfile_index = os.path.join(output_folder, 'index.html')
|
|
|
|
copy_tree(static_folder, output_folder)
|
|
|
|
html = codecs.open(outfile_index, 'w', encoding='utf-8').write(outcome)
|