From: "Andreas Müller" <schnitzeltony@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH][v2 08/10] mime-xdg.bbclass: initial add
Date: Fri, 17 Jan 2020 22:29:06 +0100 [thread overview]
Message-ID: <20200117212908.32647-9-schnitzeltony@gmail.com> (raw)
In-Reply-To: <20200117212908.32647-1-schnitzeltony@gmail.com>
When opening files by file-browsers on fresh images, user has to choose the
application to open from the pool af ALL known applications even those not
designed to open the file selected. By inheriting this classs in recipes the
assosiations in /usr/share/applications/mimeinfo.cache are build by calling
update-desktop-database.
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
---
meta/classes/mime-xdg.bbclass | 74 +++++++++++++++++++
.../update_desktop_database | 8 ++
2 files changed, 82 insertions(+)
create mode 100644 meta/classes/mime-xdg.bbclass
create mode 100644 scripts/postinst-intercepts/update_desktop_database
diff --git a/meta/classes/mime-xdg.bbclass b/meta/classes/mime-xdg.bbclass
new file mode 100644
index 0000000000..63169e990d
--- /dev/null
+++ b/meta/classes/mime-xdg.bbclass
@@ -0,0 +1,74 @@
+#
+# This class creates mime <-> application associations based on entry
+# 'MimeType' in *.desktop files
+#
+
+DEPENDS += "desktop-file-utils"
+PACKAGE_WRITE_DEPS += "desktop-file-utils-native"
+DESKTOPDIR = "${datadir}/applications"
+
+# There are recipes out there installing their .desktop files as absolute
+# symlinks. For us these are dangling and cannot be introspected for "MymeType"
+# easily. By addding package-names to MIME_XDG_PACKAGES, packager can force
+# proper update-desktop-database handling. Note that all introspection is
+# skipped for MIME_XDG_PACKAGES not empty
+MIME_XDG_PACKAGES ?= ""
+
+mime_xdg_postinst() {
+if [ "x$D" != "x" ]; then
+ $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
+ mlprefix=${MLPREFIX} \
+ desktop_dir=${DESKTOPDIR}
+else
+ update-desktop-database $D${DESKTOPDIR}
+fi
+}
+
+mime_xdg_postrm() {
+if [ "x$D" != "x" ]; then
+ $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \
+ mlprefix=${MLPREFIX} \
+ desktop_dir=${DESKTOPDIR}
+else
+ update-desktop-database $D${DESKTOPDIR}
+fi
+}
+
+python populate_packages_append () {
+ packages = d.getVar('PACKAGES').split()
+ pkgdest = d.getVar('PKGDEST')
+ desktop_base = d.getVar('DESKTOPDIR')
+ forced_mime_xdg_pkgs = (d.getVar('MIME_XDG_PACKAGES') or '').split()
+
+ for pkg in packages:
+ desktops_with_mime_found = pkg in forced_mime_xdg_pkgs
+ if d.getVar('MIME_XDG_PACKAGES') == '':
+ desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base)
+ if os.path.exists(desktop_dir):
+ for df in os.listdir(desktop_dir):
+ if df.endswith('.desktop'):
+ try:
+ with open(desktop_dir + '/'+ df, 'r') as f:
+ for line in f.read().split('\n'):
+ if 'MimeType' in line:
+ desktops_with_mime_found = True
+ break;
+ except:
+ bb.warn('Could not open %s. Set MIME_XDG_PACKAGES in recipe or add mime-xdg to INSANE_SKIP.' % desktop_dir + '/'+ df)
+ if desktops_with_mime_found:
+ break
+ if desktops_with_mime_found:
+ bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg)
+ postinst = d.getVar('pkg_postinst_%s' % pkg)
+ if not postinst:
+ postinst = '#!/bin/sh\n'
+ postinst += d.getVar('mime_xdg_postinst')
+ d.setVar('pkg_postinst_%s' % pkg, postinst)
+ postrm = d.getVar('pkg_postrm_%s' % pkg)
+ if not postrm:
+ postrm = '#!/bin/sh\n'
+ postrm += d.getVar('mime_xdg_postrm')
+ d.setVar('pkg_postrm_%s' % pkg, postrm)
+ bb.note("adding desktop-file-utils dependency to %s" % pkg)
+ d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils")
+}
diff --git a/scripts/postinst-intercepts/update_desktop_database b/scripts/postinst-intercepts/update_desktop_database
new file mode 100644
index 0000000000..8903b496f3
--- /dev/null
+++ b/scripts/postinst-intercepts/update_desktop_database
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# SPDX-License-Identifier: MIT
+#
+# Post-install intercept for mime-xdg.bbclass
+
+update-desktop-database $D${desktop_dir}
+
--
2.21.0
next prev parent reply other threads:[~2020-01-17 21:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-17 21:28 [PATCH][v2 00/10] Make MIME work on desktops Andreas Müller
2020-01-17 21:28 ` [PATCH][v2 01/10] itstool: add from meta-oe Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 02/10] itstool: extend to nativesdk Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 03/10] shared-mime-info: upgrade 1.10 -> 1.15 Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 04/10] mime.bbclass: rework Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 05/10] insane.bbclass: introduce a warning for mime missing in inherit Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 06/10] shared-mime-info: add mime to inherit Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 07/10] gcr: " Andreas Müller
2020-01-17 21:29 ` Andreas Müller [this message]
2020-01-17 21:29 ` [PATCH][v2 09/10] insane.bbclass: Spawn warning for missing mime-xdg in inherit Andreas Müller
2020-01-17 21:29 ` [PATCH][v2 10/10] gcr: add mime-xdg to inherit Andreas Müller
2020-01-17 21:32 ` ✗ patchtest: failure for Make MIME work on desktops (rev2) Patchwork
2020-01-18 8:40 ` [PATCH][v2 00/10] Make MIME work on desktops Richard Purdie
2020-01-18 11:08 ` Andreas Müller
2020-01-18 11:13 ` Richard Purdie
2020-01-18 17:49 ` Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200117212908.32647-9-schnitzeltony@gmail.com \
--to=schnitzeltony@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox