Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()