mime.bbclass 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # This class is used by recipes installing mime types
  3. #
  4. DEPENDS += "${@bb.utils.contains('BPN', 'shared-mime-info', '', 'shared-mime-info', d)}"
  5. PACKAGE_WRITE_DEPS += "shared-mime-info-native"
  6. MIMEDIR = "${datadir}/mime"
  7. mime_postinst() {
  8. if [ "x$D" != "x" ]; then
  9. $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
  10. mlprefix=${MLPREFIX} \
  11. mimedir=${MIMEDIR}
  12. else
  13. echo "Updating MIME database... this may take a while."
  14. update-mime-database $D${MIMEDIR}
  15. fi
  16. }
  17. mime_postrm() {
  18. if [ "x$D" != "x" ]; then
  19. $INTERCEPT_DIR/postinst_intercept update_mime_database ${PKG} \
  20. mlprefix=${MLPREFIX} \
  21. mimedir=${MIMEDIR}
  22. else
  23. echo "Updating MIME database... this may take a while."
  24. # $D${MIMEDIR}/packages belong to package shared-mime-info-data,
  25. # packages like libfm-mime depend on shared-mime-info-data.
  26. # after shared-mime-info-data uninstalled, $D${MIMEDIR}/packages
  27. # is removed, but update-mime-database need this dir to update
  28. # database, workaround to create one and remove it later
  29. if [ ! -d $D${MIMEDIR}/packages ]; then
  30. mkdir -p $D${MIMEDIR}/packages
  31. update-mime-database $D${MIMEDIR}
  32. rmdir --ignore-fail-on-non-empty $D${MIMEDIR}/packages
  33. else
  34. update-mime-database $D${MIMEDIR}
  35. fi
  36. fi
  37. }
  38. python populate_packages_append () {
  39. packages = d.getVar('PACKAGES').split()
  40. pkgdest = d.getVar('PKGDEST')
  41. mimedir = d.getVar('MIMEDIR')
  42. for pkg in packages:
  43. mime_packages_dir = '%s/%s%s/packages' % (pkgdest, pkg, mimedir)
  44. mimes_types_found = False
  45. if os.path.exists(mime_packages_dir):
  46. for f in os.listdir(mime_packages_dir):
  47. if f.endswith('.xml'):
  48. mimes_types_found = True
  49. break
  50. if mimes_types_found:
  51. bb.note("adding mime postinst and postrm scripts to %s" % pkg)
  52. postinst = d.getVar('pkg_postinst_%s' % pkg)
  53. if not postinst:
  54. postinst = '#!/bin/sh\n'
  55. postinst += d.getVar('mime_postinst')
  56. d.setVar('pkg_postinst_%s' % pkg, postinst)
  57. postrm = d.getVar('pkg_postrm_%s' % pkg)
  58. if not postrm:
  59. postrm = '#!/bin/sh\n'
  60. postrm += d.getVar('mime_postrm')
  61. d.setVar('pkg_postrm_%s' % pkg, postrm)
  62. if pkg != 'shared-mime-info-data':
  63. bb.note("adding shared-mime-info-data dependency to %s" % pkg)
  64. d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"shared-mime-info-data")
  65. }