diff --git a/src/config.py b/src/config.py index bc4ffb3d667e42db929fdbaee09531b84e76c634..4d38941470fec9a731bb112324ffdaad0cdf149e 100644 --- a/src/config.py +++ b/src/config.py @@ -1 +1 @@ -VERSION = "0.0.2" +VERSION = "0.0.3" diff --git a/src/doc2tosca.py b/src/doc2tosca.py index cd061f2144221bd992050b4eca0d7198303b4af5..1322b35bbf342d3ca2baf03c7213edb6bb506822 100644 --- a/src/doc2tosca.py +++ b/src/doc2tosca.py @@ -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 = "v2.6.1" -allowed_versions = ["2.6.1","2.7.1"] +allowed_versions = ["v2.6.1","v2.6.3", "v2.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( diff --git a/src/templates/home.html b/src/templates/home.html index 4c3563e937aa6f7bf42f9f2b9d81ff68d499ae6a..294e2806f57985b4b7bfd6d433baf49071b6316a 100644 --- a/src/templates/home.html +++ b/src/templates/home.html @@ -1,4 +1,4 @@ -<!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" /> diff --git a/src/test_after_request.py b/src/test_after_request.py new file mode 100644 index 0000000000000000000000000000000000000000..aefb24d83815b1ad9ca7743a1b3ebe1e522e5247 --- /dev/null +++ b/src/test_after_request.py @@ -0,0 +1,33 @@ +#!/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) diff --git a/src/web_app.py b/src/web_app.py index 1bc36a4147d530438f607b8365df5b3a225788a5..60c993e55b49435c39693e70551f720902a1a2f6 100644 --- a/src/web_app.py +++ b/src/web_app.py @@ -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)