Blame SOURCES/0053-gettext-fix-the-initialization-in-python-scripts.patch

06486d
From c647c9eaecde2653366decd9a992e75943db7fc0 Mon Sep 17 00:00:00 2001
06486d
From: Jakub Filak <jfilak@redhat.com>
06486d
Date: Tue, 22 Jul 2014 16:13:25 +0200
06486d
Subject: [ABRT PATCH 53/66] gettext: fix the initialization in python scripts
06486d
06486d
ABRT scripts cannot import and use _ symbol from reportclient because
06486d
reporclient's _ is bound to 'libreport' package.
06486d
06486d
Related to rhbz#1087880
06486d
06486d
Signed-off-by: Jakub Filak <jfilak@redhat.com>
06486d
06486d
Conflicts:
06486d
	src/plugins/abrt-action-ureport
06486d
---
06486d
 po/POTFILES.in                               |  2 ++
06486d
 src/daemon/abrt-handle-upload.in             | 26 ++++++++++++++++++++++++--
06486d
 src/plugins/abrt-action-analyze-vmcore.in    | 25 ++++++++++++++++++++++++-
06486d
 src/plugins/abrt-action-install-debuginfo.in |  2 +-
06486d
 src/plugins/abrt-action-ureport              | 24 ++++++++++++++++++++++--
06486d
 5 files changed, 73 insertions(+), 6 deletions(-)
06486d
06486d
diff --git a/po/POTFILES.in b/po/POTFILES.in
06486d
index ff9b97a..e3f917b 100644
06486d
--- a/po/POTFILES.in
06486d
+++ b/po/POTFILES.in
06486d
@@ -14,6 +14,7 @@ src/daemon/abrtd.c
06486d
 src/daemon/abrt-handle-event.c
06486d
 src/daemon/abrt-upload-watch.c
06486d
 src/daemon/abrt-auto-reporting.c
06486d
+src/daemon/abrt-handle-upload.in
06486d
 src/lib/abrt_conf.c
06486d
 src/lib/hooklib.c
06486d
 src/lib/problem_api.c
06486d
@@ -32,6 +33,7 @@ src/plugins/abrt-action-generate-core-backtrace.c
06486d
 src/plugins/abrt-action-install-debuginfo.in
06486d
 src/plugins/abrt-action-perform-ccpp-analysis.in
06486d
 src/plugins/abrt-action-trim-files.c
06486d
+src/plugins/abrt-action-ureport
06486d
 src/plugins/abrt-gdb-exploitable
06486d
 src/plugins/abrt-watch-log.c
06486d
 src/plugins/abrt-dump-oops.c
06486d
diff --git a/src/daemon/abrt-handle-upload.in b/src/daemon/abrt-handle-upload.in
06486d
index 084170e..dbc4534 100755
06486d
--- a/src/daemon/abrt-handle-upload.in
06486d
+++ b/src/daemon/abrt-handle-upload.in
06486d
@@ -11,7 +11,29 @@ import tempfile
06486d
 import shutil
06486d
 import datetime
06486d
 
06486d
-from reportclient import _, set_verbosity, error_msg_and_die, error_msg, log
06486d
+from reportclient import set_verbosity, error_msg_and_die, error_msg, log
06486d
+
06486d
+GETTEXT_PROGNAME = "abrt"
06486d
+import locale
06486d
+import gettext
06486d
+
06486d
+_ = lambda x: gettext.lgettext(x)
06486d
+
06486d
+def init_gettext():
06486d
+    try:
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    except locale.Error:
06486d
+        os.environ['LC_ALL'] = 'C'
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    # Defeat "AttributeError: 'module' object has no attribute 'nl_langinfo'"
06486d
+    try:
06486d
+        gettext.bind_textdomain_codeset(GETTEXT_PROGNAME, locale.nl_langinfo(locale.CODESET))
06486d
+    except AttributeError:
06486d
+        pass
06486d
+    gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
06486d
+    gettext.textdomain(GETTEXT_PROGNAME)
06486d
+
06486d
+
06486d
 import problem
06486d
 
06486d
 def write_str_to(filename, s):
06486d
@@ -32,7 +54,7 @@ if __name__ == "__main__":
06486d
         sys.exit(die_exitcode)
06486d
 
06486d
     # localization
06486d
-    #init_gettext() - done by reportclient module init
06486d
+    init_gettext()
06486d
 
06486d
     verbose = 0
06486d
     ABRT_VERBOSE = os.getenv("ABRT_VERBOSE")
06486d
diff --git a/src/plugins/abrt-action-analyze-vmcore.in b/src/plugins/abrt-action-analyze-vmcore.in
06486d
index 11ad846..c08af80 100644
06486d
--- a/src/plugins/abrt-action-analyze-vmcore.in
06486d
+++ b/src/plugins/abrt-action-analyze-vmcore.in
06486d
@@ -8,7 +8,28 @@ import sys
06486d
 import getopt
