From f52414d2f9444959bbd92dd48bc82421774b86fd Mon Sep 17 00:00:00 2001 From: njfio <7220+njfio@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:54:39 -0400 Subject: [PATCH] updated frontend flask code and html, test 1 --- front_end_index.html | 184 ++++++++++++++++++++++++++++++++++--------- frontend.py | 61 ++++++++++++-- 2 files changed, 202 insertions(+), 43 deletions(-) diff --git a/front_end_index.html b/front_end_index.html index 745579c..aad0b0d 100644 --- a/front_end_index.html +++ b/front_end_index.html @@ -4,13 +4,34 @@ Fluent Web Frontend \ No newline at end of file diff --git a/frontend.py b/frontend.py index fae2c75..1929687 100644 --- a/frontend.py +++ b/frontend.py @@ -2,6 +2,7 @@ import subprocess import logging import os +import tempfile app = Flask(__name__, static_folder='frontend') @@ -11,18 +12,68 @@ def index(): @app.route('/execute', methods=['POST']) def execute_fluent(): - command = request.json['command'] - engine = request.json['engine'] # Get engine from request + data = request.json + + # Handle config and pipeline files + config_file = create_temp_file(data.get('config'), '.json') + pipeline_file = create_temp_file(data.get('pipelineFile'), '.yaml') + + fluent_command = ["fluent"] + + # Add engine + fluent_command.append(data['engine']) + + # Add request (optional) + if data.get('request'): + fluent_command.append(data['request']) + + # Add options + add_option(fluent_command, '-c', config_file) + for override in data.get('override', '').split(): + add_option(fluent_command, '-o', override) + add_option(fluent_command, '-a', data.get('additionalContextFile')) + add_flag(fluent_command, '--upsert', data.get('upsert')) + add_option(fluent_command, '-i', data.get('input')) + add_option(fluent_command, '-t', data.get('metadata')) + add_option(fluent_command, '-l', data.get('uploadImageFile')) + add_option(fluent_command, '-d', data.get('downloadMedia')) + add_flag(fluent_command, '-p', data.get('parseCode')) + add_flag(fluent_command, '-x', data.get('executeOutput')) + add_flag(fluent_command, '-m', data.get('markdown')) + add_option(fluent_command, '--generate-cypher', data.get('generateCypher')) + + # Handle pipeline command + if pipeline_file: + fluent_command.extend(['pipeline', '--file', pipeline_file]) + add_option(fluent_command, '--input', data.get('pipelineInput')) + add_flag(fluent_command, '--json-output', data.get('jsonOutput')) + add_option(fluent_command, '--run-id', data.get('runId')) + add_flag(fluent_command, '--force-fresh', data.get('forceFresh')) try: - # Construct the fluent command with the engine - fluent_command = ["fluent", engine, f"{command}"] logging.debug(f"Executing command: {fluent_command}") - output = subprocess.check_output(fluent_command,).decode('utf-8') + output = subprocess.check_output(fluent_command).decode('utf-8') return jsonify({'output': output}) except subprocess.CalledProcessError as e: return jsonify({'error': str(e)}) +# Helper functions to add options/flags to the command list +def add_option(command_list, flag, value): + if value: + command_list.extend([flag, value]) + +def add_flag(command_list, flag, is_set): + if is_set: + command_list.append(flag) + +# Helper function to create temporary files +def create_temp_file(content, extension): + if content: + with tempfile.NamedTemporaryFile(delete=False, suffix=extension) as temp: + temp.write(content.encode('utf-8')) + return temp.name + return None + if __name__ == '__main__': logging.debug("Flask app starting...") logging.debug(f"Working directory: {os.getcwd()}")