set up template rendering to support multiple series
Change-Id: I2d7bffb5566135e557a7d2b4e78869821616d302 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
1d55938adb
commit
6b7df9a92d
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
@ -61,29 +62,36 @@ def main():
|
||||
args = parse_command_line_arguments()
|
||||
logger = initialize_logging(args.debug, args.verbose)
|
||||
|
||||
# Load project data, if it is present.
|
||||
# Load project data. Start by setting up a JSONSchema validator,
|
||||
# then finding all of the other YAML files.
|
||||
project_data = {}
|
||||
project_data_filename = os.path.join(
|
||||
validator = None
|
||||
fail = False
|
||||
project_schema_filename = os.path.join(
|
||||
args.source_directory,
|
||||
'projects.yaml'
|
||||
'project-data',
|
||||
'schema.yaml',
|
||||
)
|
||||
logger.info('looking for project data in %s', project_data_filename)
|
||||
if os.path.exists(project_data_filename):
|
||||
with open(project_data_filename, 'r') as f:
|
||||
project_data = yaml.safe_load(f.read())
|
||||
project_schema_filename = os.path.join(
|
||||
args.source_directory,
|
||||
'schema.yaml',
|
||||
)
|
||||
with open(project_schema_filename, 'r') as f:
|
||||
project_schema = yaml.safe_load(f.read())
|
||||
with open(project_schema_filename, 'r') as f:
|
||||
project_schema = yaml.safe_load(f.read())
|
||||
validator = jsonschema.Draft4Validator(project_schema)
|
||||
fail = False
|
||||
for error in validator.iter_errors(project_data):
|
||||
logger.error(str(error))
|
||||
fail = True
|
||||
if fail:
|
||||
raise ValueError('invalid input in %s' % project_data_filename)
|
||||
for filename in glob.glob(
|
||||
os.path.join(args.source_directory, 'project-data', '*.yaml')):
|
||||
if filename.endswith('schema.yaml'):
|
||||
continue
|
||||
series, _ = os.path.splitext(os.path.basename(filename))
|
||||
logger.info('loading %s project data from %s', series, filename)
|
||||
with open(filename, 'r') as f:
|
||||
data = yaml.safe_load(f.read())
|
||||
if validator:
|
||||
for error in validator.iter_errors(data):
|
||||
logger.error(str(error))
|
||||
fail = True
|
||||
if fail:
|
||||
raise ValueError('invalid input in %s' % filename)
|
||||
project_data[series] = data
|
||||
|
||||
# Set up jinja to discover the templates.
|
||||
try:
|
||||
loader = jinja2.FileSystemLoader(args.source_directory)
|
||||
environment = jinja2.Environment(loader=loader)
|
||||
@ -91,13 +99,14 @@ def main():
|
||||
logger.error("initialising template environment failed: %s" % e)
|
||||
return 1
|
||||
|
||||
# Render the templates.
|
||||
for templateFile in environment.list_templates():
|
||||
if not (templateFile.endswith('.html')
|
||||
or templateFile.endswith('.htaccess')):
|
||||
logger.info('ignoring %s', templateFile)
|
||||
continue
|
||||
|
||||
logger.info("generating %s" % templateFile)
|
||||
logger.info("generating %s for %s", templateFile, series)
|
||||
|
||||
try:
|
||||
template = environment.get_template(templateFile)
|
||||
@ -107,7 +116,7 @@ def main():
|
||||
raise
|
||||
|
||||
try:
|
||||
output = template.render(projects=project_data)
|
||||
output = template.render(PROJECT_DATA=project_data)
|
||||
if templateFile.endswith('.html'):
|
||||
soup = BeautifulSoup(output, "lxml")
|
||||
output = soup.prettify()
|
||||
|
@ -1,3 +1,6 @@
|
||||
{% set series = 'latest' %}
|
||||
{% set projects = PROJECT_DATA[series] %}
|
||||
|
||||
# Redirecting End-of-Life (EOL) versions, see https://wiki.openstack.org/wiki/Releases:
|
||||
redirectmatch 301 /bexar/.*$ /index.html
|
||||
redirectmatch 301 /cactus/.*$ /index.html
|
||||
|
@ -1,3 +1,6 @@
|
||||
{% set series = 'latest' %}
|
||||
{% set projects = PROJECT_DATA[series] %}
|
||||
|
||||
{% set scriptdir = '../common/js/' %}
|
||||
{% set cssdir = '../common/css/' %}
|
||||
{% extends "templates/base.tmpl" %}
|
||||
|
@ -1,3 +1,5 @@
|
||||
{% set series = 'latest' %}
|
||||
{% set projects = PROJECT_DATA[series] %}
|
||||
{% set scriptdir = './common/js/' %}
|
||||
{% set cssdir = './common/css/' %}
|
||||
{% extends "templates/base.tmpl" %}
|
||||
|
@ -1,3 +1,5 @@
|
||||
{% set series = 'latest' %}
|
||||
{% set projects = PROJECT_DATA[series] %}
|
||||
{% set scriptdir = '../../common/js/' %}
|
||||
{% set cssdir = '../../common/css/' %}
|
||||
{% set imagedir = '../../common/images/' %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user