ia64/xen-unstable

changeset 6731:1a27091a1e7a

Add remove and list support. Also make all class methods "safe".
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Sep 09 17:34:40 2005 +0000 (2005-09-09)
parents 54af57682431
children 31c257b9a360
files tools/python/xen/xend/xenstore/xstransact.py
line diff
     1.1 --- a/tools/python/xen/xend/xenstore/xstransact.py	Fri Sep 09 17:03:34 2005 +0000
     1.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py	Fri Sep 09 17:34:40 2005 +0000
     1.3 @@ -88,40 +88,81 @@ class xstransact:
     1.4          else:
     1.5              raise TypeError
     1.6  
     1.7 -    def Read(cls, path, *args):
     1.8 -        t = cls(path)
     1.9 -        v = t.read(*args)
    1.10 -        t.commit()
    1.11 -        return v
    1.12 -
    1.13 -    Read = classmethod(Read)
    1.14 +    def _remove(self, key):
    1.15 +        path = "%s/%s" % (self.path, key)
    1.16 +        return xshandle().rm(path)
    1.17  
    1.18 -    def Write(cls, path, *args, **opts):
    1.19 -        t = cls(path)
    1.20 -        t.write(*args, **opts)
    1.21 -        t.commit()
    1.22 +    def remove(self, *args):
    1.23 +        if len(args) == 0:
    1.24 +            raise TypeError
    1.25 +        for key in args:
    1.26 +            self._remove(key)
    1.27  
    1.28 -    Write = classmethod(Write)
    1.29 +    def _list(self, key):
    1.30 +        path = "%s/%s" % (self.path, key)
    1.31 +        return map(lambda x: key + "/" + x, xshandle().ls(path))
    1.32  
    1.33 -    def SafeRead(cls, path, *args):
    1.34 +    def list(self, *args):
    1.35 +        if len(args) == 0:
    1.36 +            raise TypeError
    1.37 +        ret = []
    1.38 +        for key in args:
    1.39 +            ret.extend(self._list(key))
    1.40 +        return ret
    1.41 +
    1.42 +
    1.43 +    def Read(cls, path, *args):
    1.44          while True:
    1.45              try:
    1.46 -                return cls.Read(path, *args)
    1.47 +                t = cls(path)
    1.48 +                v = t.read(*args)
    1.49 +                t.commit()
    1.50 +                return v
    1.51              except RuntimeError, ex:
    1.52                  if ex.args[0] == errno.ETIMEDOUT:
    1.53                      pass
    1.54                  raise
    1.55  
    1.56 -    SafeRead = classmethod(SafeRead)
    1.57 +    Read = classmethod(Read)
    1.58  
    1.59 -    def SafeWrite(cls, path, *args, **opts):
    1.60 +    def Write(cls, path, *args, **opts):
    1.61          while True:
    1.62              try:
    1.63 -                cls.Write(path, *args, **opts)
    1.64 +                t = cls(path)
    1.65 +                t.write(*args, **opts)
    1.66 +                t.commit()
    1.67                  return
    1.68              except RuntimeError, ex:
    1.69                  if ex.args[0] == errno.ETIMEDOUT:
    1.70                      pass
    1.71                  raise
    1.72  
    1.73 -    SafeWrite = classmethod(SafeWrite)
    1.74 +    Write = classmethod(Write)
    1.75 +
    1.76 +    def Remove(cls, *args):
    1.77 +        while True:
    1.78 +            try:
    1.79 +                t = cls(path)
    1.80 +                t.remove(*args)
    1.81 +                t.commit()
    1.82 +                return
    1.83 +            except RuntimeError, ex:
    1.84 +                if ex.args[0] == errno.ETIMEDOUT:
    1.85 +                    pass
    1.86 +                raise
    1.87 +
    1.88 +    Remove = classmethod(Remove)
    1.89 +
    1.90 +    def List(cls, path, *args):
    1.91 +        while True:
    1.92 +            try:
    1.93 +                t = cls(path)
    1.94 +                v = t.list(*args)
    1.95 +                t.commit()
    1.96 +                return v
    1.97 +            except RuntimeError, ex:
    1.98 +                if ex.args[0] == errno.ETIMEDOUT:
    1.99 +                    pass
   1.100 +                raise
   1.101 +
   1.102 +    List = classmethod(List)