seed.py 2.6 KB

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