postinstall.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from sys import platform
  2. from importlib_resources import files # from Python 3.10 use importlib.resources
  3. from platformdirs import user_data_path
  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 = files("datalad_gooey.resources.desktop").joinpath(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 = files(
  20. "datalad_gooey.resources.icons"
  21. ).joinpath('datalad_gooey_logo.svg')
  22. target_path = user_data_path() / "icons" / "datalad-gooey"
  23. if not target_path.parent.exists():
  24. target_path.parent.mkdir()
  25. # svg is text & rewriting file contents is ok, no need for shutil.copy
  26. target_path.write_text(source_path.read_text())
  27. print("Created icon in", target_path)