mime.bbclass: new class that detects if an package install a file in /usr/share/mime...
[openembedded.git] / classes / mime.bbclass
1 DEPENDS += "shared-mime-info-native shared-mime-info"
2
3 mime_postinst() {
4 if [ "$1" = configure ]; then
5         update-mime-database $D${datadir}/mime
6 fi
7 }
8
9 mime_prerm() {
10 if [ "$1" = remove ] || [ "$1" = upgrade ]; then
11     update-mime-database $D${datadir}/mime
12 fi
13 }
14
15 python populate_packages_append () {
16         import os.path, re
17         packages = bb.data.getVar('PACKAGES', d, 1).split()
18         workdir = bb.data.getVar('WORKDIR', d, 1)
19         
20         for pkg in packages:
21                 mime_dir = '%s/install/%s/usr/share/mime/packages' % (workdir, pkg)
22                 mimes = []
23                 mime_re = re.compile(".*\.xml$")
24                 if os.path.exists(mime_dir):
25                         for f in os.listdir(mime_dir):
26                                 if mime_re.match(f):
27                                         mimes.append(f)
28                 if mimes != []:
29                         bb.note("adding mime postinst and prerm scripts to %s" % pkg)
30                         postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
31                         if not postinst:
32                                 postinst = '#!/bin/sh\n'
33                         postinst += bb.data.getVar('mime_postinst', d, 1)
34                         bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
35                         prerm = bb.data.getVar('pkg_prerm_%s' % pkg, d, 1) or bb.data.getVar('pkg_prerm', d, 1)
36                         if not prerm:
37                                 prerm = '#!/bin/sh\n'
38                         prerm += bb.data.getVar('mime_prerm', d, 1)
39                         bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d)
40
41 }