postinstall.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from sys import platform
  2. from platformdirs import user_data_path
  3. from .resource_provider import gooey_resources
  4. def perform_post_install_tasks():
  5. if platform == "linux":
  6. create_desktop_file()
  7. copy_icon()
  8. else:
  9. print("Nothing to do")
  10. def create_desktop_file():
  11. df_name = "datalad-gooey.desktop"
  12. template_path = gooey_resources.get_resource_path('desktop') / df_name
  13. target_path = user_data_path() / "applications" / df_name
  14. if not target_path.parent.exists():
  15. target_path.parent.mkdir()
  16. target_path.write_text(template_path.read_text())
  17. print("Created desktop file in", target_path)
  18. def copy_icon():
  19. source_path = gooey_resources.get_icon_path('datalad_gooey_logo')
  20. target_path = user_data_path() / "icons" / "datalad-gooey"
  21. if not target_path.parent.exists():
  22. target_path.parent.mkdir()
  23. # svg is text & rewriting file contents is ok, no need for shutil.copy
  24. target_path.write_text(source_path.read_text())
  25. print("Created icon in", target_path)