mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
Added new classmethod xstransact.ListRecursive, and use this inside
DevController to tidy up the code there. Change the semantics of xstransact.list and List to return the empty list rather than None if there are no entries or the directory is not present, as this is easier to handle for the client. Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
5d7d6aff18
commit
55da9243e8
2 files changed
+40
-19
No files matched your search
@@ -85,16 +85,7 @@ class DevController:
|
||||
"""@return an s-expression describing all the devices of this
|
||||
controller's device-class.
|
||||
"""
|
||||
path = self.frontendRoot()
|
||||
while True:
|
||||
t = xstransact(path)
|
||||
try:
|
||||
listing = t.list_recursive()
|
||||
if t.commit():
|
||||
return listing
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
return xstransact.ListRecursive(self.frontendRoot())
|
||||
|
||||
|
||||
def sxpr(self, devid):
|
||||
|
||||
@@ -115,12 +115,16 @@ class xstransact:
|
||||
|
||||
def list(self, *args):
|
||||
"""If no arguments are given, list this transaction's path, returning
|
||||
the entries therein, or None if no entries are found. Otherwise,
|
||||
treat each argument as a subpath to this transaction's path, and
|
||||
return the cumulative listing of each of those instead.
|
||||
the entries therein, or the empty list if no entries are found.
|
||||
Otherwise, treat each argument as a subpath to this transaction's
|
||||
path, and return the cumulative listing of each of those instead.
|
||||
"""
|
||||
if len(args) == 0:
|
||||
return xshandle().ls(self.path)
|
||||
ret = xshandle().ls(self.path)
|
||||
if ret is None:
|
||||
return []
|
||||
else:
|
||||
return ret
|
||||
else:
|
||||
ret = []
|
||||
for key in args:
|
||||
@@ -141,8 +145,15 @@ class xstransact:
|
||||
|
||||
|
||||
def list_recursive(self, *args):
|
||||
"""If no arguments are given, list this transaction's path, returning
|
||||
the entries therein, or the empty list if no entries are found.
|
||||
Otherwise, treat each argument as a subpath to this transaction's
|
||||
path, and return the cumulative listing of each of those instead.
|
||||
"""
|
||||
if len(args) == 0:
|
||||
args = self.list()
|
||||
if args is None or len(args) == 0:
|
||||
return []
|
||||
|
||||
return self.list_recursive_(self.path, args)
|
||||
|
||||
@@ -248,11 +259,11 @@ class xstransact:
|
||||
Remove = classmethod(Remove)
|
||||
|
||||
def List(cls, path, *args):
|
||||
"""If no arguments are given (path), list its contents, returning the
|
||||
entries therein, or None if no entries are found. Otherwise, treat
|
||||
each further argument as a subpath to the given path, and return the
|
||||
cumulative listing of each of those instead. This operation is
|
||||
performed inside a transaction.
|
||||
"""If only one argument is given (path), list its contents, returning
|
||||
the entries therein, or the empty list if no entries are found.
|
||||
Otherwise, treat each further argument as a subpath to the given path,
|
||||
and return the cumulative listing of each of those instead. This
|
||||
operation is performed inside a transaction.
|
||||
"""
|
||||
while True:
|
||||
t = cls(path)
|
||||
@@ -266,6 +277,25 @@ class xstransact:
|
||||
|
||||
List = classmethod(List)
|
||||
|
||||
def ListRecursive(cls, path, *args):
|
||||
"""If only one argument is given (path), list its contents
|
||||
recursively, returning the entries therein, or the empty list if no
|
||||
entries are found. Otherwise, treat each further argument as a
|
||||
subpath to the given path, and return the cumulative listing of each
|
||||
of those instead. This operation is performed inside a transaction.
|
||||
"""
|
||||
while True:
|
||||
t = cls(path)
|
||||
try:
|
||||
v = t.list_recursive(*args)
|
||||
if t.commit():
|
||||
return v
|
||||
except:
|
||||
t.abort()
|
||||
raise
|
||||
|
||||
ListRecursive = classmethod(ListRecursive)
|
||||
|
||||
def Gather(cls, path, *args):
|
||||
while True:
|
||||
t = cls(path)
|
||||
|
||||