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
bfe25516
Commit
bfe25516
authored
5 years ago
by
carignani
Browse files
Options
Downloads
Patches
Plain Diff
Parametrized version in doc2tosca
parent
acccb51e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/config.py
+1
-1
1 addition, 1 deletion
src/config.py
src/doc2tosca.py
+16
-12
16 additions, 12 deletions
src/doc2tosca.py
src/templates/home.html
+9
-2
9 additions, 2 deletions
src/templates/home.html
src/web_app.py
+17
-9
17 additions, 9 deletions
src/web_app.py
with
43 additions
and
24 deletions
src/config.py
+
1
−
1
View file @
bfe25516
VERSION
=
"
0.0.1
"
\ No newline at end of file
VERSION
=
"
0.0.2
"
This diff is collapsed.
Click to expand it.
src/doc2tosca.py
+
16
−
12
View file @
bfe25516
...
...
@@ -16,6 +16,8 @@ BASE_FILENAME = "generated_etsi_nfv_sol001_{}_types.yaml"
TOSCA_VERSION
=
"
tosca_simple_yaml_1_2
"
SPEC_VERSION
=
"
2.6.1
"
allowed_versions
=
[
"
2.6.1
"
,
"
2.7.1
"
]
MODEL_NAMES
=
[
'
vnfd
'
,
'
nsd
'
,
'
pnfd
'
,
'
common
'
]
HDR
=
'''
tosca_definitions_version: {tosca_version}
...
...
@@ -141,36 +143,39 @@ def generate_tables_between(a_id, b_id, content, buf):
print
(
"
Regex != 1
"
)
return
definitions_count
def
dump_header
(
model_name
,
buf
,
imports
=
None
):
def
dump_header
(
model_name
,
buf
,
spec_version
=
SPEC_VERSION
,
imports
=
None
):
'''
Writes the header to the file for a specific model
'''
buf
.
write
(
HDR
.
format
(
tosca_version
=
TOSCA_VERSION
,
model
=
model_name
,
spec_version
=
SPEC_VERSION
,
spec_version
=
spec_version
,
imports
=
imports
))
MODELS
=
{}
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
)
)
def
generate_templates
(
filename
):
def
generate_templates
(
filename
,
spec_version
=
SPEC_VERSION
):
'''
Takes a filename or file object and loads the definition into the MODELS dictionary
'''
if
isinstance
(
filename
,
str
):
print
(
"
Opening
"
+
filename
)
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
)
)
sol_001
=
docx
.
Document
(
filename
)
for
m
in
MODELS
:
dump_header
(
MODELS
[
m
][
'
name
'
],
MODELS
[
m
][
'
buf
'
],
MODELS
[
m
][
'
imports
'
])
dump_header
(
MODELS
[
m
][
'
name
'
],
MODELS
[
m
][
'
buf
'
],
spec_version
,
MODELS
[
m
][
'
imports
'
])
p_id
=
0
...
...
@@ -211,7 +216,6 @@ def print_to_files(prefix=None):
Prefix is a path to a folder to work into
'''
for
m
in
MODELS
:
if
prefix
!=
None
:
MODELS
[
m
][
'
fn
'
]
=
os
.
path
.
join
(
prefix
,
MODELS
[
m
][
'
fn
'
])
...
...
This diff is collapsed.
Click to expand it.
src/templates/home.html
+
9
−
2
View file @
bfe25516
...
...
@@ -74,9 +74,16 @@ For any other inquiry, contact <a href="mailto:cti_support@etsi.org">ETSI CTI</a
<center>
<a
href=
"doc2tosca-info"
>
Details
</a>
</center>
<form
action=
"doc2tosca"
method=
"post"
enctype=
"multipart/form-data"
>
<form
action=
"doc2tosca"
id=
"doc2tosca-form"
name=
"doc2tosca-form"
method=
"post"
enctype=
"multipart/form-data"
>
Docx file:
<br
/>
<input
type=
"file"
name=
"file"
/><br
/><br
/>
<input
type=
"file"
name=
"file"
/></br></br>
Version:
<select
class=
"form-control form-control-sm"
form=
"doc2tosca-form"
name=
"doc-version"
>
{% for version in doc_allowed_versions %}
<option
value=
"{{version}}"
>
{{version}}
</option>
{% endfor %}
</select>
<br
/><br
/>
<center>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"Upload"
/>
</center>
...
...
This diff is collapsed.
Click to expand it.
src/web_app.py
+
17
−
9
View file @
bfe25516
...
...
@@ -20,10 +20,8 @@ class ReverseProxied(object):
self
.
script_name
=
script_name
self
.
scheme
=
scheme
self
.
server
=
server
print
(
"
Reverse Proxy set up
"
)
def
__call__
(
self
,
environ
,
start_response
):
print
(
"
ReverseProxy called
"
)
script_name
=
environ
.
get
(
'
HTTP_X_SCRIPT_NAME
'
,
''
)
or
self
.
script_name
if
script_name
:
environ
[
'
SCRIPT_NAME
'
]
=
script_name
...
...
@@ -34,9 +32,6 @@ class ReverseProxied(object):
if
scheme
:
environ
[
'
wsgi.url_scheme
'
]
=
scheme
server
=
environ
.
get
(
'
HTTP_X_FORWARDED_HOST
'
,
''
)
or
self
.
server
print
(
'
HTTP_X_FORWARDED_SERVER
'
+
environ
.
get
(
'
HTTP_X_FORWARDED_SERVER
'
))
print
(
'
HTTP_X_FORWARDED_FOR
'
+
environ
.
get
(
'
HTTP_X_FORWARDED_FOR
'
))
print
(
'
HTTP_X_FORWARDED_HOST
'
+
environ
.
get
(
'
HTTP_X_FORWARDED_HOST
'
))
if
server
:
environ
[
'
HTTP_HOST
'
]
=
server
return
self
.
app
(
environ
,
start_response
)
...
...
@@ -68,7 +63,7 @@ def hello():
'''
Render home page
'''
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
)
return
render_template
(
"
./home.html
"
,
VERSION
=
config
.
VERSION
,
doc_allowed_versions
=
doc2tosca
.
allowed_versions
)
@app.route
(
"
/doc2tosca-info
"
)
def
doc2tosca_info
():
...
...
@@ -158,6 +153,8 @@ def get_all_yaml_file_paths(directory):
def
after_request
(
response
):
if
request
.
path
!=
'
/doc2tosca
'
:
return
response
if
g
.
get
(
'
tmp_dir
'
)
==
None
:
return
response
shutil
.
rmtree
(
g
.
tmp_dir
,
ignore_errors
=
True
)
print
(
"
Deleted {}
\n\n
"
.
format
(
g
.
tmp_dir
))
return
response
...
...
@@ -168,14 +165,25 @@ def mk_doc2tosca():
zip_fn
=
"
tosca_defs.zip
"
if
'
file
'
not
in
request
.
files
:
flash
(
'
No file
part
'
)
return
redirect
(
request
.
url
)
flash
(
'
No file
uploaded
'
)
return
redirect
(
"
/tosca-ie
"
)
ufiles
=
request
.
files
.
getlist
(
"
file
"
)
try
:
print
(
request
.
form
)
doc_version
=
request
.
form
.
get
(
'
doc-version
'
)
except
:
flash
(
"
Something went wrong :/
"
)
return
redirect
(
"
/tosca-ie
"
)
if
doc_version
not
in
doc2tosca
.
allowed_versions
:
flash
(
'
Incorrect doc version selected
'
)
return
redirect
(
"
/tosca-ie
"
)
sol001_file
=
ufiles
[
0
]
doc2tosca
.
generate_templates
(
sol001_file
)
doc2tosca
.
generate_templates
(
sol001_file
,
doc_version
)
tmp_dir
=
tempfile
.
mkdtemp
()
print
(
"
TMP DIR:
"
+
tmp_dir
)
...
...
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