diff options
author | Tibor Frank <tifrank@cisco.com> | 2020-02-17 12:49:53 +0100 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2020-02-18 04:11:51 +0000 |
commit | a8a9827ea12122026190f9c7a590a8af7f92d772 (patch) | |
tree | 67316ab35d7a0ff375a3213c8a4ea60aad6d62d0 /resources/tools/presentation/generator_files.py | |
parent | 711ee27661c81cfd9f2f7ac49dd6e0c8e793fe52 (diff) |
PAL: CSIT-1676: Split long files into chapters
Change-Id: Id86c4fad596ce37d89d6600a30f9bbdc4e1edf5f
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 | 153 |
1 files changed, 57 insertions, 96 deletions
diff --git a/resources/tools/presentation/generator_files.py b/resources/tools/presentation/generator_files.py index 4c39e6f648..d6c7546ae7 100644 --- a/resources/tools/presentation/generator_files.py +++ b/resources/tools/presentation/generator_files.py @@ -74,105 +74,37 @@ def _tests_in_suite(suite_name, tests): return False -def file_test_results(file_spec, input_data): +def file_test_results(file_spec, input_data, frmt=u"rst"): """Generate the file(s) with algorithms - file_test_results specified in the specification file. :param file_spec: File to generate. :param input_data: Data to process. + :param frmt: Format can be: rst or html :type file_spec: pandas.Series :type input_data: InputData + :type frmt: str """ - file_name = f"{file_spec[u'output-file']}{file_spec[u'output-file-ext']}" - rst_header = file_spec[u"file-header"] + base_file_name = f"{file_spec[u'output-file']}" + rst_header = file_spec.get(u"file-header", u"") + start_lvl = file_spec.get(u"data-start-level", 4) - logging.info(f" Generating the file {file_name} ...") + logging.info(f" Generating the file {base_file_name} ...") - table_lst = get_files(file_spec[u"dir-tables"], u".csv", full_path=True) - if not table_lst: - logging.error( - f" No tables to include in {file_spec[u'dir-tables']}. Skipping." - ) + if frmt == u"html": + table_lst = get_files(file_spec[u"dir-tables"], u".rst", full_path=True) + elif frmt == u"rst": + table_lst = get_files(file_spec[u"dir-tables"], u".csv", full_path=True) + else: return - - logging.info(f" Writing file {file_name}") - - logging.info( - f" Creating the tests data set for the " - f"{file_spec.get(u'type', u'')} {file_spec.get(u'title', u'')}." - ) - tests = input_data.filter_data(file_spec) - tests = input_data.merge_data(tests) - - logging.info( - f" Creating the suites data set for the " - f"{file_spec.get(u'type', u'')} {file_spec.get(u'title', u'')}." - ) - file_spec[u"filter"] = u"all" - suites = input_data.filter_data(file_spec, data_set=u"suites") - suites = input_data.merge_data(suites) - suites.sort_index(inplace=True) - - with open(file_name, u"wt") as file_handler: - file_handler.write(rst_header) - for suite_longname, suite in suites.items(): - if len(suite_longname.split(u".")) <= \ - file_spec[u"data-start-level"]: - continue - - title_line = \ - get_rst_title_char( - suite[u"level"] - file_spec[u"data-start-level"] - 1 - ) * len(suite[u"name"]) - if not (u"-ndrpdr" in suite[u"name"] or - u"-mrr" in suite[u"name"] or - u"-func" in suite[u"name"] or - u"-device" in suite[u"name"] or - u"-dev" in suite[u"name"]): - file_handler.write(f"\n{suite[u'name']}\n{title_line}\n") - - if _tests_in_suite(suite[u"name"], tests): - file_handler.write(f"\n{suite[u'name']}\n{title_line}\n") - file_handler.write( - f"\n{suite[u'doc']}\n".replace(u'|br|', u'\n\n -') - ) - for tbl_file in table_lst: - if suite[u"name"] in tbl_file: - file_handler.write( - RST_INCLUDE_TABLE.format( - file_latex=tbl_file, - file_html=tbl_file.split(u"/")[-1])) - - logging.info(u" Done.") - - -def file_test_results_html(file_spec, input_data): - """Generate the file(s) with algorithms - - file_test_results_html - 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 - """ - - file_name = f"{file_spec[u'output-file']}.rst" - rst_header = file_spec[u"file-header"] - - logging.info(f" Generating the file {file_name} ...") - - table_lst = get_files(file_spec[u"dir-tables"], u".rst", full_path=True) if not table_lst: logging.error( f" No tables to include in {file_spec[u'dir-tables']}. Skipping." ) return - logging.info(f" Writing file {file_name}") - logging.info( f" Creating the tests data set for the " f"{file_spec.get(u'type', u'')} {file_spec.get(u'title', u'')}." @@ -197,21 +129,30 @@ def file_test_results_html(file_spec, input_data): return suites = input_data.merge_data(suites) - with open(file_name, u"wt") as file_handler: - file_handler.write(rst_header) - for suite_longname, suite in suites.items(): - if len(suite_longname.split(u".")) <= \ - file_spec[u"data-start-level"]: - continue - - title_line = \ - get_rst_title_char( - suite[u"level"] - file_spec[u"data-start-level"] - 1 - ) * len(suite[u"name"]) + file_name = u"" + for suite_longname, suite in suites.items(): + + suite_lvl = len(suite_longname.split(u".")) + if suite_lvl < start_lvl: + # Not interested in this suite + continue + + if suite_lvl == start_lvl: + # Our top-level suite + chapter = suite_longname.split(u'.')[-1] + file_name = f"{base_file_name}/{chapter}.rst" + logging.info(f" Writing file {file_name}") + with open(f"{base_file_name}/index.rst", u"a") as file_handler: + file_handler.write(f" {chapter}\n") + with open(file_name, u"a") as file_handler: + file_handler.write(rst_header) + + title_line = get_rst_title_char(suite[u"level"] - start_lvl + 2) * \ + len(suite[u"name"]) + with open(file_name, u"a") as file_handler: if not (u"-ndrpdr" in suite[u"name"] or u"-mrr" in suite[u"name"] or - u"-func" in suite[u"name"] or - u"-device" in suite[u"name"]): + u"-dev" in suite[u"name"]): file_handler.write(f"\n{suite[u'name']}\n{title_line}\n") if _tests_in_suite(suite[u"name"], tests): @@ -221,8 +162,28 @@ def file_test_results_html(file_spec, input_data): ) for tbl_file in table_lst: if suite[u"name"] in tbl_file: - file_handler.write( - f"\n.. include:: {tbl_file.split(u'/')[-1]}\n" - ) + if frmt == u"html": + file_handler.write( + f"\n.. include:: {tbl_file.split(u'/')[-1]}\n" + ) + elif frmt == u"rst": + file_handler.write( + RST_INCLUDE_TABLE.format( + file_latex=tbl_file, + file_html=tbl_file.split(u"/")[-1]) + ) logging.info(u" Done.") + + +def file_test_results_html(file_spec, input_data): + """Generate the file(s) with algorithms + - file_test_results_html + 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 + """ + file_test_results(file_spec, input_data, frmt=u"html") |