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