track the list of templates being rendered

Rather than having a list of pages that needs to be checked and
updated by hand, keep track of the pages we write and pass the list to
the template to render a complete list automatically.

Change-Id: Ia3f5acb4ce850de5f64b66e93409860d4bbf2af7
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-07-15 18:46:25 -04:00 committed by Andreas Jaeger
parent 2ad1d522cc
commit f0f66ebd28
2 changed files with 33 additions and 32 deletions

View File

@ -135,12 +135,14 @@ def load_project_data(source_directory,
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())
for error in validator.iter_errors(data):
logger.error(str(error))
fail = True
for project in data:
# If the project has a service-type set, ensure it matches
# the value in the service-type-authority data.base.
@ -159,6 +161,7 @@ def load_project_data(source_directory,
project['service_type'],
)
fail = True
# client projects must have a description
project_type = project.get('type')
if project_type == 'client' and not project.get('description'):
@ -167,6 +170,7 @@ def load_project_data(source_directory,
project['name'],
)
fail = True
# If the project claims to have a separately published guide
# of some sort, look for it before allowing the flag to stand.
if not skip_links:
@ -185,6 +189,7 @@ def load_project_data(source_directory,
if flag_val:
raise
continue
# Only try to fetch the URL if we're going to do
# something with the result.
if flag_val or check_all_links:
@ -202,6 +207,7 @@ def load_project_data(source_directory,
'%s not set for %s but %s does exist',
flag, project['name'], url,
)
if fail:
raise ValueError('invalid input in %s' % filename)
project_data[series] = data
@ -234,7 +240,7 @@ def _get_official_repos():
def render_template(environment, project_data, regular_repos, infra_repos,
template_file, output_directory):
template_file, output_directory, extra={}):
logger = logging.getLogger()
logger.info("generating %s", template_file)
@ -264,6 +270,7 @@ def render_template(environment, project_data, regular_repos, infra_repos,
scriptdir=scriptdir,
cssdir=cssdir,
imagedir=imagedir,
**extra
)
if template_file.endswith('.html'):
soup = BeautifulSoup(output, "lxml")
@ -311,11 +318,18 @@ def main():
return 1
# Render the templates.
output_pages = []
page_list_template = None
for template_file in environment.list_templates():
if not (template_file.endswith('.html')
or template_file.endswith('.htaccess')):
logger.info('ignoring %s', template_file)
continue
if template_file.endswith('www-index.html'):
# Process this one at the end, so we have the full list of
# other output files.
page_list_template = template_file
continue
render_template(
environment,
project_data,
@ -324,6 +338,21 @@ def main():
template_file,
args.output_directory,
)
output_pages.append(template_file)
if page_list_template is not None:
output_pages.sort()
render_template(
environment,
project_data,
regular_repos,
infra_repos,
page_list_template,
args.output_directory,
extra={
'file_list': output_pages,
},
)
return 0

View File

@ -4,37 +4,9 @@
<body>
<!-- TEMPLATE_FILE: openstack-manuals/www/{{TEMPLATE_FILE}} -->
<ul>
<li><a href="www/index.html">/index.html</a></li>
<li><a href="www/configuration/index.html">/configuration/index.html</a></li>
<li><a href="www/draft/draft-index.html">/draft/draft-index.html</a></li>
<li><a href="www/errorpage.html">/errorpage.html</a></li>
<li><a href="www/api/">/api/index.html</a></li>
<li><a href="www/user/index.html">/user/index.html</a></li>
<li><a href="www/language-bindings.html">/language-bindings.html</a></li>
<li><a href="www/openstack-projects.html">/openstack-projects.html</a></li>
<li><a href="www/project-install-guide/draft/index.html">/project-install-guide/draft/index.html</a></li>
<li><a href="www/project-install-guide/newton/index.html">/project-install-guide/newton/index.html</a></li>
<li><a href="www/project-install-guide/ocata/index.html">/project-install-guide/ocata/index.html</a></li>
<li><a href="www/project-deploy-guide/draft/index.html">/project-deploy-guide/draft/index.html</a></li>
<li><a href="www/project-deploy-guide/newton/index.html">/project-deploy-guide/newton/index.html</a></li>
<li><a href="www/project-deploy-guide/ocata/index.html">/project-deploy-guide/ocata/index.html</a></li>
<li><a href="www/training_labs/index.html">/training_labs/index.html</a></li>
<!-- release -->
<li><a href="www/juno/index.html">/juno/index.html</a></li>
<li><a href="www/kilo/index.html">/kilo/index.html</a></li>
<li><a href="www/liberty/index.html">/liberty/index.html</a></li>
<li><a href="www/mitaka/index.html">/mitaka/index.html</a></li>
<li><a href="www/newton/index.html">/newton/index.html</a></li>
<li><a href="www/ocata/index.html">/ocata/index.html</a></li>
<!-- translation, sorted by locale -->
<li><a href="www/de/index.html">/de/index.html</a></li>
<li><a href="www/fr/index.html">/fr/index.html</a></li>
<li><a href="www/id/index.html">/id/index.html</a></li>
<li><a href="www/it/index.html">/it/index.html</a></li>
<li><a href="www/ja/index.html">/ja/index.html</a></li>
<li><a href="www/ko_KR/index.html">/ko_KR/index.html</a></li>
<li><a href="www/pt_BR/index.html">/pt_BR/index.html</a></li>
<li><a href="www/zh_CN/index.html">/zh_CN/index.html</a></li>
{% for outfile in file_list %}
<li><a href="www/{{outfile}}">{{outfile}}</a></li>
{% endfor %}
</ul>
</body>
</html>