direct-io.hg
changeset 6711:1a27091a1e7a
Add remove and list support. Also make all class methods "safe".
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
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 + def _remove(self, key): 1.13 + path = "%s/%s" % (self.path, key) 1.14 + return xshandle().rm(path) 1.15 1.16 - Read = classmethod(Read) 1.17 + def remove(self, *args): 1.18 + if len(args) == 0: 1.19 + raise TypeError 1.20 + for key in args: 1.21 + self._remove(key) 1.22 1.23 - def Write(cls, path, *args, **opts): 1.24 - t = cls(path) 1.25 - t.write(*args, **opts) 1.26 - t.commit() 1.27 + def _list(self, key): 1.28 + path = "%s/%s" % (self.path, key) 1.29 + return map(lambda x: key + "/" + x, xshandle().ls(path)) 1.30 1.31 - Write = classmethod(Write) 1.32 + def list(self, *args): 1.33 + if len(args) == 0: 1.34 + raise TypeError 1.35 + ret = [] 1.36 + for key in args: 1.37 + ret.extend(self._list(key)) 1.38 + return ret 1.39 1.40 - def SafeRead(cls, path, *args): 1.41 + 1.42 + def Read(cls, path, *args): 1.43 while True: 1.44 try: 1.45 - return cls.Read(path, *args) 1.46 + t = cls(path) 1.47 + v = t.read(*args) 1.48 + t.commit() 1.49 + return v 1.50 except RuntimeError, ex: 1.51 if ex.args[0] == errno.ETIMEDOUT: 1.52 pass 1.53 raise 1.54 1.55 - SafeRead = classmethod(SafeRead) 1.56 + Read = classmethod(Read) 1.57 1.58 - def SafeWrite(cls, path, *args, **opts): 1.59 + def Write(cls, path, *args, **opts): 1.60 while True: 1.61 try: 1.62 - cls.Write(path, *args, **opts) 1.63 + t = cls(path) 1.64 + t.write(*args, **opts) 1.65 + t.commit() 1.66 return 1.67 except RuntimeError, ex: 1.68 if ex.args[0] == errno.ETIMEDOUT: 1.69 pass 1.70 raise 1.71 1.72 - SafeWrite = classmethod(SafeWrite) 1.73 + Write = classmethod(Write) 1.74 + 1.75 + def Remove(cls, *args): 1.76 + while True: 1.77 + try: 1.78 + t = cls(path) 1.79 + t.remove(*args) 1.80 + t.commit() 1.81 + return 1.82 + except RuntimeError, ex: 1.83 + if ex.args[0] == errno.ETIMEDOUT: 1.84 + pass 1.85 + raise 1.86 + 1.87 + Remove = classmethod(Remove) 1.88 + 1.89 + def List(cls, path, *args): 1.90 + while True: 1.91 + try: 1.92 + t = cls(path) 1.93 + v = t.list(*args) 1.94 + t.commit() 1.95 + return v 1.96 + except RuntimeError, ex: 1.97 + if ex.args[0] == errno.ETIMEDOUT: 1.98 + pass 1.99 + raise 1.100 + 1.101 + List = classmethod(List)