[yum-cvs] output.py

Jeremy Katz katzj at linux.duke.edu
Thu Sep 13 19:46:36 UTC 2007


 output.py |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

New commits:
commit 57d8bb47b807ad1d1234d746a7715d40f5b48013
Author: Jeremy Katz <katzj at redhat.com>
Date:   Thu Sep 13 15:40:11 2007 -0400

    add support for fetching strings out of specspo (rh#251891)

diff --git a/output.py b/output.py
index 0f5eb5a..8aff587 100644
--- a/output.py
+++ b/output.py
@@ -21,6 +21,8 @@ import sys
 import time
 import logging
 import types
+import gettext
+import rpm
 from i18n import _
 
 from urlgrabber.progress import TextMeter
@@ -42,6 +44,10 @@ class YumOutput:
     def __init__(self):
         self.logger = logging.getLogger("yum.cli")
         self.verbose_logger = logging.getLogger("yum.verbose.cli")
+        if hasattr(rpm, "expandMacro"):
+            self.i18ndomains = rpm.expandMacro("%_i18ndomains").split(":")
+        else:
+            self.i18ndomains = ["redhat-dist"]
     
     def printtime(self):
         months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
@@ -71,11 +77,16 @@ class YumOutput:
         
     def infoOutput(self, pkg):
         def enc(s):
-            # this sucks.  what we get back from the rpmdb
-            # are strings, but they may actually have unicode so we
-            # can't encode them
+            """Get the translated version from specspo and ensure that
+            it's actually encoded in UTF-8."""
             if type(s) == unicode:
-                return s.encode("UTF-8")
+                s = s.encode("UTF-8")
+            if len(s) > 0:
+                for d in self.i18ndomains:
+                    t = gettext.dgettext(d, s)
+                    if t != s:
+                        s = t
+                        break
             return s
         print _("Name   : %s") % pkg.name
         print _("Arch   : %s") % pkg.arch
@@ -495,7 +506,7 @@ class YumCliRPMCallBack(RPMBaseCallback):
                 self.lastmsg = msg
             if te_current == te_total:
                 print " "
-        
+
     def _makefmt(self, percent, ts_current, ts_total, progress = True):
         l = len(str(ts_total))
         size = "%s.%s" % (l, l)



More information about the Yum-cvs-commits mailing list