The web design and pages for my personal website.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

83 linhas
2.6 KiB

  1. #!/usr/bin/env python3
  2. """Bootstrap script to set up a local dev instance of Kirsle.net
  3. This will `git clone` an instance of the Rophako CMS and configure it to run
  4. this local website. When the dev Rophako instance already exists, running this
  5. script again acts as a shortcut to running `python runserver.py` from within
  6. the Rophako git repo.
  7. This script is only designed to work in Python 3 and requires the `git` and
  8. `pyvenv` commands.
  9. This performs the following tasks:
  10. * Clones Rophako into ./rophako
  11. * Sets up a Python 3 virtual environment via `pyvenv` at ./rophako/pyvenv
  12. * Installs requirements via `pip` into its virtual environment
  13. * Symlinks settings.yml and kirsle_legacy.py into the Rophako root
  14. * Runs the server
  15. """
  16. import os
  17. import os.path
  18. import subprocess
  19. import sys
  20. def main():
  21. # Make sure we have everything we need.
  22. check_depends()
  23. # Do we already have Rophako?
  24. if os.path.isdir("./rophako"):
  25. os.chdir("./rophako")
  26. else:
  27. # Clone it.
  28. must_run(["git", "clone", "https://github.com/kirsle/rophako"])
  29. os.chdir("./rophako")
  30. # Make the Python environment.
  31. must_run(["pyvenv", "pyvenv"])
  32. must_run(["pyvenv/bin/pip", "install", "-r", "requirements.txt"])
  33. # Configure it.
  34. os.symlink("../settings.yml", "settings.yml")
  35. os.symlink("../kirsle_legacy.py", "kirsle_legacy.py")
  36. print("=" * 80)
  37. print("Success! Rophako has been cloned and configured! The server")
  38. print("will now start. To quickly start the server again in the")
  39. print("future, just run bootstrap.py again.")
  40. print("=" * 80)
  41. # Run Rophako.
  42. must_run(["pyvenv/bin/python", "runserver.py"])
  43. def check_depends():
  44. # Make sure we have access to required commands.
  45. errors = False
  46. for command in [ "git", "pyvenv" ]:
  47. try:
  48. subprocess.check_call(["which", command],
  49. stdout=subprocess.PIPE,
  50. stderr=subprocess.PIPE,
  51. )
  52. except subprocess.CalledProcessError:
  53. print("You seem to be missing the command: {}".format(command))
  54. errors = True
  55. if errors:
  56. print("Make sure the required commands are installed and try again.")
  57. sys.exit(1)
  58. def must_run(args, **kwargs):
  59. """Calls subprocess to run a command which must succeed or die."""
  60. result = subprocess.call(args, **kwargs)
  61. if result != 0:
  62. print("Errors were detected in the command I tried to run: {}".format(
  63. " ".join(args),
  64. ))
  65. sys.exit(1)
  66. if __name__ == "__main__":
  67. main()