X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fdoc_gen%2Fgen_rst.py;h=3d04568de21dffc5ae656f501e7da4f527ef884a;hb=8c34e2945809ce12dd2795bb4e76c2a6b30e1be7;hp=8f239d0951be4280773719e2fb48638f39e59830;hpb=4dadc7a005ca99aa5a14ac650e9aa187cea10619;p=csit.git diff --git a/resources/tools/doc_gen/gen_rst.py b/resources/tools/doc_gen/gen_rst.py index 8f239d0951..3d04568de2 100755 --- a/resources/tools/doc_gen/gen_rst.py +++ b/resources/tools/doc_gen/gen_rst.py @@ -1,6 +1,4 @@ -#!/usr/bin/python - -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2018 Cisco and/or its affiliates. # 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: @@ -48,6 +46,16 @@ rst_py_module = """ :show-inheritance: """ +rst_rf_suite_setup = """ +.. robot-settings:: + :source: {} +""" + +rst_rf_variables = """ +.. robot-variables:: + :source: {} +""" + rst_rf_keywords = """ .. robot-keywords:: :source: {} @@ -145,7 +153,7 @@ def write_toc(fh, path, dirs): :param fh: File handler of the rst file. :param path: Path to package. :param dirs: List of directories to be included in ToC. - :type fh: file + :type fh: BinaryIO :type path: str :type dirs: list """ @@ -160,16 +168,18 @@ def write_module_title(fh, module_name): :param fh: File handler of the rst file. :param module_name: The name of module used for title. - :type fh: file + :type fh: BinaryIO :type module_name: str """ - title = "{} module".format(module_name) + title = "{} suite".format(module_name) fh.write("\n{}\n{}\n".format(title, '-' * len(title))) def generate_py_rst_files(): """Generate all rst files for all python modules.""" + dirs_ignore_list = ["__pycache__", ] + py_libs = get_files(PATH_PY_LIBS, PY_EXT) file_names = create_rst_file_names_set(py_libs, RESOURCES_DIR) @@ -177,32 +187,47 @@ def generate_py_rst_files(): path = join(WORKING_DIR, *file_name.split('.')[:-1]) dirs, files = scan_dir(path) + for item in dirs_ignore_list: + while True: + try: + dirs.remove(item) + except ValueError: + break + full_path = join(WORKING_DIR, file_name) with open(full_path, mode='a') as fh: if getsize(full_path) == 0: package = file_name.split('.')[-2] - fh.write("{} package\n".format(package)) - fh.write('=' * len("{} package".format(package))) + fh.write("{}\n".format(package)) + fh.write('=' * len("{}".format(package))) module_path = file_name.split('.')[:-1] if dirs: write_toc(fh, module_path, dirs) for file in files: module_name = file.split('.')[0] write_module_title(fh, module_name) - fh.write(rst_py_module.format('.'.join(module_path), module_name)) + fh.write(rst_py_module.format('.'.join(module_path), + module_name)) -def generate_rf_rst_files(file_names, incl_tests=True, incl_keywords=True): +def generate_rf_rst_files(file_names, incl_tests=True, incl_keywords=True, + incl_suite_setup=False, incl_variables=False): """Generate rst files for the given robot modules. :param file_names: List of file names to be included in the documentation (rst files). - :param incl_tests: If true, tests will be included in the documentation. - :param incl_keywords: If true, keywords will be included in the + :param incl_tests: If True, tests will be included in the documentation. + :param incl_keywords: If True, keywords will be included in the + documentation. + :param incl_suite_setup: If True, the suite setup will be included in the + documentation. + :param incl_variables: If True, the variables will be included in the documentation. :type file_names: set :type incl_tests: bool :type incl_keywords: bool + :type incl_suite_setup: bool + :type incl_variables: bool """ for file_name in file_names: @@ -213,8 +238,8 @@ def generate_rf_rst_files(file_names, incl_tests=True, incl_keywords=True): with open(full_path, mode='a') as fh: if getsize(full_path) == 0: package = file_name.split('.')[-2] - fh.write("{} package\n".format(package)) - fh.write('=' * len("{} package".format(package)) + '\n') + fh.write("{}\n".format(package)) + fh.write('=' * len("{}".format(package)) + '\n') module_path = file_name.split('.')[:-1] if dirs: write_toc(fh, module_path, dirs) @@ -222,10 +247,14 @@ def generate_rf_rst_files(file_names, incl_tests=True, incl_keywords=True): module_name = file.split('.')[0] write_module_title(fh, module_name) path = join(join(*module_path), module_name + RF_EXT) - if incl_tests: - fh.write(rst_rf_tests.format(path)) + if incl_suite_setup: + fh.write(rst_rf_suite_setup.format(path)) + if incl_variables: + fh.write(rst_rf_variables.format(path)) if incl_keywords: fh.write(rst_rf_keywords.format(path)) + if incl_tests: + fh.write(rst_rf_tests.format(path)) def generate_kw_rst_files(): @@ -245,7 +274,9 @@ def generate_tests_rst_files(): tests = get_files(PATH_TESTS, RF_EXT) file_names = create_rst_file_names_set(tests, TESTS_DIR) - generate_rf_rst_files(file_names) + generate_rf_rst_files(file_names, + incl_suite_setup=True, + incl_variables=True) if __name__ == '__main__':