mirror of https://github.com/hrfee/jfa-go
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
4 years ago
|
# Generates config file
|
||
|
import configparser
|
||
|
import json
|
||
|
import argparse
|
||
|
from pathlib import Path
|
||
|
|
||
|
|
||
4 years ago
|
def generate_ini(base_file, ini_file):
|
||
4 years ago
|
"""
|
||
|
Generates .ini file from config-base file.
|
||
|
"""
|
||
|
with open(Path(base_file), "r") as f:
|
||
|
config_base = json.load(f)
|
||
|
|
||
|
ini = configparser.RawConfigParser(allow_no_value=True)
|
||
|
|
||
4 years ago
|
for section in config_base["sections"]:
|
||
4 years ago
|
ini.add_section(section)
|
||
4 years ago
|
if "meta" in config_base["sections"][section]:
|
||
|
ini.set(section, "; " + config_base["sections"][section]["meta"]["description"])
|
||
|
for entry in config_base["sections"][section]["settings"]:
|
||
|
if "description" in config_base["sections"][section]["settings"][entry]:
|
||
|
ini.set(section, "; " + config_base["sections"][section]["settings"][entry]["description"])
|
||
|
value = config_base["sections"][section]["settings"][entry]["value"]
|
||
|
if isinstance(value, bool):
|
||
|
value = str(value).lower()
|
||
|
else:
|
||
|
value = str(value)
|
||
|
ini.set(section, entry, value)
|
||
4 years ago
|
|
||
|
with open(Path(ini_file), "w") as config_file:
|
||
|
ini.write(config_file)
|
||
|
return True
|
||
|
|
||
|
|
||
4 years ago
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument("-i", "--input", help="input config base from jf-accounts")
|
||
|
parser.add_argument("-o", "--output", help="output ini")
|
||
|
|
||
|
args = parser.parse_args()
|
||
4 years ago
|
|
||
4 years ago
|
print(generate_ini(base_file=args.input, ini_file=args.output))
|