Digitale bierlijst

install-service-files.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import os.path
  2. import sys
  3. from piket_client.gui import PiketMainWindow
  4. icons_dir = PiketMainWindow.icons_dir
  5. systemd_user_dir = os.path.expanduser("~/.config/systemd/user")
  6. python_interpreter_dir = os.path.dirname(sys.executable)
  7. uwsgi_path = os.path.join(python_interpreter_dir, "uwsgi")
  8. piket_client_path = os.path.join(python_interpreter_dir, "piket-client")
  9. piket_manage_people_path = os.path.join(python_interpreter_dir, "piket-manage-people")
  10. server_template = f"""[Unit]
  11. Description=piket server daemon
  12. [Service]
  13. ExecStart={uwsgi_path} --http :5000 --master --threads 2 --module piket_server:app
  14. KillSignal=SIGINT
  15. Type=notify
  16. NotifyAccess=all
  17. Environment=SENTRY_DSN={os.environ.get("SENTRY_DSN")}
  18. [Install]
  19. WantedBy=default.target
  20. """
  21. client_template = f"""[Unit]
  22. Description=piket client
  23. Requires=piket-server.service
  24. After=piket-server.service
  25. [Service]
  26. ExecStart={piket_client_path}
  27. Environment=SENTRY_DSN={os.environ.get("SENTRY_DSN")}
  28. [Install]
  29. WantedBy=graphical.target
  30. """
  31. os.makedirs(systemd_user_dir, exist_ok=True)
  32. with open(os.path.join(systemd_user_dir, "piket-server.service"), "w") as f:
  33. f.write(server_template)
  34. with open(os.path.join(systemd_user_dir, "piket-client.service"), "w") as f:
  35. f.write(client_template)
  36. # Desktop files
  37. main_template = f"""[Desktop Entry]
  38. Version=0.1.0
  39. Type=Application
  40. Name=Start Bierlijst
  41. Terminal=False
  42. Comment=V-V-V-OUWEN!!!
  43. Exec=systemctl --user start piket-client
  44. Icon={os.path.join(icons_dir, "white_beer_bottle.svg")}
  45. """
  46. manage_people = f"""[Desktop Entry]
  47. Version=0.1.0
  48. Type=Application
  49. Name=Personen aanwezig
  50. Terminal=False
  51. Comment=Stel in wie er is.
  52. Exec={sys.executable} -m piket_client.set_active
  53. Icon={os.path.join(icons_dir, "white_add_person.svg")}
  54. """
  55. with open(
  56. os.path.join(os.path.expanduser("~/Desktop"), "piket-client.desktop"), "w"
  57. ) as f:
  58. f.write(main_template)
  59. with open(
  60. os.path.join(os.path.expanduser("~/Desktop"), "piket-manage-people.desktop"), "w"
  61. ) as f:
  62. f.write(manage_people)
  63. print("Done! Don't forget to systemctl --user daemon-reload.")