generate_config 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. import argparse
  3. import sys
  4. from synapse.config.homeserver import HomeServerConfig
  5. if __name__ == "__main__":
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument(
  8. "--config-dir",
  9. default="CONFDIR",
  10. help="The path where the config files are kept. Used to create filenames for "
  11. "things like the log config and the signing key. Default: %(default)s",
  12. )
  13. parser.add_argument(
  14. "--data-dir",
  15. default="DATADIR",
  16. help="The path where the data files are kept. Used to create filenames for "
  17. "things like the database and media store. Default: %(default)s",
  18. )
  19. parser.add_argument(
  20. "--server-name",
  21. default="SERVERNAME",
  22. help="The server name. Used to initialise the server_name config param, but also "
  23. "used in the names of some of the config files. Default: %(default)s",
  24. )
  25. parser.add_argument(
  26. "--report-stats",
  27. action="store",
  28. help="Whether the generated config reports anonymized usage statistics",
  29. choices=["yes", "no"],
  30. )
  31. parser.add_argument(
  32. "--generate-secrets",
  33. action="store_true",
  34. help="Enable generation of new secrets for things like the macaroon_secret_key."
  35. "By default, these parameters will be left unset."
  36. )
  37. parser.add_argument(
  38. "-o", "--output-file",
  39. type=argparse.FileType('w'),
  40. default=sys.stdout,
  41. help="File to write the configuration to. Default: stdout",
  42. )
  43. args = parser.parse_args()
  44. report_stats = args.report_stats
  45. if report_stats is not None:
  46. report_stats = report_stats == "yes"
  47. conf = HomeServerConfig().generate_config(
  48. config_dir_path=args.config_dir,
  49. data_dir_path=args.data_dir,
  50. server_name=args.server_name,
  51. generate_secrets=args.generate_secrets,
  52. report_stats=report_stats,
  53. )
  54. args.output_file.write(conf)