diff options
author | Tibor Frank <tifrank@cisco.com> | 2017-08-11 10:44:36 +0200 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2017-10-11 15:21:02 +0200 |
commit | eecad36d7d2275fa47fbcab40dbcf56108ab0a51 (patch) | |
tree | b036a5b06035f5c36c8bb5bc279fe80925f2f8f8 /resources/tools/presentation/generator_files.py | |
parent | b62f0a99d13605a62f64f6ae9ac9aa9aae1755cb (diff) |
CSIT-755: Presentation and analytics layer
- CSIT-760: Configuration - real example
- CSIT-774: Implementation - parse configuration
- CSIT-779: Implementation - set environment
- CSIT-780: Implementation - download data
- CSIT-783: Implementation - debug mode
- CSIT-761: Implementation - Data pre-processing - parse input files
- CSIT-784: Implementation - Data pre-processing - store the data, access to data
- CSIT-789: Implementation - Data pre-processing - extract Documentation of the suite
- CSIT-757: Low Level Design
- CSIT-788: Implementation - Data pre-processing - extract VAT history and show runtime
- CSIT-785: Implementation - Data filtering
- CSIT-763: Presentation - tables
- CSIT-804: Presentation - files
- CSIT-762: Presentation - plots
- LLD: API + functional diagram
- CSIT-807: Element's models
- CSIT-813: Process static content
- CSIT-812: Report generation
- CSIT-764: Integration to CSIT
- CSIT-822: Archiving
- CSIT-790: Documentation
- configuration od the Input data is the same as for 17.07 report
Change-Id: I6fd1eb1df4af99eaf91925282cdee1c892698c59
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/presentation/generator_files.py')
-rw-r--r-- | resources/tools/presentation/generator_files.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/resources/tools/presentation/generator_files.py b/resources/tools/presentation/generator_files.py new file mode 100644 index 0000000000..0989fc76c0 --- /dev/null +++ b/resources/tools/presentation/generator_files.py @@ -0,0 +1,109 @@ +# Copyright (c) 2017 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: +# +# 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 the License for the specific language governing permissions and +# limitations under the License. + +"""Algorithms to generate files. +""" + + +import logging + +from utils import get_files, get_rst_title_char + + +def generate_files(spec, data): + """Generate all files specified in the specification file. + + :param spec: Specification read from the specification file. + :param data: Data to process. + :type spec: Specification + :type data: InputData + """ + + logging.info("Generating the files ...") + for file_spec in spec.files: + try: + eval(file_spec["algorithm"])(file_spec, data) + except NameError: + logging.error("The algorithm '{0}' is not defined.". + format(file_spec["algorithm"])) + logging.info("Done.") + + +def file_test_results(file_spec, input_data): + """Generate the file(s) with algorithm: file_test_results specified in the + specification file. + + :param file_spec: File to generate. + :param input_data: Data to process. + :type file_spec: pandas.Series + :type input_data: InputData + """ + + def tests_in_suite(suite_name, tests): + """Check if the suite includes tests. + + :param suite_name: Name of the suite to be checked. + :param tests: Set of tests + :type suite_name: str + :type tests: pandas.Series + :returns: True if the suite includes tests. + :rtype: bool + """ + + for key in tests.keys(): + if suite_name == tests[key]["parent"]: + return True + return False + + file_name = "{0}{1}".format(file_spec["output-file"], + file_spec["output-file-ext"]) + rst_header = file_spec["file-header"] + rst_include_table = ("\n.. csv-table::\n" + " :header-rows: 1\n" + " :widths: auto\n" + " :align: center\n" + " :file: {file}\n\n") + + logging.info(" Generating the file {0} ...".format(file_name)) + + table_lst = get_files(file_spec["dir-tables"], ".csv", full_path=False) + if len(table_lst) == 0: + logging.error(" No tables to include in '{0}'. Skipping.". + format(file_spec["dir-tables"])) + return None + + job = file_spec["data"].keys()[0] + build = str(file_spec["data"][job][0]) + + logging.info(" Writing file '{0}'".format(file_name)) + + suites = input_data.suites(job, build)[file_spec["data-start-level"]:] + suites.sort_index(inplace=True) + + with open(file_name, "w") as file_handler: + file_handler.write(rst_header) + for suite_longname, suite in suites.iteritems(): + suite_name = suite["name"] + file_handler.write("\n{0}\n{1}\n".format( + suite_name, get_rst_title_char( + suite["level"] - file_spec["data-start-level"] - 1) * + len(suite_name))) + file_handler.write("\n{0}\n".format( + suite["doc"].replace('|br|', '\n\n -'))) + if tests_in_suite(suite_name, input_data.tests(job, build)): + for tbl_file in table_lst: + if suite_name in tbl_file: + file_handler.write(rst_include_table. + format(file=tbl_file)) + + logging.info(" Done.") |