From 5d6c236af614131bbb0df5da2ac0b7699e26cdd9 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 16 Nov 2017 18:08:51 -0800 Subject: [PATCH] Add /api/docs to serve up the documentation This requires that the docs be at /usr/share/doc/lorax-*/html/ or if running from the source tree, at ./docs/html/ They can be re-created by running 'make docs' --- src/pylorax/api/server.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/server.py b/src/pylorax/api/server.py index 3eca9df3..eb9b7435 100644 --- a/src/pylorax/api/server.py +++ b/src/pylorax/api/server.py @@ -14,11 +14,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +import logging +log = logging.getLogger("lorax-composer") + from collections import namedtuple -from flask import Flask +from flask import Flask, send_from_directory +from glob import glob +import os from pylorax.api.crossdomain import crossdomain from pylorax.api.v0 import v0_api +from pylorax.sysutils import joinpaths GitLock = namedtuple("GitLock", ["repo", "lock", "dir"]) @@ -31,4 +37,18 @@ __all__ = ["server", "GitLock"] def hello_world(): return 'Hello, World!' +@server.route("/api/docs/") +@server.route("/api/docs/") +def api_docs(path=None): + # Find the html docs + try: + docs_path = glob("/usr/share/doc/lorax-*/html/")[0] + except IndexError: + # This assumes it is running from the source tree + docs_path = os.path.abspath(joinpaths(os.path.dirname(__file__), "../../../docs/html")) + + if not path: + path="index.html" + return send_from_directory(docs_path, path) + v0_api(server)