mime-xdg.bbclass 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # This class creates mime <-> application associations based on entry
  3. # 'MimeType' in *.desktop files
  4. #
  5. DEPENDS += "desktop-file-utils"
  6. PACKAGE_WRITE_DEPS += "desktop-file-utils-native"
  7. DESKTOPDIR = "${datadir}/applications"
  8. # There are recipes out there installing their .desktop files as absolute
  9. # symlinks. For us these are dangling and cannot be introspected for "MymeType"
  10. # easily. By addding package-names to MIME_XDG_PACKAGES, packager can force
  11. # proper update-desktop-database handling. Note that all introspection is
  12. # skipped for MIME_XDG_PACKAGES not empty
  13. MIME_XDG_PACKAGES ?= ""
  14. mime_xdg_postinst() {
  15. if [ "x$D" != "x" ]; then
  16. $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
  17. mlprefix=${MLPREFIX} \
  18. desktop_dir=${DESKTOPDIR}
  19. else
  20. update-desktop-database $D${DESKTOPDIR}
  21. fi
  22. }
  23. mime_xdg_postrm() {
  24. if [ "x$D" != "x" ]; then
  25. $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
  26. mlprefix=${MLPREFIX} \
  27. desktop_dir=${DESKTOPDIR}
  28. else
  29. update-desktop-database $D${DESKTOPDIR}
  30. fi
  31. }
  32. python populate_packages_append () {
  33. packages = d.getVar('PACKAGES').split()
  34. pkgdest = d.getVar('PKGDEST')
  35. desktop_base = d.getVar('DESKTOPDIR')
  36. forced_mime_xdg_pkgs = (d.getVar('MIME_XDG_PACKAGES') or '').split()
  37. for pkg in packages:
  38. desktops_with_mime_found = pkg in forced_mime_xdg_pkgs
  39. if d.getVar('MIME_XDG_PACKAGES') == '':
  40. desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base)
  41. if os.path.exists(desktop_dir):
  42. for df in os.listdir(desktop_dir):
  43. if df.endswith('.desktop'):
  44. try:
  45. with open(desktop_dir + '/'+ df, 'r') as f:
  46. for line in f.read().split('\n'):
  47. if 'MimeType' in line:
  48. desktops_with_mime_found = True
  49. break;
  50. except:
  51. bb.warn('Could not open %s. Set MIME_XDG_PACKAGES in recipe or add mime-xdg to INSANE_SKIP.' % desktop_dir + '/'+ df)
  52. if desktops_with_mime_found:
  53. break
  54. if desktops_with_mime_found:
  55. bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg)
  56. postinst = d.getVar('pkg_postinst_%s' % pkg)
  57. if not postinst:
  58. postinst = '#!/bin/sh\n'
  59. postinst += d.getVar('mime_xdg_postinst')
  60. d.setVar('pkg_postinst_%s' % pkg, postinst)
  61. postrm = d.getVar('pkg_postrm_%s' % pkg)
  62. if not postrm:
  63. postrm = '#!/bin/sh\n'
  64. postrm += d.getVar('mime_xdg_postrm')
  65. d.setVar('pkg_postrm_%s' % pkg, postrm)
  66. bb.note("adding desktop-file-utils dependency to %s" % pkg)
  67. d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils")
  68. }