From ac64dba0a21b50aa2090f2ff7f20bc64f7b8256f Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Fri, 31 Dec 2021 16:54:40 +0530 Subject: docs: rename script to be importable --- tools/gen-config-doc.py | 57 ------------------------------------------------- tools/gen_config_doc.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 tools/gen-config-doc.py create mode 100644 tools/gen_config_doc.py (limited to 'tools') diff --git a/tools/gen-config-doc.py b/tools/gen-config-doc.py deleted file mode 100644 index e309da942..000000000 --- a/tools/gen-config-doc.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/python - -import re -import os - - -_KEYS_FILE = os.path.join( - os.path.dirname(__file__), "../src/main/java/org/traccar/config/Keys.java" -) - -def get_config_key_descriptions(): - desc_re = re.compile(r"(/\*\*\n|\s+\*/|\s+\*)") - key_match_re = re.compile(r"\(\n(.+)\);", re.DOTALL) - key_split_re = re.compile(r",\s+", re.DOTALL) - snippets = [] - - with open(_KEYS_FILE, "r") as f: - code = f.read() - config = re.findall( - r"(/\*\*.*?\*/)\n\s+(public static final Config.*?;)", code, re.DOTALL - ) - for i in config: - try: - key_match = key_match_re.search(i[1]) - if key_match: - description = "
".join( - [ - x.strip().replace("\n", "") - for x in desc_re.sub("\n", i[0]).strip().split("\n\n") - ] - ) - terms = [x.strip() for x in key_split_re.split(key_match.group(1))] - key = terms[0].replace('"', "") - default = terms[2] if len(terms) == 3 else None - snippets.append( - f"""
-
-
- {key} config -
-

- {description}{f"
Default: {default}." if default else ""} -

-
-
""" - ) - except IndexError: - # will continue if key_match.group(1) or terms[0] does not exist - # for some reason - pass - - return ("\n").join(snippets) - - -if __name__ == "__main__": - html = get_config_key_descriptions() - print(html) diff --git a/tools/gen_config_doc.py b/tools/gen_config_doc.py new file mode 100644 index 000000000..e309da942 --- /dev/null +++ b/tools/gen_config_doc.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +import re +import os + + +_KEYS_FILE = os.path.join( + os.path.dirname(__file__), "../src/main/java/org/traccar/config/Keys.java" +) + +def get_config_key_descriptions(): + desc_re = re.compile(r"(/\*\*\n|\s+\*/|\s+\*)") + key_match_re = re.compile(r"\(\n(.+)\);", re.DOTALL) + key_split_re = re.compile(r",\s+", re.DOTALL) + snippets = [] + + with open(_KEYS_FILE, "r") as f: + code = f.read() + config = re.findall( + r"(/\*\*.*?\*/)\n\s+(public static final Config.*?;)", code, re.DOTALL + ) + for i in config: + try: + key_match = key_match_re.search(i[1]) + if key_match: + description = "
".join( + [ + x.strip().replace("\n", "") + for x in desc_re.sub("\n", i[0]).strip().split("\n\n") + ] + ) + terms = [x.strip() for x in key_split_re.split(key_match.group(1))] + key = terms[0].replace('"', "") + default = terms[2] if len(terms) == 3 else None + snippets.append( + f"""
+
+
+ {key} config +
+

+ {description}{f"
Default: {default}." if default else ""} +

+
+
""" + ) + except IndexError: + # will continue if key_match.group(1) or terms[0] does not exist + # for some reason + pass + + return ("\n").join(snippets) + + +if __name__ == "__main__": + html = get_config_key_descriptions() + print(html) -- cgit v1.2.3