doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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