From c96bab437f21aea116bfe5608bb43c9cd26fb904 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 21 Dec 2010 19:25:05 +0100 Subject: src/report-python: add report package compatibility Signed-off-by: Denys Vlasenko --- src/report-python/Makefile.am | 14 ++- src/report-python/__init__.py | 128 ++++++++++++++++++++++++++ src/report-python/accountmanager.py | 6 ++ src/report-python/io/GTKIO.py | 11 +++ src/report-python/io/NewtIO.py | 7 ++ src/report-python/io/TextIO.py | 6 ++ src/report-python/io/__init__.py | 1 + src/report-python/test_setroubleshoot_example | 18 ++++ 8 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/report-python/accountmanager.py create mode 100644 src/report-python/io/GTKIO.py create mode 100644 src/report-python/io/NewtIO.py create mode 100644 src/report-python/io/TextIO.py create mode 100644 src/report-python/io/__init__.py create mode 100755 src/report-python/test_setroubleshoot_example diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am index 1c4d55ec..c92bbaa6 100644 --- a/src/report-python/Makefile.am +++ b/src/report-python/Makefile.am @@ -1,6 +1,8 @@ pyreportexecdir = $(pyexecdir)/report -pyreportexec_PYTHON = __init__.py +pyreportexec_PYTHON = \ + __init__.py \ + accountmanager.py pyreportexec_LTLIBRARIES = _pyreport.la @@ -28,3 +30,13 @@ _pyreport_la_LDFLAGS = \ -export-symbols-regex init_pyreport _pyreport_la_LIBADD = \ ../lib/libreport.la + +# report compat: + +pyreportioexecdir = $(pyexecdir)/report/io + +pyreportioexec_PYTHON = \ + io/__init__.py \ + io/GTKIO.py \ + io/NewtIO.py \ + io/TextIO.py diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py index 90109551..892d7c2a 100644 --- a/src/report-python/__init__.py +++ b/src/report-python/__init__.py @@ -1 +1,129 @@ from _pyreport import * + + +#Compatibility with report package: + +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 + + cd = crash_data() + cd.add("component", component) + cd.add("hashmarkername", hashmarkername) + cd.add("localhash", hashvalue) + cd.add("summary", summary) + cd.add("description", alertSignature) + cd.add("product", getProduct()) + cd.add("version", getVersion()) + return cd + +def report(cd, io_unused): + dd = cd.create_dump_dir() + dir_name = dd.name + dd.close() + #r = os.spawnlp(P_WAIT, "abrt-handle-crashdump", "abrt-handle-crashdump", "-d", dirname, "-e" , "report"); + state = run_event_state() + #state.logging_callback = logfunc + r = state.run_event(dir_name, "report") + return r diff --git a/src/report-python/accountmanager.py b/src/report-python/accountmanager.py new file mode 100644 index 00000000..db8ed117 --- /dev/null +++ b/src/report-python/accountmanager.py @@ -0,0 +1,6 @@ +""" + Compatibility with report package +""" + +class AccountManager: + pass diff --git a/src/report-python/io/GTKIO.py b/src/report-python/io/GTKIO.py new file mode 100644 index 00000000..4cc8766e --- /dev/null +++ b/src/report-python/io/GTKIO.py @@ -0,0 +1,11 @@ +""" + Compatibility with report package +""" + +class GTKIO: + def __init__(self, loginManager = None): + pass + +#class FailDialog(): +# def __init__(self, title, message): +# pass diff --git a/src/report-python/io/NewtIO.py b/src/report-python/io/NewtIO.py new file mode 100644 index 00000000..10eae284 --- /dev/null +++ b/src/report-python/io/NewtIO.py @@ -0,0 +1,7 @@ +""" + Compatibility with report package +""" + +class NewtIO: + def __init__(self, screen = None): + pass diff --git a/src/report-python/io/TextIO.py b/src/report-python/io/TextIO.py new file mode 100644 index 00000000..6162fb8b --- /dev/null +++ b/src/report-python/io/TextIO.py @@ -0,0 +1,6 @@ +""" + Compatibility with report package +""" + +class TextIO: + pass diff --git a/src/report-python/io/__init__.py b/src/report-python/io/__init__.py new file mode 100644 index 00000000..2ae28399 --- /dev/null +++ b/src/report-python/io/__init__.py @@ -0,0 +1 @@ +pass diff --git a/src/report-python/test_setroubleshoot_example b/src/report-python/test_setroubleshoot_example new file mode 100755 index 00000000..74428f16 --- /dev/null +++ b/src/report-python/test_setroubleshoot_example @@ -0,0 +1,18 @@ +#!/usr/bin/python + +import report +import report.io +import report.io.GTKIO +import report.accountmanager + +accounts = report.accountmanager.AccountManager() + +signature = report.createAlertSignature("selinux-policy", + "setroubleshoot", + "self.siginfo.get_hash()", + "self.summary", + "content") + +rc = report.report(signature, report.io.GTKIO.GTKIO(accounts)) + +print "rc:", rc -- cgit