2012-03-07 17:35:18 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of the Ansible Documentation
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-08 15:39:45 +01:00
|
|
|
from __future__ import print_function
|
2012-03-07 17:35:18 +01:00
|
|
|
|
|
|
|
__docformat__ = 'restructuredtext'
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2012-03-08 19:36:47 +01:00
|
|
|
import traceback
|
2013-03-05 19:59:39 +01:00
|
|
|
try:
|
|
|
|
from sphinx.application import Sphinx
|
|
|
|
except ImportError:
|
2015-12-08 15:39:45 +01:00
|
|
|
print("#################################")
|
|
|
|
print("Dependency missing: Python Sphinx")
|
|
|
|
print("#################################")
|
2013-03-05 19:59:39 +01:00
|
|
|
sys.exit(1)
|
2012-03-11 04:34:53 +01:00
|
|
|
import os
|
2012-03-07 17:35:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SphinxBuilder(object):
|
|
|
|
"""
|
|
|
|
Creates HTML documentation using Sphinx.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""
|
|
|
|
Run the DocCommand.
|
|
|
|
"""
|
2015-12-08 15:39:45 +01:00
|
|
|
print("Creating html documentation ...")
|
2012-03-07 17:35:18 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
buildername = 'html'
|
|
|
|
|
2013-06-09 19:55:58 +02:00
|
|
|
outdir = os.path.abspath(os.path.join(os.getcwd(), "htmlout"))
|
2012-03-07 17:35:18 +01:00
|
|
|
# Create the output directory if it doesn't exist
|
|
|
|
if not os.access(outdir, os.F_OK):
|
|
|
|
os.mkdir(outdir)
|
|
|
|
|
|
|
|
doctreedir = os.path.join('./', '.doctrees')
|
|
|
|
|
2012-03-11 04:34:53 +01:00
|
|
|
confdir = os.path.abspath('./')
|
|
|
|
srcdir = os.path.abspath('rst')
|
2012-03-12 04:28:04 +01:00
|
|
|
freshenv = True
|
2012-03-07 17:35:18 +01:00
|
|
|
|
|
|
|
# Create the builder
|
|
|
|
app = Sphinx(srcdir,
|
|
|
|
confdir,
|
|
|
|
outdir,
|
|
|
|
doctreedir,
|
|
|
|
buildername,
|
|
|
|
{},
|
|
|
|
sys.stdout,
|
|
|
|
sys.stderr,
|
|
|
|
freshenv)
|
|
|
|
|
|
|
|
app.builder.build_all()
|
2012-03-07 19:08:31 +01:00
|
|
|
|
2015-12-08 15:39:45 +01:00
|
|
|
except ImportError:
|
2012-03-08 19:36:47 +01:00
|
|
|
traceback.print_exc()
|
2015-12-08 15:39:45 +01:00
|
|
|
except Exception as ex:
|
|
|
|
print("FAIL! exiting ... (%s)" % ex, file=sys.stderr)
|
2012-03-07 17:35:18 +01:00
|
|
|
|
|
|
|
def build_docs(self):
|
|
|
|
self.app.builder.build_all()
|
|
|
|
|
|
|
|
|
2012-03-07 19:08:31 +01:00
|
|
|
def build_rst_docs():
|
2012-03-07 17:35:18 +01:00
|
|
|
docgen = SphinxBuilder()
|
2012-03-07 18:41:53 +01:00
|
|
|
|
2012-03-07 19:08:31 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
if '-h' in sys.argv or '--help' in sys.argv:
|
2015-12-08 15:39:45 +01:00
|
|
|
print("This script builds the html documentation from rst/asciidoc sources.\n")
|
|
|
|
print(" Run 'make docs' to build everything.")
|
|
|
|
print(" Run 'make viewdocs' to build and then preview in a web browser.")
|
2012-03-07 19:08:31 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2014-09-21 15:18:53 +02:00
|
|
|
build_rst_docs()
|
2012-03-07 19:08:31 +01:00
|
|
|
|
2012-03-07 18:41:53 +01:00
|
|
|
if "view" in sys.argv:
|
|
|
|
import webbrowser
|
2014-02-17 12:00:41 +01:00
|
|
|
if not webbrowser.open('htmlout/index.html'):
|
2015-12-08 15:39:45 +01:00
|
|
|
print("Could not open on your webbrowser.", file=sys.stderr)
|