aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-12-31 11:14:58 -0800
committerGitHub <noreply@github.com>2021-12-31 11:14:58 -0800
commit8e36f5f968d5371080d9901403a16ea48fd2f3eb (patch)
treee07e3b6c1d5a9e36f11c83ef7d10bfa3bbdc210d
parentfe25a2a89533fa39a3df7a4b248dbf25b3a4e845 (diff)
parentac64dba0a21b50aa2090f2ff7f20bc64f7b8256f (diff)
downloadtrackermap-server-8e36f5f968d5371080d9901403a16ea48fd2f3eb.tar.gz
trackermap-server-8e36f5f968d5371080d9901403a16ea48fd2f3eb.tar.bz2
trackermap-server-8e36f5f968d5371080d9901403a16ea48fd2f3eb.zip
Merge pull request #4786 from sunhoww/doc-scripts
Add script to generate config snippets
-rw-r--r--tools/gen_config_doc.py57
1 files changed, 57 insertions, 0 deletions
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 = "<br /> ".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""" <div class="card mt-3">
+ <div class="card-body">
+ <h5 class="card-title">
+ {key} <span class="badge badge-dark">config</span>
+ </h5>
+ <p class="card-text">
+ {description}{f"<br/ > Default: {default}." if default else ""}
+ </p>
+ </div>
+ </div>"""
+ )
+ 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)