seed.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/python
  2. import os
  3. import sys
  4. import stat
  5. import subprocess
  6. KEIJI_CTL = "keiji-ctl"
  7. URL = os.getenv("SITE_URL")
  8. # the seed loop needs to create all of the:
  9. # - admin table links
  10. # - navbar png/redirect combos
  11. # - the menu link pairs
  12. admin_table = {
  13. "new": {
  14. "blog post": "/admin/posts",
  15. "digital media": "/admin/upload"
  16. },
  17. "modify": {
  18. "blog post": "/admin/posts/all"
  19. },
  20. }
  21. menu = {
  22. "//Administrator": "/admin/panel",
  23. "//Creative Writing": "/creative",
  24. "//Black Box": "/blog",
  25. "//Digital Art": "/digital"
  26. }
  27. navbar_items = {
  28. "./assets/github.png": "https://github.com/AETH-erial",
  29. "./assets/git.png": "https://git.aetherial.dev/aeth",
  30. "./assets/twitter.png": "https://x.com/Aetherial___",
  31. "./assets/linkedin.png": "https://www.linkedin.com/in/russell-hrubesky-a62237221/",
  32. "./assets/soundcloud.png": "https://soundcloud.com/aeth-592553883"
  33. }
  34. assets = [
  35. "./assets/menu.png",
  36. "./assets/github.png",
  37. "./assets/git.png",
  38. "./assets/twitter.png",
  39. "./assets/linkedin.png",
  40. "./assets/soundcloud.png"
  41. ]
  42. # find the keiji-ctl command
  43. def _find_keiji_ctl() -> str:
  44. split_path = os.environ["PATH"].split(":")
  45. for path in split_path:
  46. cmd_path = f"{path}/{KEIJI_CTL}"
  47. try:
  48. mode = os.stat(f"{path}/{KEIJI_CTL}").st_mode
  49. except FileNotFoundError:
  50. continue
  51. if stat.S_ISREG(mode):
  52. return cmd_path
  53. raise FileNotFoundError(f"the {KEIJI_CTL} binary could not be found in the system path.")
  54. def main():
  55. """ setup script shit """
  56. path = _find_keiji_ctl()
  57. cookie = subprocess.run([path, "-cmd", "auth", "-address", URL], capture_output=True, text=True).stdout.strip("\n")
  58. print(cookie)
  59. for asset in assets:
  60. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "asset", "-png", asset])
  61. for image, redirect in navbar_items.items():
  62. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "nav", "-png", image, "-redirect", redirect])
  63. for text, redirect in menu.items():
  64. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "menu", "-text", text, "-redirect", redirect])
  65. for category, pairings in admin_table.items():
  66. for text, redirect in pairings.items():
  67. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "admin", "-text", text, "-redirect", redirect, "-col", category])
  68. main()