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

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