mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Add gather function and robustify class methods' failure handling.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
1 parent
6d496fed5e
commit
967d7a84e5
1 file changed
+52
@@ -106,6 +106,23 @@ class xstransact:
|
||||
ret.extend(self._list(key))
|
||||
return ret
|
||||
|
||||
def gather(self, *args):
|
||||
ret = []
|
||||
for tup in args:
|
||||
if len(tup) == 2:
|
||||
(key, fn) = tup
|
||||
defval = None
|
||||
else:
|
||||
(key, fn, defval) = tup
|
||||
try:
|
||||
val = fn(self.read(key))
|
||||
except TypeError:
|
||||
val = defval
|
||||
ret.append(val)
|
||||
if len(ret) == 1:
|
||||
return ret[0]
|
||||
return ret
|
||||
|
||||
|
||||
def Read(cls, path, *args):
|
||||
while True:
|
||||
@@ -115,10 +132,14 @@ class xstransact:
|
||||
t.commit()
|
||||
return v
|
||||
except RuntimeError, ex:
|
||||
t.abort()
|
||||
if ex.args[0] == errno.ETIMEDOUT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
Read = classmethod(Read)
|
||||
|
||||
@@ -130,10 +151,14 @@ class xstransact:
|
||||
t.commit()
|
||||
return
|
||||
except RuntimeError, ex:
|
||||
t.abort()
|
||||
if ex.args[0] == errno.ETIMEDOUT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
Write = classmethod(Write)
|
||||
|
||||
@@ -145,10 +170,14 @@ class xstransact:
|
||||
t.commit()
|
||||
return
|
||||
except RuntimeError, ex:
|
||||
t.abort()
|
||||
if ex.args[0] == errno.ETIMEDOUT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
Remove = classmethod(Remove)
|
||||
|
||||
@@ -160,9 +189,32 @@ class xstransact:
|
||||
t.commit()
|
||||
return v
|
||||
except RuntimeError, ex:
|
||||
t.abort()
|
||||
if ex.args[0] == errno.ETIMEDOUT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
List = classmethod(List)
|
||||
|
||||
def Gather(cls, path, *args):
|
||||
while True:
|
||||
try:
|
||||
t = cls(path)
|
||||
v = t.gather(*args)
|
||||
t.commit()
|
||||
return v
|
||||
except RuntimeError, ex:
|
||||
t.abort()
|
||||
if ex.args[0] == errno.ETIMEDOUT:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
Gather = classmethod(Gather)
|
||||