Loading src/config.py +1 −1 Original line number Diff line number Diff line VERSION = "0.0.1" No newline at end of file VERSION = "0.0.2" src/doc2tosca.py +16 −12 Original line number Diff line number Diff line Loading @@ -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} Loading Loading @@ -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 Loading Loading @@ -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']) Loading src/templates/home.html +9 −2 Original line number Diff line number Diff line Loading @@ -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> Loading src/web_app.py +17 −9 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading Loading @@ -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(): Loading Loading @@ -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 Loading @@ -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) Loading Loading
src/config.py +1 −1 Original line number Diff line number Diff line VERSION = "0.0.1" No newline at end of file VERSION = "0.0.2"
src/doc2tosca.py +16 −12 Original line number Diff line number Diff line Loading @@ -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} Loading Loading @@ -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 Loading Loading @@ -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']) Loading
src/templates/home.html +9 −2 Original line number Diff line number Diff line Loading @@ -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> Loading
src/web_app.py +17 −9 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading Loading @@ -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(): Loading Loading @@ -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 Loading @@ -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) Loading