doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone
Blob Blame History Raw
From 715a047ada1ca9f9420e194306c5b0fe01b5c9f1 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Thu, 9 Oct 2014 10:24:42 +0200
Subject: [ABRT PATCH 68/68] ureport: attach contact email if configured

Resolves #1150389

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 src/plugins/abrt-action-ureport | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/plugins/abrt-action-ureport b/src/plugins/abrt-action-ureport
index e38a92c..48bebef 100755
--- a/src/plugins/abrt-action-ureport
+++ b/src/plugins/abrt-action-ureport
@@ -8,6 +8,7 @@
 import sys
 import os
 import getopt
+import augeas
 
 from report import dd_opendir, DD_FAIL_QUIETLY_ENOENT
 from reportclient import set_verbosity, error_msg_and_die, error_msg, log1, log
@@ -32,12 +33,31 @@ def init_gettext():
     gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
     gettext.textdomain(GETTEXT_PROGNAME)
 
-def spawn_and_wait(prog):
+
+def get_augeas(module, file_path):
+    """
+    A function for efficient configuration of Augeas.
+    Augeas modules are placed in /usr/share/augeas/lenses/dist
+    """
+
+    aug_obj = augeas.Augeas(flags=augeas.Augeas.NO_MODL_AUTOLOAD)
+    aug_obj.set("/augeas/load/{0}/lens".format(module), "{0}.lns".format(module))
+    aug_obj.set("/augeas/load/{0}/incl".format(module), file_path)
+    aug_obj.load()
+    return aug_obj
+
+
+def spawn_and_wait(prog, args=None):
+    if args is None:
+        args = [prog]
+    else:
+        args.insert(0, prog)
+
     try:
-        return os.spawnlp(os.P_WAIT, prog, prog)
+         return os.spawnvpe(os.P_WAIT, prog, args, os.environ)
     except OSError as err:
         error_msg(_("Unable to start '%s', error message was: '%s'"),
-                    prog, err)
+                    " ".join(args), err)
         return -1
 
 def try_parse_number(dd, filename):
@@ -78,6 +98,7 @@ if __name__ == "__main__":
             verbose += 1
 
     set_verbosity(verbose)
+    os.environ["ABRT_VERBOSE"] = str(verbose)
 
     # getcwd might fail if cwd was deleted
     try:
@@ -140,6 +161,16 @@ if __name__ == "__main__":
             sys.exit(1)
         dd.save_text("ureports_counter", str(ureports_counter + 1))
         dd.close()
+
+        email = os.getenv("uReport_ContactEmail")
+        if not email:
+            augeas = get_augeas("libreport", "/etc/libreport/plugins/ureport.conf")
+            email = augeas.get("/files/etc/libreport/plugins/ureport.conf/ContactEmail")
+
+        if email:
+            log1("Attaching ContactEmail: " + email)
+            spawn_and_wait("reporter-ureport", ["-A", "-E"])
+
         sys.exit(exitcode)
     else:
         error_msg_and_die(_("reporter-ureport failed with exit code %d" % exitcode))
-- 
1.8.3.1