Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

100 řádky
2.8 KiB

  1. # imports - module imports
  2. from bench.config.common_site_config import update_config, put_config
  3. # imports - third party imports
  4. import click
  5. @click.group(help="Change bench configuration")
  6. def config():
  7. pass
  8. @click.command(
  9. "restart_supervisor_on_update",
  10. help="Enable/Disable auto restart of supervisor processes",
  11. )
  12. @click.argument("state", type=click.Choice(["on", "off"]))
  13. def config_restart_supervisor_on_update(state):
  14. update_config({"restart_supervisor_on_update": state == "on"})
  15. @click.command(
  16. "restart_systemd_on_update", help="Enable/Disable auto restart of systemd units"
  17. )
  18. @click.argument("state", type=click.Choice(["on", "off"]))
  19. def config_restart_systemd_on_update(state):
  20. update_config({"restart_systemd_on_update": state == "on"})
  21. @click.command(
  22. "dns_multitenant", help="Enable/Disable bench multitenancy on running bench update"
  23. )
  24. @click.argument("state", type=click.Choice(["on", "off"]))
  25. def config_dns_multitenant(state):
  26. update_config({"dns_multitenant": state == "on"})
  27. @click.command(
  28. "serve_default_site", help="Configure nginx to serve the default site on port 80"
  29. )
  30. @click.argument("state", type=click.Choice(["on", "off"]))
  31. def config_serve_default_site(state):
  32. update_config({"serve_default_site": state == "on"})
  33. @click.command("rebase_on_pull", help="Rebase repositories on pulling")
  34. @click.argument("state", type=click.Choice(["on", "off"]))
  35. def config_rebase_on_pull(state):
  36. update_config({"rebase_on_pull": state == "on"})
  37. @click.command("http_timeout", help="Set HTTP timeout")
  38. @click.argument("seconds", type=int)
  39. def config_http_timeout(seconds):
  40. update_config({"http_timeout": seconds})
  41. @click.command("set-common-config", help="Set value in common config")
  42. @click.option("configs", "-c", "--config", multiple=True, type=(str, str))
  43. def set_common_config(configs):
  44. import ast
  45. common_site_config = {}
  46. for key, value in configs:
  47. if value in ("true", "false"):
  48. value = value.title()
  49. try:
  50. value = ast.literal_eval(value)
  51. except ValueError:
  52. pass
  53. common_site_config[key] = value
  54. update_config(common_site_config, bench_path=".")
  55. @click.command(
  56. "remove-common-config", help="Remove specific keys from current bench's common config"
  57. )
  58. @click.argument("keys", nargs=-1)
  59. def remove_common_config(keys):
  60. from bench.bench import Bench
  61. common_site_config = Bench(".").conf
  62. for key in keys:
  63. if key in common_site_config:
  64. del common_site_config[key]
  65. put_config(common_site_config)
  66. config.add_command(config_restart_supervisor_on_update)
  67. config.add_command(config_restart_systemd_on_update)
  68. config.add_command(config_dns_multitenant)
  69. config.add_command(config_rebase_on_pull)
  70. config.add_command(config_serve_default_site)
  71. config.add_command(config_http_timeout)
  72. config.add_command(set_common_config)
  73. config.add_command(remove_common_config)