You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 5.2 KiB

1 vuosi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # imports - standard imports
  2. import os
  3. # imports - third party imports
  4. import click
  5. @click.command("start", help="Start Xhiveframework development processes")
  6. @click.option("--no-dev", is_flag=True, default=False)
  7. @click.option(
  8. "--no-prefix",
  9. is_flag=True,
  10. default=False,
  11. help="Hide process name from bench start log",
  12. )
  13. @click.option("--concurrency", "-c", type=str)
  14. @click.option("--procfile", "-p", type=str)
  15. @click.option("--man", "-m", help="Process Manager of your choice ;)")
  16. def start(no_dev, concurrency, procfile, no_prefix, man):
  17. from bench.utils.system import start
  18. start(
  19. no_dev=no_dev,
  20. concurrency=concurrency,
  21. procfile=procfile,
  22. no_prefix=no_prefix,
  23. procman=man,
  24. )
  25. @click.command("restart", help="Restart supervisor processes or systemd units")
  26. @click.option("--web", is_flag=True, default=False)
  27. @click.option("--supervisor", is_flag=True, default=False)
  28. @click.option("--systemd", is_flag=True, default=False)
  29. def restart(web, supervisor, systemd):
  30. from bench.bench import Bench
  31. if not systemd and not web:
  32. supervisor = True
  33. Bench(".").reload(web, supervisor, systemd)
  34. @click.command("set-nginx-port", help="Set NGINX port for site")
  35. @click.argument("site")
  36. @click.argument("port", type=int)
  37. def set_nginx_port(site, port):
  38. from bench.config.site_config import set_nginx_port
  39. set_nginx_port(site, port)
  40. @click.command("set-ssl-certificate", help="Set SSL certificate path for site")
  41. @click.argument("site")
  42. @click.argument("ssl-certificate-path")
  43. def set_ssl_certificate(site, ssl_certificate_path):
  44. from bench.config.site_config import set_ssl_certificate
  45. set_ssl_certificate(site, ssl_certificate_path)
  46. @click.command("set-ssl-key", help="Set SSL certificate private key path for site")
  47. @click.argument("site")
  48. @click.argument("ssl-certificate-key-path")
  49. def set_ssl_certificate_key(site, ssl_certificate_key_path):
  50. from bench.config.site_config import set_ssl_certificate_key
  51. set_ssl_certificate_key(site, ssl_certificate_key_path)
  52. @click.command("set-url-root", help="Set URL root for site")
  53. @click.argument("site")
  54. @click.argument("url-root")
  55. def set_url_root(site, url_root):
  56. from bench.config.site_config import set_url_root
  57. set_url_root(site, url_root)
  58. @click.command("set-mariadb-host", help="Set MariaDB host for bench")
  59. @click.argument("host")
  60. def set_mariadb_host(host):
  61. from bench.utils.bench import set_mariadb_host
  62. set_mariadb_host(host)
  63. @click.command("set-redis-cache-host", help="Set Redis cache host for bench")
  64. @click.argument("host")
  65. def set_redis_cache_host(host):
  66. """
  67. Usage: bench set-redis-cache-host localhost:6379/1
  68. """
  69. from bench.utils.bench import set_redis_cache_host
  70. set_redis_cache_host(host)
  71. @click.command("set-redis-queue-host", help="Set Redis queue host for bench")
  72. @click.argument("host")
  73. def set_redis_queue_host(host):
  74. """
  75. Usage: bench set-redis-queue-host localhost:6379/2
  76. """
  77. from bench.utils.bench import set_redis_queue_host
  78. set_redis_queue_host(host)
  79. @click.command("set-redis-socketio-host", help="Set Redis socketio host for bench")
  80. @click.argument("host")
  81. def set_redis_socketio_host(host):
  82. """
  83. Usage: bench set-redis-socketio-host localhost:6379/3
  84. """
  85. from bench.utils.bench import set_redis_socketio_host
  86. set_redis_socketio_host(host)
  87. @click.command("download-translations", help="Download latest translations")
  88. def download_translations():
  89. from bench.utils.translation import download_translations_p
  90. download_translations_p()
  91. @click.command(
  92. "renew-lets-encrypt", help="Sets Up latest cron and Renew Let's Encrypt certificate"
  93. )
  94. def renew_lets_encrypt():
  95. from bench.config.lets_encrypt import renew_certs
  96. renew_certs()
  97. @click.command("backup-all-sites", help="Backup all sites in current bench")
  98. def backup_all_sites():
  99. from bench.utils.system import backup_all_sites
  100. backup_all_sites(bench_path=".")
  101. @click.command(
  102. "disable-production", help="Disables production environment for the bench."
  103. )
  104. def disable_production():
  105. from bench.config.production_setup import disable_production
  106. disable_production(bench_path=".")
  107. @click.command(
  108. "src", help="Prints bench source folder path, which can be used as: cd `bench src`"
  109. )
  110. def bench_src():
  111. from bench.cli import src
  112. print(os.path.dirname(src))
  113. @click.command("find", help="Finds benches recursively from location")
  114. @click.argument("location", default="")
  115. def find_benches(location):
  116. from bench.utils import find_benches
  117. find_benches(directory=location)
  118. @click.command(
  119. "migrate-env", help="Migrate Virtual Environment to desired Python Version"
  120. )
  121. @click.argument("python", type=str)
  122. @click.option("--no-backup", "backup", is_flag=True, default=True)
  123. def migrate_env(python, backup=True):
  124. from bench.utils.bench import migrate_env
  125. migrate_env(python=python, backup=backup)
  126. @click.command("app-cache", help="View or remove items belonging to bench get-app cache")
  127. @click.option("--clear", is_flag=True, default=False, help="Remove all items")
  128. @click.option(
  129. "--remove-app",
  130. default="",
  131. help="Removes all items that match provided app name",
  132. )
  133. @click.option(
  134. "--remove-key",
  135. default="",
  136. help="Removes all items that matches provided cache key",
  137. )
  138. def app_cache_helper(clear=False, remove_app="", remove_key=""):
  139. from bench.utils.bench import cache_helper
  140. cache_helper(clear, remove_app, remove_key)