06486d
 from subprocess import Popen, PIPE
06486d
 
06486d
-from reportclient import _, verbose, set_verbosity, error_msg_and_die, error_msg
06486d
+from reportclient import verbose, set_verbosity, error_msg_and_die, error_msg
06486d
+
06486d
+GETTEXT_PROGNAME = "abrt"
06486d
+import locale
06486d
+import gettext
06486d
+
06486d
+_ = lambda x: gettext.lgettext(x)
06486d
+
06486d
+def init_gettext():
06486d
+    try:
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    except locale.Error:
06486d
+        os.environ['LC_ALL'] = 'C'
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    # Defeat "AttributeError: 'module' object has no attribute 'nl_langinfo'"
06486d
+    try:
06486d
+        gettext.bind_textdomain_codeset(GETTEXT_PROGNAME, locale.nl_langinfo(locale.CODESET))
06486d
+    except AttributeError:
06486d
+        pass
06486d
+    gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
06486d
+    gettext.textdomain(GETTEXT_PROGNAME)
06486d
+
06486d
 
06486d
 PROGNAME = "abrt-action-analyze-vmcore"
06486d
 
06486d
@@ -26,6 +47,8 @@ if __name__ == "__main__":
06486d
     tmpdir = ""
06486d
     vmcore = ""
06486d
 
06486d
+    init_gettext()
06486d
+
06486d
     help_text = _("Usage: {0} [-v[v]] [--core=VMCORE]").format(PROGNAME)
06486d
     try:
06486d
         opts, args = getopt.getopt(sys.argv[1:], "hvd", ["help", "core="])
06486d
diff --git a/src/plugins/abrt-action-install-debuginfo.in b/src/plugins/abrt-action-install-debuginfo.in
06486d
index 5fd3110..f46d1b2 100644
06486d
--- a/src/plugins/abrt-action-install-debuginfo.in
06486d
+++ b/src/plugins/abrt-action-install-debuginfo.in
06486d
@@ -11,7 +11,7 @@ import errno
06486d
 import getopt
06486d
 import reportclient
06486d
 from subprocess import Popen, PIPE
06486d
-from reportclient import _, verbose, log, log1, log2, set_verbosity, error_msg_and_die, error_msg
06486d
+from reportclient import verbose, log, log1, log2, set_verbosity, error_msg_and_die, error_msg
06486d
 import time
06486d
 from reportclient.debuginfo import DebugInfoDownload, filter_installed_debuginfos, build_ids_to_path, clean_up
06486d
 import problem
06486d
diff --git a/src/plugins/abrt-action-ureport b/src/plugins/abrt-action-ureport
06486d
index 8c0f36f..e38a92c 100755
06486d
--- a/src/plugins/abrt-action-ureport
06486d
+++ b/src/plugins/abrt-action-ureport
06486d
@@ -10,7 +10,27 @@ import os
06486d
 import getopt
06486d
 
06486d
 from report import dd_opendir, DD_FAIL_QUIETLY_ENOENT
06486d
-from reportclient import _, set_verbosity, error_msg_and_die, error_msg, log1, log
06486d
+from reportclient import set_verbosity, error_msg_and_die, error_msg, log1, log
06486d
+
06486d
+GETTEXT_PROGNAME = "abrt"
06486d
+import locale
06486d
+import gettext
06486d
+
06486d
+_ = lambda x: gettext.lgettext(x)
06486d
+
06486d
+def init_gettext():
06486d
+    try:
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    except locale.Error:
06486d
+        os.environ['LC_ALL'] = 'C'
06486d
+        locale.setlocale(locale.LC_ALL, "")
06486d
+    # Defeat "AttributeError: 'module' object has no attribute 'nl_langinfo'"
06486d
+    try:
06486d
+        gettext.bind_textdomain_codeset(GETTEXT_PROGNAME, locale.nl_langinfo(locale.CODESET))
06486d
+    except AttributeError:
06486d
+        pass
06486d
+    gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
06486d
+    gettext.textdomain(GETTEXT_PROGNAME)
06486d
 
06486d
 def spawn_and_wait(prog):
06486d
     try:
06486d
@@ -32,7 +52,7 @@ def try_parse_number(dd, filename):
06486d
 
06486d
 if __name__ == "__main__":
06486d
     # localization
06486d
-    #init_gettext() - done by reportclient module init
06486d
+    init_gettext()
06486d
 
06486d
     verbose = 0
06486d
     ABRT_VERBOSE = os.getenv("ABRT_VERBOSE")
06486d
-- 
06486d
1.8.3.1
06486d