From f784646e12dc7e2f60c1b87bf1241aa8f3479b1d Mon Sep 17 00:00:00 2001 From: Tomas Zigo Date: Fri, 9 Sep 2022 12:40:50 +0200 Subject: [PATCH] man: allow register all addons keywords in main Keywords Index (#2529) --- man/build_keywords.py | 64 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/man/build_keywords.py b/man/build_keywords.py index 6c774f7396b..46d4853b772 100644 --- a/man/build_keywords.py +++ b/man/build_keywords.py @@ -1,8 +1,23 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# generates keywords.html -# (c) 2013 by the GRASS Development Team, Luca Delucchi +""" +Generates keywords.html file for core and optionally for addons modules. + +Usage: + +Generate core modules keywords HTML page + +python man/build_keywords.py + +Generate core modules and optionally inject addons keywords HTML page + +python man/build_keywords.py + + +@author Luca Delucchi +@author Tomas Zigo - inject addons modules keywords +""" import os import sys @@ -13,18 +28,45 @@ 'Raster', 'Raster3D', 'Temporal', 'Vector'] path = sys.argv[1] +addons_path = None +if len(sys.argv) >= 3: + addons_path = sys.argv[2] + year = os.getenv("VERSION_DATE") keywords = {} -htmlfiles = glob.glob1(path, '*.html') +htmlfiles = glob.glob(os.path.join(path, "*.html")) +if addons_path: + addons_man_files = glob.glob(os.path.join(addons_path, "*.html")) + htmlfiles.extend(addons_man_files) char_list = {} -for fname in htmlfiles: - fil = open(os.path.join(path, fname)) + +def get_module_man_html_file_path(module): + """Get module manual HTML file path + + :param str module: module manual HTML file name e.g. v.surf.rst.html + + :return str module_path: core/addon module manual HTML file path + """ + if addons_path and module in ",".join(addons_man_files): + module_path = os.path.join(addons_path, module) + module_path = module_path.replace( + os.path.commonpath([path, module_path]), + ".", + ) + else: + module_path = os.path.join(path, module) + return module_path + + +for html_file in htmlfiles: + fname = os.path.basename(html_file) + with open(html_file) as f: + lines = f.readlines() # TODO maybe move to Python re (regex) - lines = fil.readlines() # remove empty lines lines = [x for x in lines if x != '\n'] try: @@ -82,10 +124,12 @@ keyword_line = '
%s
' \ '
' % (key, key) for value in sorted(keywords[key]): - keyword_line += ' %s,' % (value, - value.replace('.html', '')) - keyword_line = keyword_line.rstrip(',') - keyword_line += '
\n' + keyword_line += ' {val},'.format( + url=get_module_man_html_file_path(value), + val=value.replace(".html", "") + ) + keyword_line = keyword_line.rstrip(",") + keyword_line += "\n" keywordsfile.write(keyword_line) keywordsfile.write("\n") # create toc