ia64/xen-unstable

changeset 7001:79f695037ab7

Added diagnostic messages to the RuntimeError exceptions when they occur inside
_read and _write. Fix gather to not return the string 'None' when reading a
value of type string that does not exist. The value None should be returned
instead.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Wed Sep 21 11:29:23 2005 +0100 (2005-09-21)
parents ba10ee566ab7
children 2eee9f6487ff
files tools/python/xen/xend/xenstore/xstransact.py
line diff
     1.1 --- a/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 21 11:26:31 2005 +0100
     1.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 21 11:29:23 2005 +0100
     1.3 @@ -41,7 +41,11 @@ class xstransact:
     1.4  
     1.5      def _read(self, key):
     1.6          path = "%s/%s" % (self.path, key)
     1.7 -        return xshandle().read(path)
     1.8 +        try:
     1.9 +            return xshandle().read(path)
    1.10 +        except RuntimeError, ex:
    1.11 +            raise RuntimeError(ex.args[0],
    1.12 +                               '%s, while reading %s' % (ex.args[1], path))
    1.13  
    1.14      def read(self, *args):
    1.15          if len(args) == 0:
    1.16 @@ -55,7 +59,12 @@ class xstransact:
    1.17  
    1.18      def _write(self, key, data):
    1.19          path = "%s/%s" % (self.path, key)
    1.20 -        xshandle().write(path, data)
    1.21 +        try:
    1.22 +            xshandle().write(path, data)
    1.23 +        except RuntimeError, ex:
    1.24 +            raise RuntimeError(ex.args[0],
    1.25 +                               ('%s, while writing %s : %s' %
    1.26 +                                (ex.args[1], path, str(data))))
    1.27  
    1.28      def write(self, *args, **opts):
    1.29          if len(args) == 0:
    1.30 @@ -121,10 +130,20 @@ class xstransact:
    1.31                  defval = None
    1.32              else:
    1.33                  (key, fn, defval) = tup
    1.34 -            try:
    1.35 -                val = fn(self._read(key))
    1.36 -            except TypeError:
    1.37 +
    1.38 +            val = self._read(key)
    1.39 +            # If fn is str, then this will successfully convert None to
    1.40 +            # 'None'.  If it is int, then it will throw TypeError on None, or
    1.41 +            # on any other non-integer value.  We have to, therefore, both
    1.42 +            # check explicitly for None, and catch TypeError.  Either failure
    1.43 +            # will result in defval being used instead.
    1.44 +            if val is None:
    1.45                  val = defval
    1.46 +            else:
    1.47 +                try:
    1.48 +                    val = fn(val)
    1.49 +                except TypeError:
    1.50 +                    val = defval
    1.51              ret.append(val)
    1.52          if len(ret) == 1:
    1.53              return ret[0]