setup.py.jinja 859 B

12345678910111213141516171819202122232425262728293031323334
  1. {% macro setup_script(values) -%}
  2. import os
  3. import json
  4. print("Updating config...")
  5. path = "{{ values.consts.data_dir }}/config/config.json"
  6. data = {"general": {"port": {{ values.network.web_port.port_number }}}}
  7. if not os.path.exists(path):
  8. os.makedirs(os.path.dirname(path), exist_ok=True)
  9. with open(path, "w") as f:
  10. f.write(json.dumps(data, indent=4))
  11. print("Config created!")
  12. exit(0)
  13. try:
  14. with open(path, "r") as f:
  15. data = json.load(f)
  16. except Exception as e:
  17. print("Failed to load config, exiting...", e)
  18. exit(1)
  19. data["general"]["port"] = {{ values.network.web_port.port_number }}
  20. print("Setting port to", data["general"]["port"])
  21. try:
  22. with open(path, "w") as f:
  23. json.dump(data, f, indent=4)
  24. except Exception as e:
  25. print("Failed to update config, exiting...", e)
  26. exit(1)
  27. print("Config updated!")
  28. {%- endmacro -%}