From 406214e5ca40ad57a1c40e4a8454336f6a26cac2 Mon Sep 17 00:00:00 2001 From: shangxdy Date: Sun, 26 Feb 2017 00:49:42 +0800 Subject: Sync upstream code Sync upstream project of tosca-parser Change-Id: Ic707844203ea05007b3c02e9dcadb52389eb3149 JIRA:PARSER-118 Signed-off-by: shangxdy --- tosca2heat/tosca-parser/toscaparser/shell.py | 40 +++++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'tosca2heat/tosca-parser/toscaparser/shell.py') diff --git a/tosca2heat/tosca-parser/toscaparser/shell.py b/tosca2heat/tosca-parser/toscaparser/shell.py index b41c024..1d98f1a 100644 --- a/tosca2heat/tosca-parser/toscaparser/shell.py +++ b/tosca2heat/tosca-parser/toscaparser/shell.py @@ -11,6 +11,7 @@ # under the License. +import argparse import os import sys @@ -40,19 +41,20 @@ e.g. class ParserShell(object): - def _validate(self, args): - if len(args) < 1: - msg = _('The program requires a template or a CSAR file as an ' - 'argument. Please refer to the usage documentation.') - raise ValueError(msg) - if "--template-file=" not in args[0]: - msg = _('The program expects "--template-file" as the first ' - 'argument. Please refer to the usage documentation.') - raise ValueError(msg) - - def main(self, args): - self._validate(args) - path = args[0].split('--template-file=')[1] + def get_parser(self, argv): + parser = argparse.ArgumentParser(prog="tosca-parser") + + parser.add_argument('--template-file', + metavar='', + required=True, + help=_('YAML template or CSAR file to parse.')) + + return parser + + def main(self, argv): + parser = self.get_parser(argv) + (args, extra_args) = parser.parse_known_args(argv) + path = args.template_file if os.path.isfile(path): self.parse(path) elif toscaparser.utils.urlutils.UrlUtils.validate_url(path): @@ -88,6 +90,18 @@ class ParserShell(object): for node in nodetemplates: print("\t" + node.name) + # example of retrieving policy object + '''if hasattr(tosca, 'policies'): + policies = tosca.policies + if policies: + print("policies:") + for policy in policies: + print("\t" + policy.name) + if policy.triggers: + print("\ttriggers:") + for trigger in policy.triggers: + print("\ttrigger name:" + trigger.name)''' + if hasattr(tosca, 'outputs'): outputs = tosca.outputs if outputs: -- cgit 1.2.3-korg