ia64/xen-unstable

changeset 7110:ca78d9668fdb

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>
author emellor@ewan
date Wed Sep 28 15:06:48 2005 +0100 (2005-09-28)
parents 1d74fff611c8
children ce54669c70fc 688ebed7d41b
files tools/python/xen/xend/server/DevController.py tools/python/xen/xend/xenstore/xstransact.py
line diff
     1.1 --- a/tools/python/xen/xend/server/DevController.py	Wed Sep 28 15:03:27 2005 +0100
     1.2 +++ b/tools/python/xen/xend/server/DevController.py	Wed Sep 28 15:06:48 2005 +0100
     1.3 @@ -85,16 +85,7 @@ class DevController:
     1.4          """@return an s-expression describing all the devices of this
     1.5          controller's device-class.
     1.6          """
     1.7 -        path = self.frontendRoot()
     1.8 -        while True:
     1.9 -            t = xstransact(path)
    1.10 -            try:
    1.11 -                listing = t.list_recursive()
    1.12 -                if t.commit():
    1.13 -                    return listing
    1.14 -            except:
    1.15 -                t.abort()
    1.16 -                raise
    1.17 +        return xstransact.ListRecursive(self.frontendRoot())
    1.18  
    1.19  
    1.20      def sxpr(self, devid):
     2.1 --- a/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 28 15:03:27 2005 +0100
     2.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py	Wed Sep 28 15:06:48 2005 +0100
     2.3 @@ -115,12 +115,16 @@ class xstransact:
     2.4  
     2.5      def list(self, *args):
     2.6          """If no arguments are given, list this transaction's path, returning
     2.7 -        the entries therein, or None if no entries are found.  Otherwise,
     2.8 -        treat each argument as a subpath to this transaction's path, and
     2.9 -        return the cumulative listing of each of those instead.
    2.10 +        the entries therein, or the empty list if no entries are found.
    2.11 +        Otherwise, treat each argument as a subpath to this transaction's
    2.12 +        path, and return the cumulative listing of each of those instead.
    2.13          """
    2.14          if len(args) == 0:
    2.15 -            return xshandle().ls(self.path)
    2.16 +            ret = xshandle().ls(self.path)
    2.17 +            if ret is None:
    2.18 +                return []
    2.19 +            else:
    2.20 +                return ret
    2.21          else:
    2.22              ret = []
    2.23              for key in args:
    2.24 @@ -141,8 +145,15 @@ class xstransact:
    2.25  
    2.26  
    2.27      def list_recursive(self, *args):
    2.28 +        """If no arguments are given, list this transaction's path, returning
    2.29 +        the entries therein, or the empty list if no entries are found.
    2.30 +        Otherwise, treat each argument as a subpath to this transaction's
    2.31 +        path, and return the cumulative listing of each of those instead.
    2.32 +        """
    2.33          if len(args) == 0:
    2.34              args = self.list()
    2.35 +            if args is None or len(args) == 0:
    2.36 +                return []
    2.37  
    2.38          return self.list_recursive_(self.path, args)
    2.39  
    2.40 @@ -248,11 +259,11 @@ class xstransact:
    2.41      Remove = classmethod(Remove)
    2.42  
    2.43      def List(cls, path, *args):
    2.44 -        """If no arguments are given (path), list its contents, returning the
    2.45 -        entries therein, or None if no entries are found.  Otherwise, treat
    2.46 -        each further argument as a subpath to the given path, and return the
    2.47 -        cumulative listing of each of those instead.  This operation is
    2.48 -        performed inside a transaction.
    2.49 +        """If only one argument is given (path), list its contents, returning
    2.50 +        the entries therein, or the empty list if no entries are found.
    2.51 +        Otherwise, treat each further argument as a subpath to the given path,
    2.52 +        and return the cumulative listing of each of those instead.  This
    2.53 +        operation is performed inside a transaction.
    2.54          """
    2.55          while True:
    2.56              t = cls(path)
    2.57 @@ -266,6 +277,25 @@ class xstransact:
    2.58  
    2.59      List = classmethod(List)
    2.60  
    2.61 +    def ListRecursive(cls, path, *args):
    2.62 +        """If only one argument is given (path), list its contents
    2.63 +        recursively, returning the entries therein, or the empty list if no
    2.64 +        entries are found.  Otherwise, treat each further argument as a
    2.65 +        subpath to the given path, and return the cumulative listing of each
    2.66 +        of those instead.  This operation is performed inside a transaction.
    2.67 +        """
    2.68 +        while True:
    2.69 +            t = cls(path)
    2.70 +            try:
    2.71 +                v = t.list_recursive(*args)
    2.72 +                if t.commit():
    2.73 +                    return v
    2.74 +            except:
    2.75 +                t.abort()
    2.76 +                raise
    2.77 +
    2.78 +    ListRecursive = classmethod(ListRecursive)
    2.79 +
    2.80      def Gather(cls, path, *args):
    2.81          while True:
    2.82              t = cls(path)