Determines whether parameter is a template or a value. Adds graph nodes and edges accordingly.
(G, name, value)
| 118 | |
| 119 | |
| 120 | def _process(G, name, value): |
| 121 | """ |
| 122 | Determines whether parameter is a template or a value. Adds graph nodes and edges accordingly. |
| 123 | """ |
| 124 | # Jinja defaults to ascii parser in python 2.x unless you set utf-8 support on per module level |
| 125 | # Instead we're just assuming every string to be a unicode string |
| 126 | if isinstance(value, str): |
| 127 | value = to_unicode(value) |
| 128 | |
| 129 | complex_value_str = None |
| 130 | if isinstance(value, list) or isinstance(value, dict): |
| 131 | complex_value_str = str(value) |
| 132 | |
| 133 | is_jinja_expr = jinja_utils.is_jinja_expression( |
| 134 | value |
| 135 | ) or jinja_utils.is_jinja_expression(complex_value_str) |
| 136 | |
| 137 | if is_jinja_expr: |
| 138 | try: |
| 139 | template_ast = ENV.parse(value) |
| 140 | G.add_node(name, template=value) |
| 141 | |
| 142 | LOG.debug("Template ast: %s", template_ast) |
| 143 | # Dependencies of the node represent jinja variables used in the template |
| 144 | # We're connecting nodes with an edge for every depencency to traverse them |
| 145 | # in the right order and also make sure that we don't have missing or cyclic |
| 146 | # dependencies upfront. |
| 147 | dependencies = meta.find_undeclared_variables(template_ast) |
| 148 | LOG.debug("Dependencies: %s", dependencies) |
| 149 | if dependencies: |
| 150 | for dependency in dependencies: |
| 151 | G.add_edge(dependency, name) |
| 152 | except exceptions.TemplateSyntaxError: |
| 153 | G.add_node(name, value=value) |
| 154 | # not jinja after all |
| 155 | # is_jinga_expression only checks for {{ or {{% for speed |
| 156 | else: |
| 157 | G.add_node(name, value=value) |
| 158 | |
| 159 | |
| 160 | def _process_defaults(G, schemas): |
no test coverage detected