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