Back to index

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

Classes

class  Report

Functions

def _transitive_dependencies
def _read_file
def _read_maps
def _command_output
def _check_bug_pattern
def _check_bug_patterns
def _dom_remove_space

Variables

 _python2 = False
 URLError = IOError
tuple _data_dir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')
string _hook_dir = '%s/package-hooks/'
string _common_hook_dir = '%s/general-hooks/'
string _ignore_file = '~/.apport-ignore.xml'
string _blacklist_dir = '/etc/apport/blacklist.d'
string _whitelist_dir = '/etc/apport/whitelist.d'
list interpreters

Detailed Description

Representation of and data collection for a problem report.

Function Documentation

def apport.report._check_bug_pattern (   report,
  pattern 
) [private]
Check if given report matches the given bug pattern XML DOM node.

Return the bug URL on match, otherwise None.

Definition at line 113 of file report.py.

00113 
00114 def _check_bug_pattern(report, pattern):
00115     '''Check if given report matches the given bug pattern XML DOM node.
00116 
00117     Return the bug URL on match, otherwise None.
00118     '''
00119     if _python2:
00120         if not pattern.attributes.has_key('url'):
00121             return None
00122     else:
00123         if 'url' not in pattern.attributes:
00124             return None
00125 
00126     for c in pattern.childNodes:
00127         # regular expression condition
00128         if c.nodeType == xml.dom.Node.ELEMENT_NODE and c.nodeName == 're':
00129             try:
00130                 key = c.attributes['key'].nodeValue
00131             except KeyError:
00132                 continue
00133             if key not in report:
00134                 return None
00135             c.normalize()
00136             if c.hasChildNodes() and c.childNodes[0].nodeType == xml.dom.Node.TEXT_NODE:
00137                 regexp = c.childNodes[0].nodeValue
00138                 v = report[key]
00139                 if isinstance(v, problem_report.CompressedValue):
00140                     v = v.get_value()
00141                     regexp = regexp.encode('UTF-8')
00142                 try:
00143                     re_c = re.compile(regexp)
00144                 except:
00145                     continue
00146                 if not re_c.search(v):
00147                     return None
00148 
00149     return pattern.attributes['url'].nodeValue
00150 

Here is the caller graph for this function:

def apport.report._check_bug_patterns (   report,
  patterns 
) [private]

Definition at line 151 of file report.py.

00151 
00152 def _check_bug_patterns(report, patterns):
00153     try:
00154         dom = xml.dom.minidom.parseString(patterns)
00155     except (ExpatError, UnicodeEncodeError):
00156         return None
00157 
00158     for pattern in dom.getElementsByTagName('pattern'):
00159         url = _check_bug_pattern(report, pattern)
00160         if url:
00161             return url
00162 
00163     return None
00164 

Here is the call graph for this function:

Here is the caller graph for this function:

def apport.report._command_output (   command,
  input = None,
  stderr = subprocess.STDOUT 
) [private]
Run command and capture its output.

Try to execute given command (argv list) and return its stdout, or return
a textual error if it failed.

Definition at line 93 of file report.py.

00093 
00094 def _command_output(command, input=None, stderr=subprocess.STDOUT):
00095     '''Run command and capture its output.
00096 
00097     Try to execute given command (argv list) and return its stdout, or return
00098     a textual error if it failed.
00099     '''
00100     sp = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=stderr)
00101 
00102     (out, err) = sp.communicate(input)
00103     if sp.returncode == 0:
00104         return out
00105     else:
00106         if err:
00107             err = err.decode('UTF-8', errors='replace')
00108         else:
00109             err = ''
00110         raise OSError('Error: command %s failed with exit code %i: %s' % (
00111             str(command), sp.returncode, err))
00112 

Here is the caller graph for this function:

def apport.report._dom_remove_space (   node) [private]
Recursively remove whitespace from given XML DOM node.

Definition at line 165 of file report.py.

00165 
00166 def _dom_remove_space(node):
00167     '''Recursively remove whitespace from given XML DOM node.'''
00168 
00169     for c in node.childNodes:
00170         if c.nodeType == xml.dom.Node.TEXT_NODE and c.nodeValue.strip() == '':
00171             c.unlink()
00172             node.removeChild(c)
00173         else:
00174             _dom_remove_space(c)
00175 
00176 #
00177 # Report class
00178 #
00179 

Here is the caller graph for this function:

def apport.report._read_file (   path) [private]
Read file content.

Return its content, or return a textual error if it failed.

Definition at line 66 of file report.py.

00066 
00067 def _read_file(path):
00068     '''Read file content.
00069 
00070     Return its content, or return a textual error if it failed.
00071     '''
00072     try:
00073         with open(path) as fd:
00074             return fd.read().strip()
00075     except (OSError, IOError) as e:
00076         return 'Error: ' + str(e)
00077 

Here is the caller graph for this function:

def apport.report._read_maps (   pid) [private]
Read /proc/pid/maps.

Since /proc/$pid/maps may become unreadable unless we are ptracing the
process, detect this, and attempt to attach/detach.

Definition at line 78 of file report.py.

00078 
00079 def _read_maps(pid):
00080     '''Read /proc/pid/maps.
00081 
00082     Since /proc/$pid/maps may become unreadable unless we are ptracing the
00083     process, detect this, and attempt to attach/detach.
00084     '''
00085     maps = 'Error: unable to read /proc maps file'
00086     try:
00087         with open('/proc/%d/maps' % pid) as fd:
00088             maps = fd.read().strip()
00089     except (OSError, IOError) as e:
00090         return 'Error: ' + str(e)
00091     return maps
00092 

Here is the caller graph for this function:

def apport.report._transitive_dependencies (   package,
  depends_set 
) [private]
Recursively add dependencies of package to depends_set.

Definition at line 53 of file report.py.

00053 
00054 def _transitive_dependencies(package, depends_set):
00055     '''Recursively add dependencies of package to depends_set.'''
00056 
00057     try:
00058         packaging.get_version(package)
00059     except ValueError:
00060         return
00061     for d in packaging.get_dependencies(package):
00062         if not d in depends_set:
00063             depends_set.add(d)
00064             _transitive_dependencies(d, depends_set)
00065 

Here is the caller graph for this function:


Variable Documentation

string apport.report._blacklist_dir = '/etc/apport/blacklist.d'

Definition at line 41 of file report.py.

string apport.report._common_hook_dir = '%s/general-hooks/'

Definition at line 35 of file report.py.

tuple apport.report._data_dir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')

Definition at line 33 of file report.py.

string apport.report._hook_dir = '%s/package-hooks/'

Definition at line 34 of file report.py.

string apport.report._ignore_file = '~/.apport-ignore.xml'

Definition at line 38 of file report.py.

Definition at line 19 of file report.py.

string apport.report._whitelist_dir = '/etc/apport/whitelist.d'

Definition at line 42 of file report.py.

Initial value:
00001 ['sh', 'bash', 'dash', 'csh', 'tcsh', 'python*',
00002                 'ruby*', 'php', 'perl*', 'mono*', 'awk']

Definition at line 45 of file report.py.

Definition at line 26 of file report.py.