Back to index

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

Classes

class  CrashDatabase
class  NeedsCredentials

Functions

def _u
def get_crashdb

Variables

 URLError = IOError

Detailed Description

Abstract crash database interface.

Function Documentation

def apport.crashdb._u (   str) [private]
Convert str to an unicode if it isn't already.

Definition at line 29 of file crashdb.py.

00029 
00030 def _u(str):
00031     '''Convert str to an unicode if it isn't already.'''
00032 
00033     if type(str) == type(b''):
00034         return str.decode('UTF-8', 'ignore')
00035     return str
00036 

Here is the caller graph for this function:

def apport.crashdb.get_crashdb (   auth_file,
  name = None,
  conf = None 
)
Return a CrashDatabase object for the given crash db name.

This reads the configuration file 'conf'.

If name is None, it defaults to the 'default' value in conf.

If conf is None, it defaults to the environment variable
APPORT_CRASHDB_CONF; if that does not exist, the hardcoded default is
/etc/apport/crashdb.conf. This Python syntax file needs to specify:

- A string variable 'default', giving a default value for 'name' if that is
  None.

- A dictionary 'databases' which maps names to crash db configuration
  dictionaries. These need to have at least the key 'impl' (Python module
  in apport.crashdb_impl which contains a concrete 'CrashDatabase' class
  implementation for that crash db type). Other generally known options are
  'bug_pattern_url', 'dupdb_url', and 'problem_types'.

Definition at line 799 of file crashdb.py.

00799 
00800 def get_crashdb(auth_file, name=None, conf=None):
00801     '''Return a CrashDatabase object for the given crash db name.
00802 
00803     This reads the configuration file 'conf'.
00804 
00805     If name is None, it defaults to the 'default' value in conf.
00806 
00807     If conf is None, it defaults to the environment variable
00808     APPORT_CRASHDB_CONF; if that does not exist, the hardcoded default is
00809     /etc/apport/crashdb.conf. This Python syntax file needs to specify:
00810 
00811     - A string variable 'default', giving a default value for 'name' if that is
00812       None.
00813 
00814     - A dictionary 'databases' which maps names to crash db configuration
00815       dictionaries. These need to have at least the key 'impl' (Python module
00816       in apport.crashdb_impl which contains a concrete 'CrashDatabase' class
00817       implementation for that crash db type). Other generally known options are
00818       'bug_pattern_url', 'dupdb_url', and 'problem_types'.
00819     '''
00820     if not conf:
00821         conf = os.environ.get('APPORT_CRASHDB_CONF', '/etc/apport/crashdb.conf')
00822     settings = {}
00823     with open(conf) as f:
00824         exec(compile(f.read(), conf, 'exec'), settings)
00825 
00826     # Load third parties crashdb.conf
00827     confdDir = conf + '.d'
00828     if os.path.isdir(confdDir):
00829         for cf in os.listdir(confdDir):
00830             cfpath = os.path.join(confdDir, cf)
00831             if os.path.isfile(cfpath) and cf.endswith('.conf'):
00832                 try:
00833                     with open(cfpath) as f:
00834                         exec(compile(f.read(), cfpath, 'exec'), settings['databases'])
00835                 except Exception as e:
00836                     # ignore broken files
00837                     sys.stderr.write('Invalid file %s: %s\n' % (cfpath, str(e)))
00838                     pass
00839 
00840     if not name:
00841         name = settings['default']
00842 
00843     db = settings['databases'][name]
00844 
00845     m = __import__('apport.crashdb_impl.' + db['impl'], globals(), locals(), ['CrashDatabase'])
00846     return m.CrashDatabase(auth_file, db)
00847 

Here is the caller graph for this function:


Variable Documentation

Definition at line 17 of file crashdb.py.