[Yum-devel] [PATCH] Move exception2msg() from utils.py to i18n.py
Zdeněk Pavlas
zpavlas at redhat.com
Wed Aug 10 07:59:03 UTC 2011
---
utils.py | 30 +-----------------------------
yum/i18n.py | 28 ++++++++++++++++++++++++++++
yummain.py | 4 ++--
3 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/utils.py b/utils.py
index 90b6fd4..99533a6 100755
--- a/utils.py
+++ b/utils.py
@@ -23,7 +23,7 @@ import yum
from cli import *
from yum import Errors
from yum import _
-from yum.i18n import utf8_width
+from yum.i18n import utf8_width, exception2msg
from yum import logginglevels
from optparse import OptionGroup
@@ -163,34 +163,6 @@ def show_lock_owner(pid, logger):
return ps
-def exception2msg(e):
- """Convert an exception to a message. This function will convert
- the exception using to_unicode, unicode, or str, whichever works correctly.
-
- :param e: an exception
- :return: a string representation of the exception
- """
-
- # DIE python DIE! Which one works:
- # to_unicode(e.value); unicode(e); str(e);
- # Call this so you don't have to care.
- try:
- return to_unicode(e.value)
- except:
- pass
-
- try:
- return unicode(e)
- except:
- pass
-
- try:
- return str(e)
- except:
- pass
- return "<exception failed to convert to text>"
-
-
class YumUtilBase(YumBaseCli):
"""A class to extend the yum cli for utilities."""
diff --git a/yum/i18n.py b/yum/i18n.py
index 9889bf6..85ad15e 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -462,6 +462,34 @@ def str_eq(a, b):
return False
+def exception2msg(e):
+ """Convert an exception to a message. This function will convert
+ the exception using to_unicode, unicode, or str, whichever works correctly.
+
+ :param e: an exception
+ :return: a string representation of the exception
+ """
+
+ # DIE python DIE! Which one works:
+ # to_unicode(e.value); unicode(e); str(e);
+ # Call this so you don't have to care.
+ try:
+ return to_unicode(e.value)
+ except:
+ pass
+
+ try:
+ return unicode(e)
+ except:
+ pass
+
+ try:
+ return str(e)
+ except:
+ pass
+ return "<exception failed to convert to text>"
+
+
try:
'''
Setup the yum translation domain and make _() and P_() translation wrappers
diff --git a/yummain.py b/yummain.py
index d7ba288..4b1112a 100755
--- a/yummain.py
+++ b/yummain.py
@@ -29,10 +29,10 @@ from yum import Errors
from yum import plugins
from yum import logginglevels
from yum import _
-from yum.i18n import to_unicode, utf8_width
+from yum.i18n import to_unicode, utf8_width, exception2msg
import yum.misc
import cli
-from utils import suppress_keyboard_interrupt_message, show_lock_owner, exception2msg
+from utils import suppress_keyboard_interrupt_message, show_lock_owner
def main(args):
"""Run the yum program from a command line interface."""
--
1.7.4.4
More information about the Yum-devel
mailing list