diff options
author | Anton Tananaev <anton@traccar.org> | 2023-01-01 11:10:35 -0800 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-01-01 11:10:35 -0800 |
commit | 42f269d5f9e0829c7dbfa22ccb6b41415e6e4415 (patch) | |
tree | 7aece52814ef57ab7b32df3fc8e9c8c7563fa810 /tools/gen_config_doc.py | |
parent | 67964087deaa12557ac3c48b537ee22475f82f5d (diff) | |
download | trackermap-server-42f269d5f9e0829c7dbfa22ccb6b41415e6e4415.tar.gz trackermap-server-42f269d5f9e0829c7dbfa22ccb6b41415e6e4415.tar.bz2 trackermap-server-42f269d5f9e0829c7dbfa22ccb6b41415e6e4415.zip |
Rename config script
Diffstat (limited to 'tools/gen_config_doc.py')
-rw-r--r-- | tools/gen_config_doc.py | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/tools/gen_config_doc.py b/tools/gen_config_doc.py deleted file mode 100644 index 98266386e..000000000 --- a/tools/gen_config_doc.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/python - -import re -import os -import argparse - -_KEYS_FILE = os.path.join( - os.path.dirname(__file__), "../src/main/java/org/traccar/config/Keys.java" -) - - -def get_config_keys(): - """Parses Keys.java to extract keys to be used in configuration files - - Args: None - - Returns: - list: A list of dict containing the following keys - - 'key': A dot separated name of the config key - 'description': A list of str - """ - 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) - keys = [] - - with open(_KEYS_FILE, "r") as f: - config = re.findall( - r"(/\*\*.*?\*/)\n\s+(public static final Config.*?;)", f.read(), re.DOTALL - ) - for i in config: - try: - key_match = key_match_re.search(i[1]) - if key_match: - terms = [x.strip() for x in key_split_re.split(key_match.group(1))] - key = terms[0].replace('"', "") - description = [ - x.strip().replace("\n", "") - for x in desc_re.sub("\n", i[0]).strip().split("\n\n") - ] - if len(terms) == 3: - description.append(f"Default: {terms[2]}") - keys.append( - { - "key": key, - "description": description, - } - ) - except IndexError: - # will continue if key_match.group(1) or terms[0] does not exist - # for some reason - pass - - return keys - - -def get_html(): - return ("\n").join( - [ - f""" <div class="card mt-3"> - <div class="card-body"> - <h5 class="card-title"> - {x["key"]} <span class="badge badge-dark">config</span> - </h5> - <p class="card-text"> - {"<br /> ".join(x["description"])} - </p> - </div> - </div>""" - for x in get_config_keys() - ] - ) - - -def get_pug(): - return ("\n").join( - [ - f""" div(class='card mt-3') - div(class='card-body') - h5(class='card-title') {x["key"]} #[span(class='badge badge-dark') config] - p(class='card-text') {"#[br] ".join(x["description"])}""" - for x in get_config_keys() - ] - ) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Parses Keys.java to extract keys to be used in configuration files" - ) - parser.add_argument( - "--format", choices=["pug", "html"], default="pug", help="default: 'pug'" - ) - args = parser.parse_args() - - def get_output(): - if args.format == 'html': - return get_html() - - return get_pug() - - print(get_output())
\ No newline at end of file |