summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2011-06-01 12:39:55 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2011-06-01 12:39:55 +0200
commitf4e4a76f3ca70f0bad636e324c43d3da993df854 (patch)
tree57bb95b352cd12cc3a35a57fe5db6d201815bfc6 /src
parent82c53df6074a4db8f2c5cb4e6b665c2e0881eb28 (diff)
downloadabrt-f4e4a76f3ca70f0bad636e324c43d3da993df854.tar.gz
abrt-f4e4a76f3ca70f0bad636e324c43d3da993df854.tar.xz
abrt-f4e4a76f3ca70f0bad636e324c43d3da993df854.zip
py-libreport: added compatibility with python-meh
- which means it should be usable to report bugs from Anaconda
Diffstat (limited to 'src')
-rw-r--r--src/report-python/__init__.py239
-rw-r--r--src/report-python/libreport-meh-test.py31
-rw-r--r--src/report-python/problem_data.c10
-rw-r--r--src/report-python/py_report_test.py7
4 files changed, 176 insertions, 111 deletions
diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py
index 78beff6d..9efd5257 100644
--- a/src/report-python/__init__.py
+++ b/src/report-python/__init__.py
@@ -5,119 +5,136 @@ from _pyreport import *
import os
-def createAlertSignature(component, hashmarkername, hashvalue, summary, alertSignature):
+SYSTEM_RELEASE_PATHS = ["/etc/system-release","/etc/redhat-release"]
+####SYSTEM_RELEASE_DEPS = ["system-release", "redhat-release"]
+
+_hardcoded_default_product = ""
+_hardcoded_default_version = ""
+
+####def getProduct_fromPRODUCT():
+#### try:
+#### import product
+#### return product.productName
+#### except:
+#### return ""
+
+####def getVersion_fromPRODUCT():
+#### try:
+#### import product
+#### return product.productVersion
+#### except:
+#### return ""
+
+####def getProduct_fromRPM():
+#### try:
+#### import rpm
+#### ts = rpm.TransactionSet()
+#### for each_dep in SYSTEM_RELEASE_DEPS:
+#### mi = ts.dbMatch('provides', each_dep)
+#### for h in mi:
+#### if h['name']:
+#### return h['name'].split("-")[0].capitalize()
+####
+#### return ""
+#### except:
+#### return ""
+
+####def getVersion_fromRPM():
+#### try:
+#### import rpm
+#### ts = rpm.TransactionSet()
+#### for each_dep in SYSTEM_RELEASE_DEPS:
+#### mi = ts.dbMatch('provides', each_dep)
+#### for h in mi:
+#### if h['version']:
+#### return str(h['version'])
+#### return ""
+#### except:
+#### return ""
+
+def getProduct_fromFILE():
+ for each_path in SYSTEM_RELEASE_PATHS:
+ try:
+ file = open(each_path, "r")
+ content = file.read()
+ if content.startswith("Red Hat Enterprise Linux"):
+ return "Red Hat Enterprise Linux"
+ if content.startswith("Fedora"):
+ return "Fedora"
+ i = content.find(" release")
+ if i > -1:
+ return content[0:i]
+ except:
+ pass
+ return ""
+
+def getVersion_fromFILE():
+ for each_path in SYSTEM_RELEASE_PATHS:
+ try:
+ file = open(each_path, "r")
+ content = file.read()
+ if content.find("Rawhide") > -1:
+ return "rawhide"
+ clist = content.split(" ")
+ i = clist.index("release")
+ return clist[i+1]
+ except:
+ pass
+ return ""
+
+def getProduct():
+ ####product = getProduct_fromPRODUCT()
+ ####if product:
+ #### return product
+ product = getProduct_fromFILE()
+ if product:
+ return product
+ ####product = getProduct_fromRPM()
+ ####if product:
+ #### return product
+ return _hardcoded_default_product
+
+def getVersion():
+ ####version = getVersion_fromPRODUCT()
+ ####if version:
+ #### return version
+ version = getVersion_fromFILE()
+ if version:
+ return version
+ ####version = getVersion_fromRPM()
+ ####if version:
+ #### return version
+ return _hardcoded_default_version
- SYSTEM_RELEASE_PATHS = ["/etc/system-release","/etc/redhat-release"]
- ####SYSTEM_RELEASE_DEPS = ["system-release", "redhat-release"]
-
- _hardcoded_default_product = ""
- _hardcoded_default_version = ""
-
- ####def getProduct_fromPRODUCT():
- #### try:
- #### import product
- #### return product.productName
- #### except:
- #### return ""
-
- ####def getVersion_fromPRODUCT():
- #### try:
- #### import product
- #### return product.productVersion
- #### except:
- #### return ""
-
- ####def getProduct_fromRPM():
- #### try:
- #### import rpm
- #### ts = rpm.TransactionSet()
- #### for each_dep in SYSTEM_RELEASE_DEPS:
- #### mi = ts.dbMatch('provides', each_dep)
- #### for h in mi:
- #### if h['name']:
- #### return h['name'].split("-")[0].capitalize()
- ####
- #### return ""
- #### except:
- #### return ""
-
- ####def getVersion_fromRPM():
- #### try:
- #### import rpm
- #### ts = rpm.TransactionSet()
- #### for each_dep in SYSTEM_RELEASE_DEPS:
- #### mi = ts.dbMatch('provides', each_dep)
- #### for h in mi:
- #### if h['version']:
- #### return str(h['version'])
- #### return ""
- #### except:
- #### return ""
-
- def getProduct_fromFILE():
- for each_path in SYSTEM_RELEASE_PATHS:
- try:
- file = open(each_path, "r")
- content = file.read()
- if content.startswith("Red Hat Enterprise Linux"):
- return "Red Hat Enterprise Linux"
- if content.startswith("Fedora"):
- return "Fedora"
- i = content.find(" release")
- if i > -1:
- return content[0:i]
- except:
- pass
- return ""
-
- def getVersion_fromFILE():
- for each_path in SYSTEM_RELEASE_PATHS:
- try:
- file = open(each_path, "r")
- content = file.read()
- if content.find("Rawhide") > -1:
- return "rawhide"
- clist = content.split(" ")
- i = clist.index("release")
- return clist[i+1]
- except:
- pass
- return ""
-
- def getProduct():
- ####product = getProduct_fromPRODUCT()
- ####if product:
- #### return product
- product = getProduct_fromFILE()
- if product:
- return product
- ####product = getProduct_fromRPM()
- ####if product:
- #### return product
- return _hardcoded_default_product
-
- def getVersion():
- ####version = getVersion_fromPRODUCT()
- ####if version:
- #### return version
- version = getVersion_fromFILE()
- if version:
- return version
- ####version = getVersion_fromRPM()
- ####if version:
- #### return version
- return _hardcoded_default_version
-
- cd = problem_data()
- cd.add("component", component)
- cd.add("hashmarkername", hashmarkername)
+def createAlertSignature(component, hashmarkername, hashvalue, summary, alertSignature):
+ pd = problem_data()
+ pd.add("component", component)
+ pd.add("hashmarkername", hashmarkername)
+ pd.add("duphash", hashvalue)
+ pd.add("reason", summary)
+ pd.add("description", alertSignature)
+ pd.add_basics()
+
+ return pd
+
+# used in anaconda / python-meh
+def createPythonUnhandledExceptionSignature(component, hashmarkername, hashvalue, summary, description, exnFileName):
+ pd = problem_data()
+ pd.add("component", component)
+ pd.add("hashmarkername", hashmarkername)
#cd.add("localhash", hashvalue)
- cd.add("duphash", hashvalue)
- cd.add("reason", summary)
- cd.add("description", alertSignature)
- cd.add("product", getProduct())
- cd.add("version", getVersion())
- return cd
+ pd.add("duphash", hashvalue)
+ pd.add("reason", summary)
+ pd.add("description", description)
+ #pd.add("product", getProduct())
+ #pd.add("version", getVersion())
+ pd.add_basics() # adds product and version + some other required field
+ # FIXME: how to handle files out of dump dir??
+ #1 = flag BIN
+ pd.add("pythonUnhandledException", exnFileName, 1)
+
+ return pd
+
"""
def report(cd, io_unused):
state = run_event_state()
diff --git a/src/report-python/libreport-meh-test.py b/src/report-python/libreport-meh-test.py
new file mode 100644
index 00000000..4ef24834
--- /dev/null
+++ b/src/report-python/libreport-meh-test.py
@@ -0,0 +1,31 @@
+#!/bin/env python
+
+from meh.dump import ReverseExceptionDump
+from meh.handler import *
+from meh.ui.gui import *
+
+class Config:
+ def __init__(self):
+ self.programName = "abrt"
+ self.programVersion = "2.0"
+ self.attrSkipList = []
+ self.fileList = []
+ self.config_value_one = 1
+ self.config_value_two = 2
+
+
+
+#meh.makeRHHandler("crash-test-meh", "1.0", Config())
+config = Config()
+intf = GraphicalIntf(None)
+handler = ExceptionHandler(config, intf, ReverseExceptionDump)
+handler.install(None)
+
+
+print "handler set up, about to divide by zero"
+
+zero = 0
+print 1 / zero
+
+print "should have crashed"
+
diff --git a/src/report-python/problem_data.c b/src/report-python/problem_data.c
index ac80362a..9067dead 100644
--- a/src/report-python/problem_data.c
+++ b/src/report-python/problem_data.c
@@ -112,6 +112,15 @@ static PyObject *p_create_dump_dir_from_problem_data(PyObject *pself, PyObject *
return (PyObject*)new_dd;
}
+static PyObject *p_add_basics_to_problem_data(PyObject *pself, PyObject *always_null)
+{
+ p_problem_data *self = (p_problem_data*)pself;
+ add_basics_to_problem_data(self->cd);
+
+ Py_RETURN_NONE;
+}
+
+
//static PyMemberDef p_problem_data_members[] = {
// { NULL }
//};
@@ -121,6 +130,7 @@ static PyMethodDef p_problem_data_methods[] = {
{ "add" , p_problem_data_add , METH_VARARGS },
{ "get" , p_get_problem_data_item , METH_VARARGS },
{ "create_dump_dir", p_create_dump_dir_from_problem_data, METH_VARARGS },
+ { "add_basics", p_add_basics_to_problem_data, METH_NOARGS },
{ NULL }
};
diff --git a/src/report-python/py_report_test.py b/src/report-python/py_report_test.py
new file mode 100644
index 00000000..e15044f8
--- /dev/null
+++ b/src/report-python/py_report_test.py
@@ -0,0 +1,7 @@
+import _pyreport
+
+pd = _pyreport.problem_data()
+pd.add("foo", "bar")
+pd.add("description", "python-libreport test bug")
+
+_pyreport.report(pd)