Skip to content

Commit

Permalink
doc/conf: generate releases.json in conf.py
Browse files Browse the repository at this point in the history
pave the road to build all the ingredients of the document using RTD
facility.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Nov 20, 2020
1 parent 0980cde commit b1c4a82
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
18 changes: 0 additions & 18 deletions admin/build-doc
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
30 changes: 29 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import datetime
import fileinput
import json
import os
import shutil
import sys
import os

import yaml

# project information
project = 'Ceph'
Expand Down Expand Up @@ -197,6 +201,27 @@ def __getattr__(cls, name):
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')
Expand All @@ -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'))

0 comments on commit b1c4a82

Please sign in to comment.