From 4fbd9cdd56cd72bceeacfd9315b6efa6673b397e Mon Sep 17 00:00:00 2001 From: Vahid Hashemian Date: Wed, 2 Dec 2015 11:58:52 -0800 Subject: [PATCH] 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 --- toscaparser/shell.py | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/toscaparser/shell.py b/toscaparser/shell.py index 00097bf1..848726f2 100644 --- a/toscaparser/shell.py +++ b/toscaparser/shell.py @@ -64,27 +64,36 @@ class ParserShell(object): def parse(self, path, a_file=True): output = None tosca = ToscaTemplate(path, None, a_file) + version = tosca.version if tosca.version: print ("\nversion: " + version) - description = tosca.description - if description: - print ("\ndescription: " + description) - inputs = tosca.inputs - if inputs: - print ("\ninputs:") - for input in inputs: - print ("\t" + input.name) - nodetemplates = tosca.nodetemplates - if nodetemplates: - print ("\nnodetemplates:") - for node in nodetemplates: - print ("\t" + node.name) - outputs = tosca.outputs - if outputs: - print ("\noutputs:") - for output in outputs: - print ("\t" + output.name) + + if hasattr(tosca, 'description'): + description = tosca.description + if description: + print ("\ndescription: " + description) + + if hasattr(tosca, 'inputs'): + inputs = tosca.inputs + if inputs: + print ("\ninputs:") + for input in inputs: + print ("\t" + input.name) + + if hasattr(tosca, 'nodetemplates'): + nodetemplates = tosca.nodetemplates + if nodetemplates: + print ("\nnodetemplates:") + 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):