ia64/xen-unstable

changeset 13175:777bbae06fdb

Added I18N support for Xen-API error codes.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Sat Dec 23 11:24:10 2006 +0000 (2006-12-23)
parents e60644c61371
children 93ca2dcd681d
files tools/python/Makefile tools/python/xen/xm/XenAPI.py tools/python/xen/xm/main.py tools/python/xen/xm/messages/en/xen-xm.po
line diff
     1.1 --- a/tools/python/Makefile	Sat Dec 23 11:23:27 2006 +0000
     1.2 +++ b/tools/python/Makefile	Sat Dec 23 11:24:10 2006 +0000
     1.3 @@ -7,16 +7,26 @@ all: build
     1.4  .PHONY: build
     1.5  build:
     1.6  	CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
     1.7 +	for file in `cd xen/xm; find messages -name xen-xm.po`; do \
     1.8 +            dest=`echo "build/$$file" | \
     1.9 +                  sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \
    1.10 +            mkdir -p `dirname "$$dest"`; \
    1.11 +            msgfmt -c -o "$$dest" "xen/xm/$$file"; \
    1.12 +        done
    1.13  
    1.14  .PHONY: install
    1.15  ifndef XEN_PYTHON_NATIVE_INSTALL
    1.16 -install: all
    1.17 +install: install-messages
    1.18  	CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" --force
    1.19  else
    1.20 -install: all
    1.21 +install: install-messages
    1.22  	CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force
    1.23  endif
    1.24  
    1.25 +install-messages: all
    1.26 +	mkdir -p "$(DESTDIR)/usr/share/locale"
    1.27 +	cp -R build/messages/* "$(DESTDIR)/usr/share/locale/"
    1.28 +
    1.29  .PHONY: test
    1.30  test:
    1.31  	export LD_LIBRARY_PATH=$$(readlink -f ../libxc):$$(readlink -f ../xenstore); python test.py -b -u
     2.1 --- a/tools/python/xen/xm/XenAPI.py	Sat Dec 23 11:23:27 2006 +0000
     2.2 +++ b/tools/python/xen/xm/XenAPI.py	Sat Dec 23 11:24:10 2006 +0000
     2.3 @@ -44,17 +44,32 @@
     2.4  # OF THIS SOFTWARE.
     2.5  # --------------------------------------------------------------------
     2.6  
     2.7 +import gettext
     2.8  import xmlrpclib
     2.9  
    2.10  import xen.util.xmlrpclib2
    2.11  
    2.12  
    2.13 +gettext.install('xen-xm')
    2.14 +
    2.15  class Failure(Exception):
    2.16      def __init__(self, details):
    2.17          self.details = details
    2.18  
    2.19      def __str__(self):
    2.20 -        return "Xen-API failure: %s" % str(self.details)
    2.21 +        try:
    2.22 +            return _(self.details[0]) % self._details_map()
    2.23 +        except TypeError, exn:
    2.24 +            return "Message database broken: %s.\nXen-API failure: %s" % \
    2.25 +                   (exn, str(self.details))
    2.26 +        except Exception, exn:
    2.27 +            import sys
    2.28 +            print >>sys.stderr, exn
    2.29 +            return "Xen-API failure: %s" % str(self.details)
    2.30 +
    2.31 +    def _details_map(self):
    2.32 +        return dict([(str(i), self.details[i])
    2.33 +                     for i in range(len(self.details))])
    2.34  
    2.35  
    2.36  class Session(xen.util.xmlrpclib2.ServerProxy):
     3.1 --- a/tools/python/xen/xm/main.py	Sat Dec 23 11:23:27 2006 +0000
     3.2 +++ b/tools/python/xen/xm/main.py	Sat Dec 23 11:24:10 2006 +0000
     3.3 @@ -1780,7 +1780,7 @@ def _run_cmd(cmd, cmd_name, args):
     3.4      except SystemExit, code:
     3.5          return code == 0, code
     3.6      except XenAPI.Failure, exn:
     3.7 -        err(str(exn))
     3.8 +        print >>sys.stderr, str(exn)
     3.9      except xmlrpclib.Fault, ex:
    3.10          if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
    3.11              err("Domain '%s' does not exist." % ex.faultString)
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po	Sat Dec 23 11:24:10 2006 +0000
     4.3 @@ -0,0 +1,67 @@
     4.4 +# ============================================================================
     4.5 +# This library is free software; you can redistribute it and/or
     4.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     4.7 +# License as published by the Free Software Foundation.
     4.8 +# 
     4.9 +# This library is distributed in the hope that it will be useful,
    4.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.12 +# Lesser General Public License for more details.
    4.13 +#
    4.14 +# You should have received a copy of the GNU Lesser General Public
    4.15 +# License along with this library; if not, write to the Free Software
    4.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.17 +# ============================================================================
    4.18 +# Copyright (c) 2006 XenSource Inc.
    4.19 +# ============================================================================
    4.20 +# 
    4.21 +#
    4.22 +msgid ""
    4.23 +msgstr ""
    4.24 +"Project-Id-Version: Xen-xm 3.0\n"
    4.25 +"PO-Revision-Date: 2006-12-23 11:04+0000\n"
    4.26 +"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
    4.27 +"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
    4.28 +"MIME-Version: 1.0\n"
    4.29 +"Content-Type: text/plain; charset=ASCII\n"
    4.30 +"Content-Transfer-Encoding: 8bit\n"
    4.31 +
    4.32 +msgid "INTERNAL_ERROR"
    4.33 +msgstr "Internal error: %(1)s."
    4.34 +
    4.35 +msgid "MAP_DUPLICATE_KEY"
    4.36 +msgstr "This map already contains %(1)s -> %(2)s."
    4.37 +
    4.38 +msgid "MESSAGE_METHOD_UNKNOWN"
    4.39 +msgstr "The method %(1)s is unsupported."
    4.40 +
    4.41 +msgid "MESSAGE_PARAMETER_COUNT_MISMATCH"
    4.42 +msgstr "The method %(1)s takes %(2)s argument(s) (%(3)s given)."
    4.43 +
    4.44 +msgid "SESSION_AUTHENTICATION_FAILED"
    4.45 +msgstr "Permission denied."
    4.46 +
    4.47 +msgid "HOST_CPU_HANDLE_INVALID"
    4.48 +msgstr "The host_cpu handle %(1)s is invalid."
    4.49 +
    4.50 +msgid "HOST_HANDLE_INVALID"
    4.51 +msgstr "The host handle %(1)s is invalid."
    4.52 +
    4.53 +msgid "SR_HANDLE_INVALID"
    4.54 +msgstr "The SR handle %(1)s is invalid."
    4.55 +
    4.56 +msgid "VBD_HANDLE_INVALID"
    4.57 +msgstr "The VBD handle %(1)s is invalid."
    4.58 +
    4.59 +msgid "VDI_HANDLE_INVALID"
    4.60 +msgstr "The VDI handle %(1)s is invalid."
    4.61 +
    4.62 +msgid "VIF_HANDLE_INVALID"
    4.63 +msgstr "The VIF handle %(1)s is invalid."
    4.64 +
    4.65 +msgid "VM_HANDLE_INVALID"
    4.66 +msgstr "The VM handle %(1)s is invalid."
    4.67 +
    4.68 +msgid "VTPM_HANDLE_INVALID"
    4.69 +msgstr "The VTPM handle %(1)s is invalid."
    4.70 +