Add checks in shell for optional keynames in the template

Check for presence of the optional attributes before extracting
their value.

Change-Id: Ic017f2d7926938cf78b353f608b2e6015841bd4f
Closes-Bug: #1522131
This commit is contained in:
Vahid Hashemian 2015-12-02 11:58:52 -08:00
parent cd560b8f26
commit 4fbd9cdd56

View File

@ -64,27 +64,36 @@ class ParserShell(object):
def parse(self, path, a_file=True): def parse(self, path, a_file=True):
output = None output = None
tosca = ToscaTemplate(path, None, a_file) tosca = ToscaTemplate(path, None, a_file)
version = tosca.version version = tosca.version
if tosca.version: if tosca.version:
print ("\nversion: " + version) print ("\nversion: " + version)
description = tosca.description
if description: if hasattr(tosca, 'description'):
print ("\ndescription: " + description) description = tosca.description
inputs = tosca.inputs if description:
if inputs: print ("\ndescription: " + description)
print ("\ninputs:")
for input in inputs: if hasattr(tosca, 'inputs'):
print ("\t" + input.name) inputs = tosca.inputs
nodetemplates = tosca.nodetemplates if inputs:
if nodetemplates: print ("\ninputs:")
print ("\nnodetemplates:") for input in inputs:
for node in nodetemplates: print ("\t" + input.name)
print ("\t" + node.name)
outputs = tosca.outputs if hasattr(tosca, 'nodetemplates'):
if outputs: nodetemplates = tosca.nodetemplates
print ("\noutputs:") if nodetemplates:
for output in outputs: print ("\nnodetemplates:")
print ("\t" + output.name) for node in nodetemplates:
print ("\t" + node.name)
if hasattr(tosca, 'outputs'):
outputs = tosca.outputs
if outputs:
print ("\noutputs:")
for output in outputs:
print ("\t" + output.name)
def main(args=None): def main(args=None):