Alon Bar-Lev has uploaded a new change for review.

Change subject: packagers: yum: do not use yum state strings
......................................................................

packagers: yum: do not use yum state strings

the yum.i18n produces non standard string encoding, encoded using ansi
codec but has unicode string, while the locale environment is set to
unicode, and python does enforce proper unicode in string.format().

the solution is to provide our own translation table for transaction
status, as no [simple] way was found to convert the non standard format
into unicode.

Change-Id: If230a17799263e705f194f180af04bf2904a5d90
Reported-By: Jakub Bittner <[email protected]>
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M ChangeLog
M src/otopi/miniyum.py
2 files changed, 27 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/26/17326/1

diff --git a/ChangeLog b/ChangeLog
index e43d036..aed7c5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
  * packagers: yum: do not enable if running non root.
  * packagers: yum: selinux: do not change type to rpm_t.
  * packagers: yum: rollback complex transaction successfully.
+ * packagers: yum: workaround non-standard encoding of yum.i18n.
  * java: do not fail to set null environment.
  * dialog: fix handling of empty string notes.
  * dialog: support tuples for note like list.
diff --git a/src/otopi/miniyum.py b/src/otopi/miniyum.py
index 86555c2..a7a5497 100755
--- a/src/otopi/miniyum.py
+++ b/src/otopi/miniyum.py
@@ -105,6 +105,18 @@
 class MiniYum(object):
     """Minimalist yum API interaction."""
 
+    TRANSACTION_STATE = {
+        yum.constants.TS_UPDATE: _('update'),
+        yum.constants.TS_INSTALL: _('install'),
+        yum.constants.TS_TRUEINSTALL: _('trueinstall'),
+        yum.constants.TS_ERASE: _('erase'),
+        yum.constants.TS_OBSOLETED: _('obsoleted'),
+        yum.constants.TS_OBSOLETING: _('obsoleting'),
+        yum.constants.TS_AVAILABLE: _('available'),
+        yum.constants.TS_UPDATED: _('updated'),
+        'repackaging': _('repackaging'),
+    }
+
     class _LogHandler(logging.Handler):
         """Required for extracting yum log output."""
 
@@ -176,12 +188,20 @@
             if self._lastaction != action or package != self._lastpackage:
                 self._lastaction = action
                 self._lastpackage = package
+
+                #
+                # NOTE:
+                # do not use self.action as it is encoded
+                # using invalid encoding, some unicode proprietary
+                # for yum.
+                # test using LC_ALL=cs_CZ.utf8, LANG=cs_CZ
+                #
                 self._sink.info(
                     _('{action}: {count}/{total}: {package}').format(
-                        action=self.action[action],
+                        action=MiniYum.TRANSACTION_STATE.get(action, action),
                         count=ts_current,
                         total=ts_total,
-                        package=package
+                        package=package.name,
                     )
                 )
 
@@ -811,19 +831,12 @@
         try:
             with self._disableOutput:
                 ret = []
-                state = {
-                    yum.constants.TS_UPDATE: "update",
-                    yum.constants.TS_INSTALL: "install",
-                    yum.constants.TS_TRUEINSTALL: "trueinstall",
-                    yum.constants.TS_ERASE: "erase",
-                    yum.constants.TS_OBSOLETED: "obsoleted",
-                    yum.constants.TS_OBSOLETING: "obsoleting",
-                    yum.constants.TS_AVAILABLE: "available",
-                    yum.constants.TS_UPDATED: "updated",
-                }
                 for txmbr in sorted(self._yb.tsInfo):
                     info = self._get_package_info(txmbr)
-                    info['operation'] = state[txmbr.output_state]
+                    info['operation'] = self.TRANSACTION_STATE.get(
+                        txmbr.output_state,
+                        txmbr.output_state
+                    )
                     ret.append(info)
                 return ret
 


-- 
To view, visit http://gerrit.ovirt.org/17326
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If230a17799263e705f194f180af04bf2904a5d90
Gerrit-PatchSet: 1
Gerrit-Project: otopi
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to