Blame SOURCES/0213-reportclient-honor-ABRT_VERBOSE.patch

3bb9bc
From 128490bb35079d77c0fa04f2e254bd6a0acc382a Mon Sep 17 00:00:00 2001
3bb9bc
From: Jakub Filak <jfilak@redhat.com>
3bb9bc
Date: Thu, 24 Nov 2016 07:54:21 +0100
3bb9bc
Subject: [PATCH] reportclient: honor ABRT_VERBOSE
3bb9bc
3bb9bc
libreport's verbosity can be configured via ABRT_VERBOSE environment
3bb9bc
variable and reportclient must be aware of that.
3bb9bc
3bb9bc
Related to #1257159
3bb9bc
3bb9bc
Signed-off-by: Jakub Filak <jfilak@redhat.com>
3bb9bc
---
3bb9bc
 src/client-python/__init__.py |  9 ++++++++
3bb9bc
 tests/Makefile.am             |  1 +
3bb9bc
 tests/client_python.at        | 53 +++++++++++++++++++++++++++++++++++++++++++
3bb9bc
 tests/testsuite.at            |  1 +
3bb9bc
 4 files changed, 64 insertions(+)
3bb9bc
 create mode 100644 tests/client_python.at
3bb9bc
3bb9bc
diff --git a/src/client-python/__init__.py b/src/client-python/__init__.py
3bb9bc
index 8966f22..f10f710 100644
3bb9bc
--- a/src/client-python/__init__.py
3bb9bc
+++ b/src/client-python/__init__.py
3bb9bc
@@ -31,6 +31,7 @@ from report import EXIT_STOP_EVENT_RUN as RETURN_STOP_EVENT_RUN
3bb9bc
 
3bb9bc
 
3bb9bc
 GETTEXT_PROGNAME = "libreport"
3bb9bc
+import os
3bb9bc
 import locale
3bb9bc
 import gettext
3bb9bc
 
3bb9bc
@@ -52,10 +53,18 @@ def init_gettext():
3bb9bc
 init_gettext()
3bb9bc
 
3bb9bc
 verbose = 0
3bb9bc
+ABRT_VERBOSE = os.getenv("ABRT_VERBOSE")
3bb9bc
+if ABRT_VERBOSE:
3bb9bc
+    try:
3bb9bc
+        verbose = int(ABRT_VERBOSE)
3bb9bc
+    except:
3bb9bc
+        pass
3bb9bc
+
3bb9bc
 
3bb9bc
 def set_verbosity(verbosity):
3bb9bc
     global verbose
3bb9bc
     verbose = verbosity
3bb9bc
+    os.environ["ABRT_VERBOSE"] = str(verbose)
3bb9bc
 
3bb9bc
 def log(fmt, *args):
3bb9bc
     sys.stderr.write("%s\n" % (fmt % args))
3bb9bc
diff --git a/tests/Makefile.am b/tests/Makefile.am
3bb9bc
index b45f2d9..52dfce4 100644
3bb9bc
--- a/tests/Makefile.am
3bb9bc
+++ b/tests/Makefile.am
3bb9bc
@@ -40,6 +40,7 @@ TESTSUITE_AT = \
3bb9bc
   libreport_types.at \
3bb9bc
   xml_definition.at \
3bb9bc
   report_python.at \
3bb9bc
+  client_python.at \
3bb9bc
   xfuncs.at \
3bb9bc
   string_list.at \
3bb9bc
   ureport.at \
3bb9bc
diff --git a/tests/client_python.at b/tests/client_python.at
3bb9bc
new file mode 100644
3bb9bc
index 0000000..656b1b2
3bb9bc
--- /dev/null
3bb9bc
+++ b/tests/client_python.at
3bb9bc
@@ -0,0 +1,53 @@
3bb9bc
+# -*- Autotest -*-
3bb9bc
+
3bb9bc
+AT_BANNER([client_python])
3bb9bc
+
3bb9bc
+## --------- ##
3bb9bc
+## verbosity ##
3bb9bc
+## --------- ##
3bb9bc
+
3bb9bc
+AT_PYTESTFUN([verbosity], [[
3bb9bc
+import sys
3bb9bc
+import os
3bb9bc
+import unittest
3bb9bc
+
3bb9bc
+sys.path.insert(0, "../../../src/client-python")
3bb9bc
+sys.path.insert(0, "../../../src/client-python/.libs")
3bb9bc
+
3bb9bc
+
3bb9bc
+class TestReportClientVerbose(unittest.TestCase):
3bb9bc
+    def setUp(self):
3bb9bc
+        try:
3bb9bc
+            del os.environ["ABRT_VERBOSE"]
3bb9bc
+        except:
3bb9bc
+            pass
3bb9bc
+        os.unsetenv("ABRT_VERBOSE")
3bb9bc
+        self.clientpython = __import__("client-python", globals(), locals(), [], -1)
3bb9bc
+        reload(self.clientpython)
3bb9bc
+        sys.modules["clientpython"] = self.clientpython
3bb9bc
+
3bb9bc
+    def tearDown(self):
3bb9bc
+        del sys.modules["clientpython"]
3bb9bc
+
3bb9bc
+    def test_default(self):
3bb9bc
+        self.assertEquals(self.clientpython.verbose, 0)
3bb9bc
+
3bb9bc
+    def test_assign(self):
3bb9bc
+        self.clientpython.set_verbosity(1)
3bb9bc
+        self.assertEquals(self.clientpython.verbose, 1)
3bb9bc
+        self.assertEquals(os.environ["ABRT_VERBOSE"], "1")
3bb9bc
+
3bb9bc
+    def test_load_from_environ(self):
3bb9bc
+        os.environ["ABRT_VERBOSE"] = "2"
3bb9bc
+        reload(self.clientpython)
3bb9bc
+        self.assertEquals(self.clientpython.verbose, 2)
3bb9bc
+
3bb9bc
+    def test_recover_from_invalid_environ(self):
3bb9bc
+        os.environ["ABRT_VERBOSE"] = "foo"
3bb9bc
+        reload(self.clientpython)
3bb9bc
+        self.assertEquals(self.clientpython.verbose, 0)
3bb9bc
+
3bb9bc
+
3bb9bc
+if __name__ == "__main__":
3bb9bc
+    unittest.main()
3bb9bc
+]])
3bb9bc
diff --git a/tests/testsuite.at b/tests/testsuite.at
3bb9bc
index ccb37d1..8ded735 100644
3bb9bc
--- a/tests/testsuite.at
3bb9bc
+++ b/tests/testsuite.at
3bb9bc
@@ -15,6 +15,7 @@ m4_include([make_description.at])
3bb9bc
 m4_include([libreport_types.at])
3bb9bc
 m4_include([xml_definition.at])
3bb9bc
 m4_include([report_python.at])
3bb9bc
+m4_include([client_python.at])
3bb9bc
 m4_include([string_list.at])
3bb9bc
 m4_include([ureport.at])
3bb9bc
 m4_include([problem_report.at])
3bb9bc
-- 
3bb9bc
1.8.3.1
3bb9bc