Tools used by OpenStack Documentation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB

#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import glob
import os
import sys
def get_pdf_link(root, publish_path):
p = '%s/*.pdf' % root
re = glob.glob(p)
if len(re) == 0:
return ''
filename = os.path.basename(re[0])
path = os.path.relpath(root, publish_path)
return ' <a href="%s/%s">(pdf)</a>' % (path, filename)
def generate_index_file(publish_path):
"""Generate index.html file in publish_path."""
if not os.path.isdir(publish_path):
index_file = open(os.path.join(publish_path, 'index.html'), 'w')
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n'
'<html lang="en" xmlns="" xml:lang="en">\n'
'<h1>Generated documents</h1>\n')
links = {}
for root, dirs, files in os.walk(publish_path):
dirs[:] = [d for d in dirs if d not in ['common', 'webapp', 'content',
'www', 'samples']]
# Ignore top-level index.html files
if root == publish_path:
pdf_link = get_pdf_link(root, publish_path)
if os.path.isfile(os.path.join(root, 'index.html')):
path = os.path.relpath(root, publish_path)
links[path] = ('<a href="%s/index.html">%s</a>%s\n' %
(path, path.replace('draft/', ''), pdf_link))
for entry in sorted([s for s in links if not s.startswith('draft/')]):
drafts = [s for s in links if s.startswith('draft/')]
if drafts:
index_file.write('<h2>Draft guides</h2>\n')
for entry in sorted(drafts):
if os.path.isfile(os.path.join(publish_path, 'www-index.html')):
index_file.write('<h2>WWW index pages</h2>\n')
index_file.write('<a href="www-index.html">List of generated '
'WWW pages</a>\n')
def main():
parser = argparse.ArgumentParser(description="Generate index file.")
parser.add_argument('directory', metavar='DIR',
help="Directory to search.")
args = parser.parse_args()
if __name__ == "__main__":