import os
import inspect
import datetime
from problem import proxies, exception, tools, watch
from _pyabrt import *
JAVA = 'java'
SELINUX = 'selinux'
CCPP = 'CCpp'
PYTHON = 'Python'
KERNELOOPS = 'Kerneloops'
RUNTIME = 'runtime'
XORG = 'xorg'
UNKNOWN = 'libreport'
REQUIRED_FIELDS = ['executable']
PROBLEM_TYPES = {
'JAVA': JAVA,
'SELINUX': SELINUX,
'CCPP': CCPP,
'PYTHON': PYTHON,
'KERNELOOPS': KERNELOOPS,
'RUNTIME': RUNTIME,
'XORG': XORG,
'UNKNOWN': UNKNOWN,
}
class Problem(object):
'''
Base class for the other problem types.
No need to use this class directly, use one
of the specific problem classes.
'''
def __init__(self, typ, reason):
self._data = dict()
self._dirty_data = dict()
self._persisted = False
self._proxy = None
self._probdir = None
self.type = typ
self.analyzer = typ
self.reason = reason
self._proxy = proxies.get_proxy()
def __cast(self, attr, val, reverse=False):
# str with digits -> int
if not reverse and type(val) == str and val.isdigit():
val = int(val)
# by attr name
mapping = {
'time': (datetime.datetime.fromtimestamp,
lambda x: x.strftime('%s'))
}
if attr in mapping:
fun, revfun = mapping[attr]
if reverse:
fun = revfun
val = fun(val)
if reverse:
return str(val)
return val
def __getattr__(self, attr):
exc = AttributeError("object has no attribute '{0}'".format(attr))
val = None
# was deleted before?
if attr in self._dirty_data and self._dirty_data[attr] is None:
raise exc
if attr in self._data:
val = self._data[attr]
# try to fetch the item
if self._persisted:
val = self._proxy.get_item(self._probdir, attr)
self._data[attr] = val
if val is None:
raise exc
val = self.__cast(attr, val)
super(Problem, self).__setattr__(attr, val)
return val
def __setattr__(self, attr, value):
super(Problem, self).__setattr__(attr, value)
if not attr[0] == '_':
self._data[attr] = value
if self._persisted:
self._dirty_data[attr] = value
def __delattr__(self, attr):
# it might not be loaded at first
self.__getattr__(attr)
super(Problem, self).__delattr__(attr)
del self._data[attr]
if self._persisted:
self._dirty_data[attr] = None
def __getitem__(self, attr):
try:
return self.__getattr__(attr)
except AttributeError as e:
raise KeyError(e)
def __setitem__(self, attr, value):
self.__setattr__(attr, value)
def __delitem__(self, attr):
try:
self.__delattr__(attr)
except AttributeError as e:
raise KeyError(e)
def __repr__(self):
return '