From 95a52712ecdcf2806895e6a0ac827c5cb402b73c Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 14 Jan 2016 18:28:03 +0300 Subject: [PATCH] Add scripts to generate doc with examples --- doc_generate_static.py | 93 ++++++++++++++++++++++++++++++++++++++++++ examples_gen.sh | 10 +++++ 2 files changed, 103 insertions(+) create mode 100644 doc_generate_static.py create mode 100644 examples_gen.sh diff --git a/doc_generate_static.py b/doc_generate_static.py new file mode 100644 index 0000000..6165ca2 --- /dev/null +++ b/doc_generate_static.py @@ -0,0 +1,93 @@ +# Copyright 2016 Mirantis, Inc. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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 then +# License for the specific language governing permissions and limitations +# under the License. + +import six +import os + +from glob import glob + +from bareon_dynamic_allocator import utils +from bareon_dynamic_allocator import viewer +from bareon_dynamic_allocator.allocators import DynamicAllocator + + +doc_schemas_path = os.path.join(os.path.dirname(os.path.realpath(__file__)) , 'doc', 'source', 'schemas') +doc_schemas_rst_path = os.path.join(os.path.dirname(os.path.realpath(__file__)) , 'doc', 'source', 'examples.rst') + + +def generate_svg_files(): + + result = {} + + for dynamic_schema_path in sorted(glob(os.path.join(doc_schemas_path, '*_ds.yaml'))): + print 'Read file {0}'.format(dynamic_schema_path) + dynamic_schema = utils.parse_yaml(dynamic_schema_path) + dynamic_schema_file_name = os.path.basename(dynamic_schema_path) + dynamic_schema_name = os.path.splitext(dynamic_schema_file_name)[0] + for hw_info_path in sorted(glob(os.path.join(doc_schemas_path, '*_disk.yaml'))): + print 'Read file {0}'.format(hw_info_path) + hw_info_file_name = os.path.basename(hw_info_path) + hw_info_name = os.path.splitext(hw_info_file_name)[0] + hw_info = utils.parse_yaml(hw_info_path) + static_schema = DynamicAllocator(hw_info, dynamic_schema).generate_static() + + static_schema_name = '{0}_{1}.svg'.format(dynamic_schema_name, hw_info_name) + result[static_schema_name[:-4]] = { + 'dynamic_schema': os.path.join('schemas', dynamic_schema_file_name), + 'hw_info': os.path.join('schemas', hw_info_file_name), + 'image': os.path.join('schemas', static_schema_name)} + + viewer.SVGViewer(static_schema, file_path=os.path.join(doc_schemas_path, static_schema_name), fit=True).show_me() + + rst_doc = """ +=================== +Allocation Examples +=================== + + """ + for name, value in sorted(six.iteritems(result)): + rst_doc += """ + +{topic} +----------------- + +Hardware information +~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: {hw_info} + :language: yaml + +Dynamic schema +~~~~~~~~~~~~~~ +.. literalinclude:: {dynamic_schema} + :language: yaml + +Allocation result +~~~~~~~~~~~~~~~~~ + +.. image:: {image} + :width: 100% + + """.format( + topic=name, + image=value['image'], + hw_info=value['hw_info'], + dynamic_schema=value['dynamic_schema']) + + with open(doc_schemas_rst_path, 'w') as f: + f.write(rst_doc) + + +if __name__ == '__main__': + generate_svg_files() diff --git a/examples_gen.sh b/examples_gen.sh new file mode 100644 index 0000000..bbf4e45 --- /dev/null +++ b/examples_gen.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -eux + +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 + +rm -rf build/doc || true +python doc_generate_static.py +python setup.py build_sphinx