summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/shell.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2017-02-26 00:49:42 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2017-02-26 00:58:41 +0800
commit406214e5ca40ad57a1c40e4a8454336f6a26cac2 (patch)
treec07fa0c0a66716351a367d1959415584fb73bab1 /tosca2heat/tosca-parser/toscaparser/shell.py
parent0504c523da459a48721fef74216125d83a4e057d (diff)
Sync upstream code
Sync upstream project of tosca-parser Change-Id: Ic707844203ea05007b3c02e9dcadb52389eb3149 JIRA:PARSER-118 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/shell.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/shell.py40
1 files changed, 27 insertions, 13 deletions
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='<filename>',
+ 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: