Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tosca2doc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTI Tools
tosca2doc
Commits
aa5eb74b
Commit
aa5eb74b
authored
6 years ago
by
carignani
Browse files
Options
Downloads
Patches
Plain Diff
Several improvements
parent
986b91f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/doc2tosca.py
+10
-7
10 additions, 7 deletions
src/doc2tosca.py
src/tosca2doc.py
+3
-3
3 additions, 3 deletions
src/tosca2doc.py
src/web_app.py
+25
-11
25 additions, 11 deletions
src/web_app.py
with
38 additions
and
21 deletions
src/doc2tosca.py
+
10
−
7
View file @
aa5eb74b
...
...
@@ -12,7 +12,7 @@ import docx
from
docx.table
import
Table
from
docx.text.paragraph
import
Paragraph
BASE_FILENAME
=
"
try-tosca-export_{}
.yaml
"
BASE_FILENAME
=
"
generated_etsi_nfv_sol001_{}_types
.yaml
"
TOSCA_VERSION
=
"
tosca_simple_yaml_1_2
"
SPEC_VERSION
=
"
2.6.1
"
...
...
@@ -21,7 +21,7 @@ MODEL_NAMES = ['vnfd', 'nsd', 'pnfd', 'common']
HDR
=
'''
tosca_definitions_version: {tosca_version}
description: ETSI NFV SOL 001 {model} types definitions version {spec_version}
metadata:
- template_name: {model}
- template_name:
etsi_nfv_sol001_
{model}
_types
- template_name: ETSI_NFV
- template_version: {spec_version}
...
...
@@ -108,7 +108,7 @@ def write_table_to_file(tab, buf):
return
"
"
+
txt
txt
=
tab
.
rows
[
0
].
cells
[
0
].
text
# print("
+++++
Included in: " + tab.rows[0].cells[0].text.split("\n")[0])
# 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# -------------------- #\n')
if
not
txt
.
endswith
(
'
\n
'
):
...
...
@@ -121,6 +121,7 @@ def generate_tables_between(a_id, b_id, content, buf):
fdesc file. Returns the number of written definitions
'''
definitions_count
=
0
for
idx
in
range
(
a_id
,
b_id
):
tmp_elem
=
content
[
idx
]
if
isinstance
(
tmp_elem
,
Table
)
and
is_tosca_def
(
tmp_elem
):
...
...
@@ -153,12 +154,15 @@ def dump_header(model_name, buf, imports=None):
MODELS
=
{}
for
mn
in
MODEL_NAMES
:
MODELS
[
mn
]
=
tosca_model_info
(
mn
,
'
- etsi_nfv_sol001_common_types.yaml
'
)
MODELS
[
mn
]
=
tosca_model_info
(
mn
,
'
- https://forge.etsi.org/rep/nfv/SOL001/raw/v{}/etsi_nfv_sol001_common_types.yaml
'
.
format
(
SPEC_VERSION
)
)
def
generate_templates
(
filename
):
'''
Takes a filename and loads the definition into the MODELS dictionary
Takes a filename
or file object
and loads the definition into the MODELS dictionary
'''
if
isinstance
(
filename
,
str
):
print
(
"
Opening
"
+
filename
)
...
...
@@ -166,8 +170,7 @@ def generate_templates(filename):
sol_001
=
docx
.
Document
(
filename
)
for
m
in
MODELS
:
# MODELS[m]['imports']
dump_header
(
MODELS
[
m
][
'
name
'
],
MODELS
[
m
][
'
buf
'
])
dump_header
(
MODELS
[
m
][
'
name
'
],
MODELS
[
m
][
'
buf
'
],
MODELS
[
m
][
'
imports
'
])
p_id
=
0
...
...
This diff is collapsed.
Click to expand it.
src/tosca2doc.py
+
3
−
3
View file @
aa5eb74b
...
...
@@ -14,9 +14,9 @@ PRINT_TRESHOLD = 1
TEMPLATES
=
{}
FNS
=
{
'
VNFD
'
:
'
etsi_nfv_sol001_vnfd_
2_5_1_
types.yaml
'
,
'
NSD
'
:
'
etsi_nfv_sol001_nsd_
2_5_1_
types.yaml
'
,
'
PNFD
'
:
'
etsi_nfv_sol001_pnfd_
2_5_1_
types.yaml
'
'
VNFD
'
:
'
etsi_nfv_sol001_vnfd_types.yaml
'
,
'
NSD
'
:
'
etsi_nfv_sol001_nsd_types.yaml
'
,
'
PNFD
'
:
'
etsi_nfv_sol001_pnfd_types.yaml
'
}
TOSCA_TYPES
=
[
...
...
This diff is collapsed.
Click to expand it.
src/web_app.py
+
25
−
11
View file @
aa5eb74b
#!/bin/python3
import
os
import
shutil
import
tempfile
from
zipfile
import
ZipFile
from
flask
import
Flask
,
flash
,
request
,
redirect
,
url_for
,
send_file
,
render_template
from
flask
import
Flask
,
flash
,
request
,
redirect
,
send_file
,
render_template
,
g
from
werkzeug.utils
import
secure_filename
import
docx
import
tempfile
from
zipfile
import
ZipFile
import
os
import
config
import
tosca2doc
...
...
@@ -25,7 +24,7 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app
.
secret_key
=
'
super secret key
'
app
.
config
[
'
SESSION_TYPE
'
]
=
'
filesystem
'
TOSCA_DEFS
=
[
'
VNFD
'
,
'
NSD
'
,
'
PNFD
'
]
TOSCA_DEFS
=
[
'
VNFD
'
,
'
NSD
'
,
'
PNFD
'
]
def
allowed_file
(
filename
):
'''
...
...
@@ -37,7 +36,10 @@ def allowed_file(filename):
@app.route
(
"
/
"
)
def
hello
():
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
)
'''
Render home page
'''
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
)
@app.route
(
"
/tosca2doc
"
,
methods
=
[
'
POST
'
])
def
mk_tosca2doc
():
...
...
@@ -69,6 +71,9 @@ def mk_tosca2doc():
flash
(
'
No selected file
'
)
return
redirect
(
"
/
"
)
tmp_dir
=
tempfile
.
mkdtemp
()
g
.
tmp_dir
=
tmp_dir
doc
=
docx
.
Document
()
for
tosca_def
in
TOSCA_DEFS
:
...
...
@@ -82,8 +87,10 @@ def mk_tosca2doc():
tosca2doc
.
generate_from_file
(
tosca_def
,
doc
,
filepath
)
doc
.
save
(
'
/tmp/myfile.docx
'
)
return
send_file
(
'
/tmp/myfile.docx
'
)
outfilename
=
os
.
path
.
join
(
tmp_dir
,
'
myfile.docx
'
)
doc
.
save
(
outfilename
)
return
send_file
(
outfilename
)
#return ("No content found")
...
...
@@ -104,6 +111,14 @@ def get_all_yaml_file_paths(directory):
# returning all file paths
return
file_paths
@app.after_request
def
after_request
(
response
):
if
request
.
path
!=
'
/doc2tosca
'
:
return
response
shutil
.
rmtree
(
g
.
tmp_dir
,
ignore_errors
=
True
)
print
(
"
Deleted {}
\n\n
"
.
format
(
g
.
tmp_dir
))
return
response
@app.route
(
"
/doc2tosca
"
,
methods
=
[
'
POST
'
])
def
mk_doc2tosca
():
...
...
@@ -115,8 +130,6 @@ def mk_doc2tosca():
ufiles
=
request
.
files
.
getlist
(
"
file
"
)
# uploaded_file.filename
# uploaded_file.read()
sol001_file
=
ufiles
[
0
]
doc2tosca
.
generate_templates
(
sol001_file
)
...
...
@@ -133,6 +146,7 @@ def mk_doc2tosca():
for
myfile
in
file_paths
:
archive
.
write
(
myfile
,
arcname
=
os
.
path
.
basename
(
myfile
))
g
.
tmp_dir
=
tmp_dir
return
send_file
(
zip_path
,
as_attachment
=
True
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment