Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CTI Tools
tosca2doc
Commits
8374ed65
Commit
8374ed65
authored
Jun 17, 2019
by
carignani
Browse files
custom version of YAML files for doc2tosca enabled
parent
b1226384
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/config.py
View file @
8374ed65
VERSION
=
"0.0.
2
"
VERSION
=
"0.0.
3
"
src/doc2tosca.py
View file @
8374ed65
...
...
@@ -14,9 +14,9 @@ from docx.text.paragraph import Paragraph
BASE_FILENAME
=
"generated_etsi_nfv_sol001_{}_types.yaml"
TOSCA_VERSION
=
"tosca_simple_yaml_1_2"
SPEC_VERSION
=
"2.6.1"
SPEC_VERSION
=
"
v
2.6.1"
allowed_versions
=
[
"2.6.1"
,
"2.7.1"
]
allowed_versions
=
[
"
v
2.6.1"
,
"
v2.6.3"
,
"v
2.7.1"
]
MODEL_NAMES
=
[
'vnfd'
,
'nsd'
,
'pnfd'
,
'common'
]
...
...
@@ -165,10 +165,14 @@ def generate_templates(filename, spec_version=SPEC_VERSION):
for
mn
in
MODEL_NAMES
:
MODELS
[
mn
]
=
tosca_model_info
(
mn
,
'- https://forge.etsi.org/rep/nfv/SOL001/raw/
v
{}/etsi_nfv_sol001_common_types.yaml'
.
format
(
spec_version
)
'- https://forge.etsi.org/rep/nfv/SOL001/raw/{}/etsi_nfv_sol001_common_types.yaml'
.
format
(
spec_version
)
)
sol_001
=
docx
.
Document
(
filename
)
try
:
sol_001
=
docx
.
Document
(
filename
)
except
:
print
(
"Error opening the submitted Docx file"
)
raise
ValueError
(
"Cannot open the submitted Docx file"
)
for
m
in
MODELS
:
dump_header
(
...
...
src/templates/home.html
View file @
8374ed65
<!
doctype html
>
<!
DOCTYPE HTML
>
<html>
...
...
@@ -83,6 +83,9 @@ For any other inquiry, contact <a href="mailto:cti_support@etsi.org">ETSI CTI</a
<option
value=
"{{version}}"
>
{{version}}
</option>
{% endfor %}
</select>
<br
/>
Custom version (overrides the selector):
<input
type=
"text"
name=
"custom-doc-version"
>
<br
/><br
/>
<center>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"Upload"
/>
...
...
src/test_after_request.py
0 → 100644
View file @
8374ed65
#!/bin/python3
'''
just a test
'''
import
os
from
flask
import
Flask
,
flash
,
request
,
send_file
,
g
app
=
Flask
(
__name__
)
@
app
.
after_request
def
after_request
(
response
):
if
request
.
path
!=
'/ciao'
:
return
response
os
.
remove
(
g
.
fname
)
print
(
"Deleted {}
\n\n
"
.
format
(
g
.
fname
))
return
response
@
app
.
route
(
"/"
)
def
hello
():
'''
noting
'''
return
'Hello world'
@
app
.
route
(
"/ciao"
)
def
ciao
():
fname
=
'/tmp/MIOMIOMIO.txt'
myfile
=
open
(
fname
,
'w'
)
myfile
.
write
(
'PROVA
\n
'
*
100
)
myfile
.
close
()
g
.
fname
=
fname
return
send_file
(
fname
,
as_attachment
=
True
)
src/web_app.py
View file @
8374ed65
...
...
@@ -173,6 +173,7 @@ def mk_doc2tosca():
try
:
print
(
request
.
form
)
doc_version
=
request
.
form
.
get
(
'doc-version'
)
custom_doc_version
=
request
.
form
.
get
(
'custom-doc-version'
)
except
:
flash
(
"Something went wrong :/"
)
return
redirect
(
"/tosca-ie"
)
...
...
@@ -183,7 +184,16 @@ def mk_doc2tosca():
sol001_file
=
ufiles
[
0
]
doc2tosca
.
generate_templates
(
sol001_file
,
doc_version
)
if
custom_doc_version
!=
""
:
doc_version
=
custom_doc_version
try
:
doc2tosca
.
generate_templates
(
sol001_file
,
doc_version
)
except
ValueError
as
e
:
flash
(
str
(
e
))
return
redirect
(
"/tosca-ie"
)
except
:
flash
(
"Unknown error in the generation of the files. Please contact the support."
)
return
redirect
(
"/tosca-ie"
)
tmp_dir
=
tempfile
.
mkdtemp
()
print
(
"TMP DIR: "
+
tmp_dir
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment