blob: 271f48dd729d326be93b744a1270d64b56681906 [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
Patrick Williams213cb262021-08-07 19:21:33 -050037python populate_packages:append () {
Andrew Geissler82c905d2020-04-13 13:39:40 -050038 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 Williams213cb262021-08-07 19:21:33 -050062 postinst = d.getVar('pkg_postinst:%s' % pkg)
Andrew Geissler82c905d2020-04-13 13:39:40 -050063 if not postinst:
64 postinst = '#!/bin/sh\n'
65 postinst += d.getVar('mime_xdg_postinst')
Patrick Williams213cb262021-08-07 19:21:33 -050066 d.setVar('pkg_postinst:%s' % pkg, postinst)
67 postrm = d.getVar('pkg_postrm:%s' % pkg)
Andrew Geissler82c905d2020-04-13 13:39:40 -050068 if not postrm:
69 postrm = '#!/bin/sh\n'
70 postrm += d.getVar('mime_xdg_postrm')
Patrick Williams213cb262021-08-07 19:21:33 -050071 d.setVar('pkg_postrm:%s' % pkg, postrm)
Andrew Geissler82c905d2020-04-13 13:39:40 -050072 bb.note("adding desktop-file-utils dependency to %s" % pkg)
Patrick Williams213cb262021-08-07 19:21:33 -050073 d.appendVar('RDEPENDS:' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils")
Andrew Geissler82c905d2020-04-13 13:39:40 -050074}