generate_config 2.2 KB

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