summaryrefslogtreecommitdiffstats
path: root/app/toscalib/utils/tosca_print.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/toscalib/utils/tosca_print.py')
-rw-r--r--app/toscalib/utils/tosca_print.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/app/toscalib/utils/tosca_print.py b/app/toscalib/utils/tosca_print.py
new file mode 100644
index 0000000..a7205e3
--- /dev/null
+++ b/app/toscalib/utils/tosca_print.py
@@ -0,0 +1,58 @@
+#Author: Shu Shi
+#emaiL: shushi@research.att.com
+
+
+LEVEL_NODE_NAME = 1
+LEVEL_NODE_DETAILS = 2
+LEVEL_NODE_EVERYTHING = 3
+
+def _print_template(template, level=LEVEL_NODE_DETAILS):
+ print_str = ''
+ if template is None:
+ return print_str
+ print_str += 'Nodes:'+ '\n'
+ for node in iter(template.node_dict.values()):
+ print_str += _print_node(node, level)
+ return print_str
+
+def _print_node(node, level):
+ print_str = ''
+ if node is None:
+ return
+ print_str += ' '+ node.name + '\n'
+ print_str += ' type: '+ node.type+ '\n'
+ if level == LEVEL_NODE_DETAILS:
+ if len(node.properties) > 0:
+ print_str += ' properties:' + '\n'
+ for prop in iter(node.properties.values()):
+ if prop.filled:
+ print_str += ' '+ prop.name+ ': '+ str(prop.value._get_value()[0])+ '\n'
+ else:
+ print_str += ' '+ prop.name+ ': null'+ '\n'
+ if len(node.requirements)> 0:
+ print_str += ' requirements:'+ '\n'
+ for req in node.requirements:
+ if req.filled:
+ print_str += ' '+ req.name+ ': '+ req.value.name+ '\n'
+ else:
+ print_str += ' '+ req.name+ ': null'+ '\n'
+ print_str += ''+ '\n'
+ return print_str
+
+
+def _print_node_types(db):
+ print_str = 'Available node types: '+ '\n'
+ for name in db.NODE_TYPES.keys():
+ print_str += name, '\n'
+ return print_str
+
+def _print_templates(db):
+ print_str = 'Available templates: '+ '\n'
+ for name in db.TEMPLATES.keys():
+ print_str += name, '\n'
+ return print_str
+
+def _print_node_type(node_type):
+ print_str = 'Node Type Definition: '+ node_type.name+ '\n'
+ print_str += node_type.raw_content+ '\n'
+ return print_str