Apport Hooks
From openSUSE
[edit]
What are Apport Hooks
You can extend the reports generated by Apport through writing general or package specific hooks.
[edit]
Examples
[edit]
A General Hook
This is a general hook. You can place it under /usr/share/apport/general-hook and it will be executed every time one of the Apport UI is processing a report for sending it to the crash database server.
'''Apport general hook for collection additional data about RPM package.
Author: Jan Blunck <jblunck@suse.de>'''
import os.path, subprocess, rpm, binascii
skip_rpmtags = (
'DIRINDEXES',
'DIRNAMES',
'BASENAMES',
'FILELANGS',
'FILEINODES',
'FILEDEVICES',
'CHANGELOGTIME',
'CHANGELOGNAME',
'CHANGELOGTEXT',
'FILESIZES',
'FILESTATES',
'FILEMODES',
'FILERDEVS',
'FILEMTIMES',
'FILEMD5S',
'FILELINKTOS',
'FILEFLAGS',
'FILEUSERNAME',
'FILEGROUPNAME',
'FILEVERIFYFLAGS',
)
def add_info(report):
if report['Package']:
package_version = '-'.join(report['Package'].split()[0:1])
tn = rpm.tagnames
ts = rpm.ts()
mi = ts.dbMatch("name", package_version)
for hdr in mi:
for key in hdr.keys():
if tn[key] not in skip_rpmtags:
data = ' '.join(["%s" % hdr[key]])
try:
data.decode('ascii')
except UnicodeDecodeError:
report['PackageRpmTag_' + tn[key]] = "base64 %s" % binascii.b2a_base64(data)
else:
report['PackageRpmTag_' + tn[key]] = data
cmd = 'rpm -q --qf %{VENDOR} ' + package_version
rpmstring = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
arch = rpmstring.communicate()[0].strip()
report['PackageVendor'] = arch
cmd = 'rpm -q --qf %{DISTRIBUTION} ' + package_version
rpmstring = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
arch = rpmstring.communicate()[0].strip()
report['PackageDistribution'] = arch
cmd = 'rpm -q --qf %{SIGGPG} ' + package_version
rpmstring = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
arch = rpmstring.communicate()[0].strip()
report['PackageKeyIdShort'] = arch[27:34]
report['PackageKeyIdRPM'] = arch[18:34]
if __name__ == '__main__':
report = {}
report['Package'] = 'coreutils 6.12-29.10 [modified: %s]'
add_info(report)
for key in report:
print '%s: %s' % (key, report[key].split('\n', 1)[0])
Passed QA check: Fsundermeyer 14:53, 15 June 2009 (UTC)

