Back to index

apport  2.4
Classes | Functions | Variables
apport.ui Namespace Reference

Classes

class  UserInterface
class  HookUI

Functions

def excstr
def thread_collect_info

Variables

string __version__ = '2.4'
tuple symptom_script_dir
int PF_KTHREAD = 0x200000

Detailed Description

Abstract Apport user interface.

This encapsulates the workflow and common code for any user interface
implementation (like GTK, Qt, or CLI).

Function Documentation

def apport.ui.excstr (   exception)
Return exception message as unicode.

Definition at line 36 of file ui.py.

00036 
00037 def excstr(exception):
00038     '''Return exception message as unicode.'''
00039 
00040     if sys.version_info.major == 2:
00041         return str(exception).decode(locale.getpreferredencoding(), 'replace')
00042     return str(exception)

Here is the caller graph for this function:

def apport.ui.thread_collect_info (   report,
  reportfile,
  package,
  ui,
  symptom_script = None,
  ignore_uninstalled = False 
)
Collect information about report.

Encapsulate calls to add_*_info() and update given report, so that this
function is suitable for threading.

ui must be a HookUI instance, it gets passed to add_hooks_info().

If reportfile is not None, the file is written back with the new data.

If symptom_script is given, it will be run first (for run_symptom()).

Definition at line 49 of file ui.py.

00049 
00050                         ignore_uninstalled=False):
00051     '''Collect information about report.
00052 
00053     Encapsulate calls to add_*_info() and update given report, so that this
00054     function is suitable for threading.
00055 
00056     ui must be a HookUI instance, it gets passed to add_hooks_info().
00057 
00058     If reportfile is not None, the file is written back with the new data.
00059 
00060     If symptom_script is given, it will be run first (for run_symptom()).
00061     '''
00062     report.add_gdb_info()
00063     report.add_os_info()
00064 
00065     if symptom_script:
00066         symb = {}
00067         try:
00068             with open(symptom_script) as f:
00069                 exec(compile(f.read(), symptom_script, 'exec'), symb)
00070             package = symb['run'](report, ui)
00071             if not package:
00072                 apport.error('symptom script %s did not determine the affected package', symptom_script)
00073                 return
00074             report['Symptom'] = os.path.splitext(os.path.basename(symptom_script))[0]
00075         except StopIteration:
00076             sys.exit(0)
00077         except:
00078             apport.error('symptom script %s crashed:', symptom_script)
00079             traceback.print_exc()
00080             sys.exit(0)
00081 
00082     if not package:
00083         if 'ExecutablePath' in report:
00084             package = apport.fileutils.find_file_package(report['ExecutablePath'])
00085         else:
00086             raise KeyError('called without a package, and report does not have ExecutablePath')
00087     try:
00088         report.add_package_info(package)
00089     except ValueError:
00090         # this happens if we are collecting information on an uninstalled
00091         # package
00092         if not ignore_uninstalled:
00093             raise
00094     except SystemError as e:
00095         report['UnreportableReason'] = excstr(e)
00096         return
00097 
00098     if report.add_hooks_info(ui):
00099         sys.exit(0)
00100 
00101     # check package origin; we do that after adding hooks, so that hooks have
00102     # the chance to set a third-party CrashDB.
00103     try:
00104         if 'CrashDB' not in report and 'APPORT_DISABLE_DISTRO_CHECK' not in os.environ:
00105             if 'Package' not in report:
00106                 report['UnreportableReason'] = _('This package does not seem to be installed correctly')
00107             elif not apport.packaging.is_distro_package(report['Package'].split()[0]):
00108                 #TRANS: %s is the name of the operating system
00109                 report['UnreportableReason'] = _(
00110                     'This is not an official %s package. Please remove any third party package and try again.') % report['DistroRelease'].split()[0]
00111     except ValueError:
00112         # this happens if we are collecting information on an uninstalled
00113         # package
00114         if not ignore_uninstalled:
00115             raise
00116 
00117     # add title
00118     if 'Title' not in report:
00119         title = report.standard_title()
00120         if title:
00121             report['Title'] = title
00122 
00123     # check obsolete packages
00124     if report['ProblemType'] == 'Crash' and 'APPORT_IGNORE_OBSOLETE_PACKAGES' not in os.environ:
00125         old_pkgs = report.obsolete_packages()
00126         if old_pkgs:
00127             report['UnreportableReason'] = _('You have some obsolete package \
00128 versions installed. Please upgrade the following packages and check if the \
00129 problem still occurs:\n\n%s') % ', '.join(old_pkgs)
00130 
00131     # disabled: if we have a SIGABRT without an assertion message, declare as unreportable
00132     #if report.get('Signal') == '6' and 'AssertionMessage' not in report:
00133     #    report['UnreportableReason'] = _('The program crashed on an assertion failure, but the message could not be retrieved. Apport does not support reporting these crashes.')
00134 
00135     if reportfile:
00136         try:
00137             with open(reportfile, 'ab') as f:
00138                 os.chmod(reportfile, 0)
00139                 report.write(f, only_new=True)
00140         except IOError as e:
00141             # this should happen very rarely; presumably a new crash report is
00142             # being generated by a background apport instance (which will set
00143             # the file to permissions zero while writing), while the first
00144             # report is being processed
00145             apport.error('Cannot update %s: %s' % (reportfile, e))
00146 
00147         apport.fileutils.mark_report_seen(reportfile)
00148         os.chmod(reportfile, 0o640)
00149 

Here is the call graph for this function:


Variable Documentation

string apport.ui.__version__ = '2.4'

Definition at line 16 of file ui.py.

int apport.ui.PF_KTHREAD = 0x200000

Definition at line 45 of file ui.py.

Initial value:
00001 os.environ.get('APPORT_SYMPTOMS_DIR',
00002                                     '/usr/share/apport/symptoms')

Definition at line 43 of file ui.py.