From a38b63b3cd00ae640ca1a3d8ad2070d27841e346 Mon Sep 17 00:00:00 2001
From: Michele Carignani <michele.carignani@etsi.org>
Date: Thu, 7 Mar 2019 10:16:56 +0100
Subject: [PATCH] added first prototype of document to tosca translator

---
 doc2tosca.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 doc2tosca.py

diff --git a/doc2tosca.py b/doc2tosca.py
new file mode 100644
index 0000000..7c8695c
--- /dev/null
+++ b/doc2tosca.py
@@ -0,0 +1,52 @@
+#!/bin/python2.7
+'''
+Generate tosca definitions from Docx specfication
+'''
+
+import sys
+import docx
+
+def  is_tosca_def(table):
+    '''
+    Returns true when a table contains TOSCA definitions, i.e.
+    the table contains just one cell and text starts with an 
+    empty space ' '' 
+    '''
+    txt = table.rows[0].cells[0].text[0]
+    return \
+    len(table.rows) == 1 and \
+    len(table.columns) == 1 and \
+    txt.startswith(' ')
+
+
+try:
+    SOL001_FN = sys.argv[1] 
+except:
+    print 'Error: Filename missing or filename not a docx document'
+    print 'Usage: doc2tosca <docx-with-tosca-definitions>'
+    sys.exit(1)
+
+OUT_FN = 'try-tosca-export.yaml'
+
+SOL001 = docx.Document(SOL001_FN)
+
+DEFINITIONS = [t for t in SOL001.tables if is_tosca_def(t)]
+F = open(OUT_FN, 'w')
+
+HDR='''tosca_definitions_version: tosca_simple_yaml_1_2
+description: ETSI NFV SOL 001 nsd types definitions version 2.5.1
+
+imports:
+  - etsi_nfv_sol001_vnfd_2_5_1_types.yaml
+
+data_types:
+'''
+
+F.write(HDR)
+
+for t in DEFINITIONS:
+    F.write(t.rows[0].cells[0].text.encode('utf-8'))
+    F.write('\n# -------------------- #\n')
+
+F.write('\n')
+F.close()
-- 
GitLab