seed.py 2.7 KB

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