Back to index

apport  2.3
generic.py
Go to the documentation of this file.
00001 '''Attach generally useful information, not specific to any package.'''
00002 
00003 # Copyright (C) 2009 Canonical Ltd.
00004 # Authors: Matt Zimmerman <mdz@canonical.com>
00005 #          Martin Pitt <martin.pitt@ubuntu.com>
00006 #          Brian Murray <brian@ubuntu.com>
00007 #
00008 # This program is free software; you can redistribute it and/or modify it
00009 # under the terms of the GNU General Public License as published by the
00010 # Free Software Foundation; either version 2 of the License, or (at your
00011 # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
00012 # the full text of the license.
00013 
00014 import os, re
00015 import apport.hookutils, apport.fileutils
00016 
00017 
00018 def add_info(report, ui):
00019     nm = apport.hookutils.nonfree_kernel_modules()
00020     if nm:
00021         report['NonfreeKernelModules'] = ' '.join(nm)
00022 
00023     # check for low space
00024     mounts = {'/': 'system',
00025               '/var': '/var',
00026               '/tmp': '/tmp'}
00027 
00028     home = os.getenv('HOME')
00029     if home:
00030         mounts[home] = 'home'
00031     treshold = 50
00032 
00033     for mount in mounts:
00034         st = os.statvfs(mount)
00035         free_mb = st.f_bavail * st.f_frsize / 1000000
00036 
00037         if free_mb < treshold:
00038             report['UnreportableReason'] = 'Your %s partition has less than \
00039 %s MB of free space available, which leads to problems using applications \
00040 and installing updates. Please free some space.' % (mounts[mount], free_mb)
00041 
00042     # important glib errors/assertions (which should not have private data)
00043     if 'ExecutablePath' in report:
00044         path = report['ExecutablePath']
00045         gtk_like = (apport.hookutils.links_with_shared_library(path, 'libgtk') or
00046                     apport.hookutils.links_with_shared_library(path, 'libgtk-3') or
00047                     apport.hookutils.links_with_shared_library(path, 'libX11'))
00048         if gtk_like and apport.hookutils.in_session_of_problem(report):
00049             xsession_errors = apport.hookutils.xsession_errors()
00050             if xsession_errors:
00051                 report['XsessionErrors'] = xsession_errors
00052 
00053     # using local libraries?
00054     if 'ProcMaps' in report:
00055         local_libs = set()
00056         for lib in re.finditer(r'\s(/[^ ]+\.so[.0-9]*)$', report['ProcMaps'], re.M):
00057             if not apport.fileutils.likely_packaged(lib.group(1)):
00058                 local_libs.add(lib.group(1))
00059         if local_libs:
00060             if not ui.yesno('''The crashed program seems to use third-party or local libraries:
00061 
00062 %s
00063 
00064 It is highly recommended to check if the problem persists without those first.
00065 
00066 Do you want to continue the report process anyway?
00067 ''' % '\n'.join(local_libs)):
00068                 raise StopIteration
00069             report['LocalLibraries'] = ' '.join(local_libs)
00070             report['Tags'] = (report.get('Tags', '') + ' local-libs').strip()
00071 
00072     # using third-party packages?
00073     if '[origin:' in report.get('Package', '') or '[origin:' in report.get('Dependencies', ''):
00074         report['Tags'] = (report.get('Tags', '') + ' third-party-packages').strip()
00075 
00076     # using ecryptfs?
00077     if os.path.exists(os.path.expanduser('~/.ecryptfs/wrapped-passphrase')):
00078         report['EcryptfsInUse'] = 'Yes'
00079 
00080     # filter out crashes on missing GLX (LP#327673)
00081     in_gl = '/usr/lib/libGL.so' in (report.get('StacktraceTop') or '\n').splitlines()[0]
00082     if in_gl and 'Loading extension GLX' not in apport.hookutils.read_file('/var/log/Xorg.0.log'):
00083         report['UnreportableReason'] = 'The X.org server does not support the GLX extension, which the crashed program expected to use.'
00084     # filter out package install failures due to a segfault
00085     if 'Segmentation fault' in report.get('ErrorMessage', '') \
00086             and report['ProblemType'] == 'Package':
00087         report['UnreportableReason'] = 'The package installation resulted in a segmentation fault which is better reported as a crash report rather than a package install failure.'
00088 
00089 
00090 if __name__ == '__main__':
00091     r = {}
00092     add_info(r, None)
00093     for k in r:
00094         print('%s: %s' % (k, r[k]))