Merge "Generate api-ref redirects for service type aliases"

This commit is contained in:
Zuul 2017-10-23 01:13:27 +00:00 committed by Gerrit Code Review
commit 91eda9070c
3 changed files with 27 additions and 4 deletions

View File

@ -14,5 +14,8 @@ openstackdocstheme>=1.16.0 # Apache-2.0
nwdiag
sphinxcontrib-nwdiag
requests
os-service-types
# For translations
Babel>=2.3.4,!=2.4.0 # BSD

View File

@ -20,6 +20,8 @@ import sys
import lxml.html
from lxml import etree
import jinja2
import os_service_types
import requests
def initialize_logging(debug, verbose):
@ -67,8 +69,16 @@ def main():
logger.error("initialising template environment failed: %s" % e)
return 1
try:
service_types = os_service_types.ServiceTypes(
session=requests.Session(), only_remote=True)
except Exception as e:
logger.error("initialising service types data failed: %s" % e)
return 1
for templateFile in environment.list_templates():
if not templateFile.endswith('.html'):
if not (templateFile.endswith('.html')
or templateFile.endswith('.htaccess')):
continue
logger.info("generating %s" % templateFile)
@ -80,10 +90,14 @@ def main():
(templateFile, e))
continue
try:
output = lxml.html.tostring(
lxml.html.fromstring(template.render()),
pretty_print=True)
if templateFile.endswith('.html'):
output = lxml.html.tostring(
lxml.html.fromstring(template.render()),
pretty_print=True)
else:
output = template.render(REVERSE=service_types.reverse)
except Exception as e:
logger.error("rendering template %s failed: %s" %
(templateFile, e))

View File

@ -60,3 +60,9 @@ redirect 301 /api-ref-share-v2.html /api-ref/shared-file-system/index.html
redirect 301 /api-ref-share-v1.html /api-ref/shared-file-system/index.html
# Redirect Telemetry (ceilometer only) API
redirect 301 /api-ref-telemetry-v2.html https://docs.openstack.org/ceilometer/latest/webapi/v2.html
# Redirect service-type aliases to service-type api-ref locations
{% for alias, service_type in REVERSE.items() -%}
redirectmatch 301 /api-ref/{{ alias }}/(.*) /api-ref/{{ service_type }}/$1
{% endfor %}