2020-07-12 18:53:04 +00:00
|
|
|
# Generates config file
|
2020-06-29 22:06:58 +00:00
|
|
|
import configparser
|
|
|
|
import json
|
|
|
|
from pathlib import Path
|
|
|
|
|
2020-06-29 22:23:43 +00:00
|
|
|
|
2020-06-30 18:58:06 +00:00
|
|
|
def generate_ini(base_file, ini_file, version):
|
2020-06-29 22:06:58 +00:00
|
|
|
"""
|
|
|
|
Generates .ini file from config-base file.
|
|
|
|
"""
|
2020-06-29 22:23:43 +00:00
|
|
|
with open(Path(base_file), "r") as f:
|
2020-06-29 22:06:58 +00:00
|
|
|
config_base = json.load(f)
|
2020-06-29 22:23:43 +00:00
|
|
|
|
2020-06-29 22:06:58 +00:00
|
|
|
ini = configparser.RawConfigParser(allow_no_value=True)
|
|
|
|
|
|
|
|
for section in config_base:
|
|
|
|
ini.add_section(section)
|
|
|
|
for entry in config_base[section]:
|
2020-06-29 22:23:43 +00:00
|
|
|
if "description" in config_base[section][entry]:
|
|
|
|
ini.set(section, "; " + config_base[section][entry]["description"])
|
|
|
|
if entry != "meta":
|
|
|
|
value = config_base[section][entry]["value"]
|
2020-06-29 22:06:58 +00:00
|
|
|
if isinstance(value, bool):
|
|
|
|
value = str(value).lower()
|
|
|
|
else:
|
|
|
|
value = str(value)
|
2020-06-29 22:23:43 +00:00
|
|
|
ini.set(section, entry, value)
|
2020-06-29 22:06:58 +00:00
|
|
|
|
2020-06-30 18:58:06 +00:00
|
|
|
ini["jellyfin"]["version"] = version
|
|
|
|
ini["jellyfin"]["device_id"] = ini["jellyfin"]["device_id"].replace(
|
|
|
|
"{version}", version
|
|
|
|
)
|
|
|
|
|
2020-06-29 22:23:43 +00:00
|
|
|
with open(Path(ini_file), "w") as config_file:
|
2020-06-29 22:06:58 +00:00
|
|
|
ini.write(config_file)
|
|
|
|
return True
|