diff --git a/src/doc2tosca.py b/src/doc2tosca.py index 11908766bd418291d43a3b9bfc8476d041718925..f6bad2ef51d5869dc45adc8c9a85e9c462771401 100644 --- a/src/doc2tosca.py +++ b/src/doc2tosca.py @@ -89,7 +89,7 @@ def find_sect(sect_to_find, start_idx, doc_content): ''' while start_idx < len(doc_content): my_elem = doc_content[start_idx] - if isinstance(my_elem, Paragraph) and my_elem.text == sect_to_find: + if isinstance(my_elem, Paragraph) and my_elem.text.strip() == sect_to_find: break start_idx = start_idx + 1 @@ -111,7 +111,7 @@ def write_table_to_file(tab, buf): txt = tab.rows[0].cells[0].text # print("# Included in: " + tab.rows[0].cells[0].text.split("\n")[0]) - buf.write("\n".join([pad2(x) for x in txt.split("\n")])) + buf.write("\n".join([x for x in txt.split("\n")])) # buf.write('\n# -------------------- #\n') if not txt.endswith('\n'): buf.write('\n') @@ -125,6 +125,12 @@ def generate_tables_between(a_id, b_id, content, buf): definitions_count = 0 for idx in range(a_id, b_id): + if idx >= len(content): + print("A: " + str(a_id)) + print("B: " + str(b_id)) + print("IDX: " + str(idx)) + print("LEN(CONTENT): " + str(len(content))) + return tmp_elem = content[idx] if isinstance(tmp_elem, Table) and is_tosca_def(tmp_elem): write_table_to_file(tmp_elem, buf) @@ -202,11 +208,13 @@ def generate_templates(filename, spec_version=SPEC_VERSION, yaml_root_path='uri' sect_6_id = find_sect("6\tVNFD TOSCA model", p_id, CONTENT) - sect_7_id = find_sect("7\tNSD TOSCA model", sect_6_id + 1, CONTENT) + sect_7_id = find_sect("7\tNSD TOSCA model", sect_6_id, CONTENT) - sect_8_id = find_sect("8\tPNFD TOSCA model", sect_7_id + 1, CONTENT) + sect_8_id = find_sect("8\tPNFD TOSCA model", sect_7_id, CONTENT) - annex_a_id = find_sect("Annex A (informative):", sect_7_id + 1, CONTENT) + sect_9_id = find_sect("9\tCommon Definitions", sect_8_id, CONTENT) + + annex_a_id = find_sect("Annex A (informative):", sect_9_id, CONTENT) count = generate_tables_between(sect_6_id, sect_7_id, CONTENT, MODELS['vnfd']['buf']) print("Printed " + str(count) + " types to " + "VNFD\n\n\n") @@ -214,9 +222,12 @@ def generate_templates(filename, spec_version=SPEC_VERSION, yaml_root_path='uri' count = generate_tables_between(sect_7_id, sect_8_id, CONTENT, MODELS['nsd']['buf']) print("Printed " + str(count) + " types to " + "NSD\n\n\n") - count = generate_tables_between(sect_8_id, annex_a_id, CONTENT, MODELS['pnfd']['buf']) + count = generate_tables_between(sect_8_id, sect_9_id, CONTENT, MODELS['pnfd']['buf']) print("Printed " + str(count) + " types to " + "PNFD\n\n\n") + count = generate_tables_between(sect_9_id, annex_a_id, CONTENT, MODELS['common']['buf']) + print("Printed " + str(count) + " types to " + "Common\n\n\n") + def print_to_files(prefix=None): ''' diff --git a/src/templates/doc2tosca-details.html b/src/templates/doc2tosca-details.html index 203211b0cf009132f81599f5c8c7d3d5545ddeb6..6e49aa9586d6005faf4d35c57210af309a41af4e 100644 --- a/src/templates/doc2tosca-details.html +++ b/src/templates/doc2tosca-details.html @@ -40,6 +40,7 @@ <li><code>6 VNFD TOSCA model</code></li> <li><code>7 NSD TOSCA model</code></li> <li><code>8 PNFD TOSCA model</code>,</li> +<li><code>9 Common Definitions</code>,</li> </ul> <p>Step 2: For each of the section after the heading (and until the next heading is found), the tool searches for tables with the following properties:</p> @@ -49,12 +50,13 @@ <li>the content matches the regular expression <code>^tosca\.[a-zA-Z\.:0-9\s]*$</code>, i.e. the text starts with <code>tosca.</code> and contains letters, numbers, <code>:</code> or white space.</li> </ul> -<p>Step 3: The three sets of generated definitions are written to files named:</p> +<p>Step 3: The four sets of generated definitions are written to files named:</p> <ul> <li><code>generated_etsi_nfv_sol001_vnfd_types.yaml</code></li> <li><code>generated_etsi_nfv_sol001_nsd_types.yaml</code></li> <li><code>generated_etsi_nfv_sol001_pnfd_types.yaml</code></li> +<li><code>generated_etsi_nfv_sol001_common_types.yaml</code></li> </ul> <p>Step 4: The files are archived in a zip file named <code>tosca_defs.zip</code> which is served as a response.</p> diff --git a/src/templates/doc2tosca-details.md b/src/templates/doc2tosca-details.md index 080cf8a93f5895a87e9f44720605671958f24079..3449b2255dce1152a5df3b5328a15d43fab084ef 100644 --- a/src/templates/doc2tosca-details.md +++ b/src/templates/doc2tosca-details.md @@ -5,17 +5,19 @@ Step 1: In the uploaded Document it searches for headings equal to: * `6\tVNFD TOSCA model` * `7\tNSD TOSCA model` * `8\tPNFD TOSCA model`, +* `9\tCommon Definitions`, Step 2: For each of the section after the heading (and until the next heading is found), the tool searches for tables with the following properties: * It contains only one cell (i.e. one row and one column) and * the content matches the regular expression `^tosca\.[a-zA-Z\.:0-9\s]*$`, i.e. the text starts with `tosca.` and contains letters, numbers, `:` or white space. -Step 3: The three sets of generated definitions are written to files named: +Step 3: The four sets of generated definitions are written to files named: * `generated_etsi_nfv_sol001_vnfd_types.yaml` * `generated_etsi_nfv_sol001_nsd_types.yaml` * `generated_etsi_nfv_sol001_pnfd_types.yaml` +* `generated_etsi_nfv_sol001_common_types.yaml` Step 4: The files are archived in a zip file named `tosca_defs.zip` which is served as a response.