From 019dfdd9d635556576c1070b413e69d7018eb3b3 Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Fri, 31 Dec 2021 08:16:39 +0530 Subject: docs: add script to generate config snippets --- tools/gen-config-doc.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tools/gen-config-doc.py diff --git a/tools/gen-config-doc.py b/tools/gen-config-doc.py new file mode 100644 index 000000000..a0f3014b0 --- /dev/null +++ b/tools/gen-config-doc.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +import re + + +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("../src/main/java/org/traccar/config/Keys.java", "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 = desc_re.sub("", i[0]).strip() + 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 From b06ab631df79ebcace59478b44108e155ad802a6 Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Fri, 31 Dec 2021 14:01:41 +0530 Subject: fix: add period to config default text Co-authored-by: Anton Tananaev --- tools/gen-config-doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gen-config-doc.py b/tools/gen-config-doc.py index a0f3014b0..c6d133ca6 100644 --- a/tools/gen-config-doc.py +++ b/tools/gen-config-doc.py @@ -29,7 +29,7 @@ def get_config_key_descriptions(): {key} config

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

""" -- cgit v1.2.3 From b25eb46b1b5a2e1633f994f3478d237a190f9f02 Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Fri, 31 Dec 2021 16:48:58 +0530 Subject: docs: add line breaks in config descriptions --- tools/gen-config-doc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/gen-config-doc.py b/tools/gen-config-doc.py index c6d133ca6..62c4c535e 100644 --- a/tools/gen-config-doc.py +++ b/tools/gen-config-doc.py @@ -18,7 +18,12 @@ def get_config_key_descriptions(): try: key_match = key_match_re.search(i[1]) if key_match: - description = desc_re.sub("", i[0]).strip() + 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 @@ -29,7 +34,7 @@ def get_config_key_descriptions(): {key} config

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

""" -- cgit v1.2.3 From 9e3e63d00857fa297b4e882bdcf6ee06f27c6054 Mon Sep 17 00:00:00 2001 From: Sun Howwrongbum Date: Fri, 31 Dec 2021 16:50:32 +0530 Subject: docs: fix config file path --- tools/gen-config-doc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/gen-config-doc.py b/tools/gen-config-doc.py index 62c4c535e..e309da942 100644 --- a/tools/gen-config-doc.py +++ b/tools/gen-config-doc.py @@ -1,15 +1,20 @@ #!/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("../src/main/java/org/traccar/config/Keys.java", "r") as f: + with open(_KEYS_FILE, "r") as f: code = f.read() config = re.findall( r"(/\*\*.*?\*/)\n\s+(public static final Config.*?;)", code, re.DOTALL -- cgit v1.2.3 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 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