ia64/xen-unstable
changeset 7081:7c5d9879967d
Added behaviour to list() to list the transaction's path if no arguments are
given. Added list_recursive().
Signed-off-by: Ewan Mellor <ewan@xensource.com>
given. Added list_recursive().
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@ewan |
---|---|
date | Tue Sep 27 22:02:57 2005 +0100 (2005-09-27) |
parents | a172340ae3f3 |
children | 41735ccc5ee3 |
files | tools/python/xen/xend/xenstore/xstransact.py |
line diff
1.1 --- a/tools/python/xen/xend/xenstore/xstransact.py Tue Sep 27 15:11:59 2005 +0100 1.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py Tue Sep 27 22:02:57 2005 +0100 1.3 @@ -1,4 +1,5 @@ 1.4 # Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk> 1.5 +# Copyright (C) 2005 XenSource Ltd 1.6 1.7 # This file is subject to the terms and conditions of the GNU General 1.8 # Public License. See the file "COPYING" in the main directory of 1.9 @@ -9,6 +10,7 @@ import threading 1.10 from xen.lowlevel import xs 1.11 from xen.xend.xenstore.xsutil import xshandle 1.12 1.13 + 1.14 class xstransact: 1.15 1.16 def __init__(self, path): 1.17 @@ -105,13 +107,39 @@ class xstransact: 1.18 return [] 1.19 1.20 def list(self, *args): 1.21 + """If no arguments are given, list this transaction's path, returning 1.22 + the entries therein, or None if no entries are found. Otherwise, 1.23 + treat each argument as a subpath to this transaction's path, and 1.24 + return the cumulative listing of each of those instead. 1.25 + """ 1.26 if len(args) == 0: 1.27 - raise TypeError 1.28 + return xshandle().ls(self.path) 1.29 + else: 1.30 + ret = [] 1.31 + for key in args: 1.32 + ret.extend(self._list(key)) 1.33 + return ret 1.34 + 1.35 + 1.36 + def list_recursive_(self, subdir, keys): 1.37 ret = [] 1.38 - for key in args: 1.39 - ret.extend(self._list(key)) 1.40 + for key in keys: 1.41 + new_subdir = subdir + "/" + key 1.42 + l = xshandle().ls(new_subdir) 1.43 + if l: 1.44 + ret.append([key, self.list_recursive_(new_subdir, l)]) 1.45 + else: 1.46 + ret.append([key, xshandle().read(new_subdir)]) 1.47 return ret 1.48 1.49 + 1.50 + def list_recursive(self, *args): 1.51 + if len(args) == 0: 1.52 + args = self.list() 1.53 + 1.54 + return self.list_recursive_(self.path, args) 1.55 + 1.56 + 1.57 def gather(self, *args): 1.58 if len(args) and type(args[0]) != tuple: 1.59 args = args,