generate_config 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. import argparse
  3. import sys
  4. from sydent.config import SydentConfig
  5. if __name__ == "__main__":
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument(
  8. "--template-dir",
  9. default="TEMPLATE_DIR",
  10. help="The root path where the template files are kept. Default: %(default)s",
  11. )
  12. parser.add_argument(
  13. "--server-name",
  14. default="SERVER_NAME",
  15. help="The server name. Used to initialise the server_name config param. "
  16. "Default: %(default)s",
  17. )
  18. parser.add_argument(
  19. "--pid-file",
  20. default="sydent.pid",
  21. help="The file where the PID of the running Sydent process will be written. "
  22. "Default: %(default)s",
  23. )
  24. parser.add_argument(
  25. "--db-path",
  26. default="sydent.db",
  27. help="The SQLite Database file for Sydent to use. Default: %(default)s",
  28. )
  29. parser.add_argument(
  30. "--no-secrets",
  31. action="store_true",
  32. help="Disable the automatic generation of secrets like the signing key",
  33. )
  34. parser.add_argument(
  35. "-o",
  36. "--output-file",
  37. type=argparse.FileType("w"),
  38. default=sys.stdout,
  39. help="File to write the configuration to. Default: stdout",
  40. )
  41. args = parser.parse_args()
  42. conf = SydentConfig().generate_config(
  43. template_dir_path=args.template_dir,
  44. server_name=args.server_name,
  45. pid_file=args.pid_file,
  46. db_path=args.db_path,
  47. generate_secrets=(not args.no_secrets),
  48. )
  49. args.output_file.write(conf)