WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Added I18N support for Xen-API error code

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added I18N support for Xen-API error codes.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 23 Dec 2006 15:10:10 -0800
Delivery-date: Sat, 23 Dec 2006 15:11:04 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1166873050 0
# Node ID 777bbae06fdb1f78410c9b86a33d5ba340a75a4f
# Parent  e60644c61371a86658e35a2918a3c76b2f7b8a98
Added I18N support for Xen-API error codes.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/Makefile                     |   14 +++++-
 tools/python/xen/xm/XenAPI.py             |   17 +++++++
 tools/python/xen/xm/main.py               |    2 
 tools/python/xen/xm/messages/en/xen-xm.po |   67 ++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 4 deletions(-)

diff -r e60644c61371 -r 777bbae06fdb tools/python/Makefile
--- a/tools/python/Makefile     Sat Dec 23 11:23:27 2006 +0000
+++ b/tools/python/Makefile     Sat Dec 23 11:24:10 2006 +0000
@@ -7,15 +7,25 @@ all: build
 .PHONY: build
 build:
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
+       for file in `cd xen/xm; find messages -name xen-xm.po`; do \
+            dest=`echo "build/$$file" | \
+                  sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \
+            mkdir -p `dirname "$$dest"`; \
+            msgfmt -c -o "$$dest" "xen/xm/$$file"; \
+        done
 
 .PHONY: install
 ifndef XEN_PYTHON_NATIVE_INSTALL
-install: all
+install: install-messages
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install 
--home="$(DESTDIR)/usr" --prefix="" --force
 else
-install: all
+install: install-messages
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install 
--root="$(DESTDIR)" --force
 endif
+
+install-messages: all
+       mkdir -p "$(DESTDIR)/usr/share/locale"
+       cp -R build/messages/* "$(DESTDIR)/usr/share/locale/"
 
 .PHONY: test
 test:
diff -r e60644c61371 -r 777bbae06fdb tools/python/xen/xm/XenAPI.py
--- a/tools/python/xen/xm/XenAPI.py     Sat Dec 23 11:23:27 2006 +0000
+++ b/tools/python/xen/xm/XenAPI.py     Sat Dec 23 11:24:10 2006 +0000
@@ -44,17 +44,32 @@
 # OF THIS SOFTWARE.
 # --------------------------------------------------------------------
 
+import gettext
 import xmlrpclib
 
 import xen.util.xmlrpclib2
 
+
+gettext.install('xen-xm')
 
 class Failure(Exception):
     def __init__(self, details):
         self.details = details
 
     def __str__(self):
-        return "Xen-API failure: %s" % str(self.details)
+        try:
+            return _(self.details[0]) % self._details_map()
+        except TypeError, exn:
+            return "Message database broken: %s.\nXen-API failure: %s" % \
+                   (exn, str(self.details))
+        except Exception, exn:
+            import sys
+            print >>sys.stderr, exn
+            return "Xen-API failure: %s" % str(self.details)
+
+    def _details_map(self):
+        return dict([(str(i), self.details[i])
+                     for i in range(len(self.details))])
 
 
 class Session(xen.util.xmlrpclib2.ServerProxy):
diff -r e60644c61371 -r 777bbae06fdb tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Sat Dec 23 11:23:27 2006 +0000
+++ b/tools/python/xen/xm/main.py       Sat Dec 23 11:24:10 2006 +0000
@@ -1780,7 +1780,7 @@ def _run_cmd(cmd, cmd_name, args):
     except SystemExit, code:
         return code == 0, code
     except XenAPI.Failure, exn:
-        err(str(exn))
+        print >>sys.stderr, str(exn)
     except xmlrpclib.Fault, ex:
         if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
             err("Domain '%s' does not exist." % ex.faultString)
diff -r e60644c61371 -r 777bbae06fdb tools/python/xen/xm/messages/en/xen-xm.po
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/python/xen/xm/messages/en/xen-xm.po Sat Dec 23 11:24:10 2006 +0000
@@ -0,0 +1,67 @@
+# ============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# ============================================================================
+# Copyright (c) 2006 XenSource Inc.
+# ============================================================================
+# 
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Xen-xm 3.0\n"
+"PO-Revision-Date: 2006-12-23 11:04+0000\n"
+"Last-Translator: Ewan Mellor <ewan@xxxxxxxxxxxxx>\n"
+"Language-Team: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ASCII\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "INTERNAL_ERROR"
+msgstr "Internal error: %(1)s."
+
+msgid "MAP_DUPLICATE_KEY"
+msgstr "This map already contains %(1)s -> %(2)s."
+
+msgid "MESSAGE_METHOD_UNKNOWN"
+msgstr "The method %(1)s is unsupported."
+
+msgid "MESSAGE_PARAMETER_COUNT_MISMATCH"
+msgstr "The method %(1)s takes %(2)s argument(s) (%(3)s given)."
+
+msgid "SESSION_AUTHENTICATION_FAILED"
+msgstr "Permission denied."
+
+msgid "HOST_CPU_HANDLE_INVALID"
+msgstr "The host_cpu handle %(1)s is invalid."
+
+msgid "HOST_HANDLE_INVALID"
+msgstr "The host handle %(1)s is invalid."
+
+msgid "SR_HANDLE_INVALID"
+msgstr "The SR handle %(1)s is invalid."
+
+msgid "VBD_HANDLE_INVALID"
+msgstr "The VBD handle %(1)s is invalid."
+
+msgid "VDI_HANDLE_INVALID"
+msgstr "The VDI handle %(1)s is invalid."
+
+msgid "VIF_HANDLE_INVALID"
+msgstr "The VIF handle %(1)s is invalid."
+
+msgid "VM_HANDLE_INVALID"
+msgstr "The VM handle %(1)s is invalid."
+
+msgid "VTPM_HANDLE_INVALID"
+msgstr "The VTPM handle %(1)s is invalid."
+

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Added I18N support for Xen-API error codes., Xen patchbot-unstable <=