arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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