ia64/xen-unstable
changeset 6846:f92bdd9153f5
Add store function.
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 | Wed Sep 14 19:22:31 2005 +0000 (2005-09-14) |
parents | d5497a215660 |
children | 960d4f6b58b3 |
files | tools/python/xen/xend/xenstore/xstransact.py |
line diff
1.1 --- a/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 14 19:17:22 2005 +0000 1.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py Wed Sep 14 19:22:31 2005 +0000 1.3 @@ -121,6 +121,20 @@ class xstransact: 1.4 return ret[0] 1.5 return ret 1.6 1.7 + def store(self, *args): 1.8 + for tup in args: 1.9 + if len(tup) == 2: 1.10 + (key, val) = tup 1.11 + try: 1.12 + fmt = { str : "%s", 1.13 + int : "%i", 1.14 + float : "%f" }[type(val)] 1.15 + except KeyError: 1.16 + raise TypeError 1.17 + else: 1.18 + (key, val, fmt) = tup 1.19 + self.write(key, fmt % val) 1.20 + 1.21 1.22 def Read(cls, path, *args): 1.23 while True: 1.24 @@ -216,3 +230,22 @@ class xstransact: 1.25 raise 1.26 1.27 Gather = classmethod(Gather) 1.28 + 1.29 + def Store(cls, path, *args): 1.30 + while True: 1.31 + try: 1.32 + t = cls(path) 1.33 + v = t.store(*args) 1.34 + t.commit() 1.35 + return v 1.36 + except RuntimeError, ex: 1.37 + t.abort() 1.38 + if ex.args[0] == errno.ETIMEDOUT: 1.39 + pass 1.40 + else: 1.41 + raise 1.42 + except: 1.43 + t.abort() 1.44 + raise 1.45 + 1.46 + Store = classmethod(Store)