blob: 642a5b7595ea75da15322508a2f0acae27d38ff3 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001#
2# This class creates mime <-> application associations based on entry
3# 'MimeType' in *.desktop files
4#
5
6DEPENDS += "desktop-file-utils"
7PACKAGE_WRITE_DEPS += "desktop-file-utils-native"
8DESKTOPDIR = "${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
15MIME_XDG_PACKAGES ?= ""
16
17mime_xdg_postinst() {
18if [ "x$D" != "x" ]; then
19 $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
20 mlprefix=${MLPREFIX} \
21 desktop_dir=${DESKTOPDIR}
22else
23 update-desktop-database $D${DESKTOPDIR}
24fi
25}
26
27mime_xdg_postrm() {
28if [ "x$D" != "x" ]; then
29 $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
30 mlprefix=${MLPREFIX} \
31 desktop_dir=${DESKTOPDIR}
32else
33 update-desktop-database $D${DESKTOPDIR}
34fi
35}
36
37python populate_packages_append () {
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)
62 postinst = d.getVar('pkg_postinst_%s' % pkg)
63 if not postinst:
64 postinst = '#!/bin/sh\n'
65 postinst += d.getVar('mime_xdg_postinst')
66 d.setVar('pkg_postinst_%s' % pkg, postinst)
67 postrm = d.getVar('pkg_postrm_%s' % pkg)
68 if not postrm:
69 postrm = '#!/bin/sh\n'
70 postrm += d.getVar('mime_xdg_postrm')
71 d.setVar('pkg_postrm_%s' % pkg, postrm)
72 bb.note("adding desktop-file-utils dependency to %s" % pkg)
73 d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils")
74}