seed.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "navbar item": "/admin/navbar/new"
  17. },
  18. "modify": {
  19. "blog post": "/admin/posts/all",
  20. "navbar": "/admin/navbar/all"
  21. },
  22. }
  23. menu = {
  24. "//Administrator": "/admin/panel",
  25. "//Creative Writing": "/creative",
  26. "//Black Box": "/blog",
  27. "//Digital Art": "/digital"
  28. }
  29. navbar_items = {
  30. "./assets/github.png": "https://github.com/AETH-erial",
  31. "./assets/git.png": "https://git.aetherial.dev/aeth",
  32. "./assets/twitter.png": "https://x.com/Aetherial___",
  33. "./assets/linkedin.png": "https://www.linkedin.com/in/russell-hrubesky-a62237221/",
  34. "./assets/soundcloud.png": "https://soundcloud.com/aeth-592553883"
  35. }
  36. assets = [
  37. "./assets/menu.png",
  38. "./assets/github.png",
  39. "./assets/git.png",
  40. "./assets/twitter.png",
  41. "./assets/linkedin.png",
  42. "./assets/soundcloud.png"
  43. ]
  44. # find the keiji-ctl command
  45. def _find_keiji_ctl() -> str:
  46. split_path = os.environ["PATH"].split(":")
  47. for path in split_path:
  48. cmd_path = f"{path}/{KEIJI_CTL}"
  49. try:
  50. mode = os.stat(f"{path}/{KEIJI_CTL}").st_mode
  51. except FileNotFoundError:
  52. continue
  53. if stat.S_ISREG(mode):
  54. return cmd_path
  55. raise FileNotFoundError(f"the {KEIJI_CTL} binary could not be found in the system path.")
  56. def main():
  57. """ setup script shit """
  58. path = _find_keiji_ctl()
  59. cookie = subprocess.run([path, "-cmd", "auth", "-address", URL], capture_output=True, text=True).stdout.strip("\n")
  60. print(cookie)
  61. for asset in assets:
  62. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "asset", "-png", asset])
  63. for image, redirect in navbar_items.items():
  64. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "nav", "-png", image, "-redirect", redirect])
  65. for text, redirect in menu.items():
  66. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "menu", "-text", text, "-redirect", redirect])
  67. for category, pairings in admin_table.items():
  68. for text, redirect in pairings.items():
  69. subprocess.run([path, "-address", URL, "-cookie", cookie, "-cmd", "admin", "-text", text, "-redirect", redirect, "-col", category])
  70. main()