summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/shell.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2017-09-07 12:50:34 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2017-09-07 13:40:31 +0800
commitf6f9aa52c2107b4a0e17c1b9f3f6bf411387ceba (patch)
tree0527c6d48073bde21c568c329776a60c60790cbd /tosca2heat/tosca-parser/toscaparser/shell.py
parentdd361d8d9df7a69a4fc7c004db5b959440a024c2 (diff)
Add debug mode parameter
In debug mode, it's not allowed to raise exceptions as possible for convinient to debug more details, this patch will add parameter to enable such scenario. The requirement is from ONAP JIRA: PARSER-148 Change-Id: Ide8acec333d17331bd6ed400110a141391fd3593 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.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/shell.py b/tosca2heat/tosca-parser/toscaparser/shell.py
index f669e27..ba9c28f 100644
--- a/tosca2heat/tosca-parser/toscaparser/shell.py
+++ b/tosca2heat/tosca-parser/toscaparser/shell.py
@@ -53,55 +53,70 @@ class ParserShell(object):
required=True,
help=_('YAML template or CSAR file to parse.'))
- parser.add_argument('-nrpv', dest='no_required_paras_valid',
+ parser.add_argument('-nrpv', dest='no_required_paras_check',
action='store_true', default=False,
help=_('Ignore input parameter validation '
'when parse template.'))
+ parser.add_argument('--debug', dest='debug_mode',
+ action='store_true', default=False,
+ help=_('debug mode for print more details '
+ 'other than raise exceptions when '
+ 'errors happen as possible'))
+
return parser
def main(self, argv):
parser = self.get_parser(argv)
(args, extra_args) = parser.parse_known_args(argv)
path = args.template_file
- nrpv = args.no_required_paras_valid
+ nrpv = args.no_required_paras_check
+ debug = args.debug_mode
+
if os.path.isfile(path):
- self.parse(path, no_req_paras_valid=nrpv)
+ self.parse(path, no_required_paras_check=nrpv, debug_mode=debug)
elif toscaparser.utils.urlutils.UrlUtils.validate_url(path):
- self.parse(path, False, no_req_paras_valid=nrpv)
+ self.parse(path, False,
+ no_required_paras_check=nrpv,
+ debug_mode=debug)
else:
raise ValueError(_('"%(path)s" is not a valid file.')
% {'path': path})
- def parse(self, path, a_file=True, no_req_paras_valid=False):
- output = None
- tosca = None
+ def parse(self, path, a_file=True, no_required_paras_check=False,
+ debug_mode=False):
+ nrpv = no_required_paras_check
try:
tosca = ToscaTemplate(path, None, a_file,
- no_required_paras_valid=no_req_paras_valid)
+ no_required_paras_check=nrpv,
+ debug_mode=debug_mode)
except ValidationError as e:
msg = _(' ===== main service template ===== ')
log.error(msg)
log.error(e.message)
- raise e
-
- version = tosca.version
- if tosca.version:
+ if debug_mode:
+ print(msg)
+ print(e.message)
+ else:
+ raise e
+
+ version = tosca.version if tosca else "unknown"
+ if tosca and tosca.version:
print("\nversion: " + version)
- if hasattr(tosca, 'description'):
+ if tosca and hasattr(tosca, 'description'):
description = tosca.description
if description:
print("\ndescription: " + description)
- if hasattr(tosca, 'inputs'):
+ if tosca and hasattr(tosca, 'inputs'):
inputs = tosca.inputs
if inputs:
print("\ninputs:")
for input in inputs:
print("\t" + input.name)
- if hasattr(tosca, 'nodetemplates'):
+ if tosca and hasattr(tosca, 'nodetemplates'):
nodetemplates = tosca.nodetemplates
if nodetemplates:
print("\nnodetemplates:")
@@ -120,7 +135,7 @@ class ParserShell(object):
for trigger in policy.triggers:
print("\ttrigger name:" + trigger.name)'''
- if hasattr(tosca, 'outputs'):
+ if tosca and hasattr(tosca, 'outputs'):
outputs = tosca.outputs
if outputs:
print("\noutputs:")