1
0

generate_config 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  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", "--output-file",
  40. type=argparse.FileType('w'),
  41. default=sys.stdout,
  42. help="File to write the configuration to. Default: stdout",
  43. )
  44. parser.add_argument(
  45. "--header-file",
  46. type=argparse.FileType('r'),
  47. help="File from which to read a header, which will be printed before the "
  48. "generated config.",
  49. )
  50. args = parser.parse_args()
  51. report_stats = args.report_stats
  52. if report_stats is not None:
  53. report_stats = report_stats == "yes"
  54. conf = HomeServerConfig().generate_config(
  55. config_dir_path=args.config_dir,
  56. data_dir_path=args.data_dir,
  57. server_name=args.server_name,
  58. generate_secrets=args.generate_secrets,
  59. report_stats=report_stats,
  60. )
  61. if args.header_file:
  62. shutil.copyfileobj(args.header_file, args.output_file)
  63. args.output_file.write(conf)