From b1c4a821b6fda64f6e9edd5599d2b121f8afa85a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 20 Nov 2020 12:55:38 +0800 Subject: [PATCH] doc/conf: generate releases.json in conf.py pave the road to build all the ingredients of the document using RTD facility. Signed-off-by: Kefu Chai --- admin/build-doc | 18 ------------------ doc/conf.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/admin/build-doc b/admin/build-doc index ac655b75e05c..1aba2b5662d2 100755 --- a/admin/build-doc +++ b/admin/build-doc @@ -139,24 +139,6 @@ for target in $sphinx_targets; do done -# build the releases.json. this reads in the yaml version and dumps -# out the json representation of the same file. the resulting releases.json -# should be served from the root of hosted site. -$vdir/bin/python << EOF > $TOPDIR/build-doc/output/html/_static/releases.json -from __future__ import print_function -import datetime -import json -import yaml - -def json_serialize(obj): - if isinstance(obj, datetime.date): - return obj.isoformat() - -with open("$TOPDIR/doc/releases/releases.yml", 'r') as fp: - releases = yaml.safe_load(fp) - print(json.dumps(releases, indent=2, default=json_serialize)) -EOF - # # Build and install JavaDocs # diff --git a/doc/conf.py b/doc/conf.py index 31ea852a3422..af6e5cb43108 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,7 +1,11 @@ +import datetime import fileinput +import json +import os import shutil import sys -import os + +import yaml # project information project = 'Ceph' @@ -197,6 +201,27 @@ for c in pybinds: sys.path.insert(0, pybind) +# build the releases.json. this reads in the yaml version and dumps +# out the json representation of the same file. the resulting releases.json +# should be served from '/_static/releases.json' of hosted site. +def yaml_to_json(input_path, output_path): + def json_serialize(obj): + if isinstance(obj, datetime.date): + return obj.isoformat() + + yaml_fn = os.path.join(top_level, input_path) + json_fn = os.path.join(top_level, output_path) + + def process(app): + with open(yaml_fn) as input: + with open(json_fn, 'w') as output: + releases = yaml.safe_load(input) + s = json.dumps(releases, indent=2, default=json_serialize) + output.write(s) + + return process + + # handles edit-on-github and old version warning display def setup(app): app.add_js_file('js/ceph.js') @@ -208,3 +233,6 @@ def setup(app): generate_state_diagram(['src/osd/PeeringState.h', 'src/osd/PeeringState.cc'], 'doc/dev/peering_graph.generated.dot')) + app.connect('builder-inited', + yaml_to_json('doc/releases/releases.yml', + 'doc/_static/releases.json')) -- 2.47.3