From ejcasler@us.ibm.com Thu Aug 14 17:00:56 2008 Date: Thu, 14 Aug 2008 14:00:29 -0700 From: Eric Casler To: ssmoser@linux.vnet.ibm.com Subject: [PATCH] Added bound argument to getDict. bound is an optional argument that restricts return values by the attribute ovf:bound. Signed-off-by: Eric Casler --- py/ovf/Ovf.py | 52 +++++++++++++++++++++++++++++----------------------- 1 files changed, 29 insertions(+), 23 deletions(-) diff --git a/py/ovf/Ovf.py b/py/ovf/Ovf.py index 18e346e..11e8761 100644 --- a/py/ovf/Ovf.py +++ b/py/ovf/Ovf.py @@ -151,7 +151,7 @@ def getContentEntities(ovfNode, ovfId=None): return [entity for entity in entities if entity.getAttribute('ovf:id') == ovfId] -def getDict(ovfSection, configId=None): +def getDict(ovfSection, configId=None, bound=None): """ Returns a dictionary, with keys representing the attributes and the children, for an ovf section. Optionally, limits to given configuration. @@ -164,6 +164,9 @@ def getDict(ovfSection, configId=None): @param configId: configuration identifier @type configId: String + @param bound: bound identifier: min, normal, max + @type bound: String + @return: attributes and data from section @rtype: dictionary @@ -197,28 +200,31 @@ def getDict(ovfSection, configId=None): if(configId == None or (isConfiguration(configId) and child.getAttribute('ovf:configuration') == configId)): - - childDict = dict(node=child, - name=child.tagName) - getAttributes(child, childDict) - sectDict['children'].append(childDict) - - # Get info from grandchildren, either text, or - # data from offspring. - if child.hasChildNodes(): - data = False - for grandchild in child.childNodes: - if grandchild.nodeType == Node.ELEMENT_NODE: - childDict[grandchild.tagName] = \ - grandchild.firstChild.data - data = True - - if not data: - # Child has data i.e. AnnotationSection - if not childDict.has_key('text'): - childDict['text'] = '' - childDict['text'] = (childDict['text'] + - child.firstChild.data) + # Restrict by given bound value + if(bound == None or + child.getAttribute('ovf:bound') == bound): + + childDict = dict(node=child, + name=child.tagName) + getAttributes(child, childDict) + sectDict['children'].append(childDict) + + # Get info from grandchildren, either text, or + # data from offspring. + if child.hasChildNodes(): + data = False + for grandchild in child.childNodes: + if grandchild.nodeType == Node.ELEMENT_NODE: + childDict[grandchild.tagName] = \ + grandchild.firstChild.data + data = True + + if not data: + # Child has data i.e. AnnotationSection + if not childDict.has_key('text'): + childDict['text'] = '' + childDict['text'] = (childDict['text'] + + child.firstChild.data) return sectDict -- 1.5.4.3