Skip to content

Commit

Permalink
Ref #8 Generate Flask application. Uploading file added.
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Kaźmierczyk <kazm@ibm.com>
  • Loading branch information
kkazmierczyk committed Oct 30, 2024
1 parent 29c552c commit b60e879
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
42 changes: 42 additions & 0 deletions javacore_analyser_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright IBM Corp. 2024 - 2024
# SPDX-License-Identifier: Apache-2.0
#
import os
import tempfile

# Assisted by WCA@IBM
# Latest GenAI contribution: ibm/granite-20b-code-instruct-v2
from flask import Flask, render_template, request

import javacore_analyzer

REPORTS_DIR = "reports"

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload_file():
# Create a temporary directory to store uploaded files
javacores_temp_dir = tempfile.TemporaryDirectory()
javacores_temp_dir_name = javacores_temp_dir.name

# Get the list of files from webpage
files = request.files.getlist("files")

input_files = []
# Iterate for each file in the files List, and Save them
for file in files:
file_name = os.path.join(javacores_temp_dir_name, file.filename)
file.save(file_name)
input_files.append(file_name)

# Process the uploaded file
javacore_analyzer.process_javacores_and_generate_report_data(input_files, REPORTS_DIR)

if __name__ == '__main__':
app.run(debug=True)
4 changes: 1 addition & 3 deletions javacore_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ def generate_javecore_set_data(files):

# Location when we store extracted archive or copied javacores files
javacores_temp_dir = tempfile.TemporaryDirectory()
# It is strange but sometimes the temp directory contains the content from previous run
# javacores_temp_dir.cleanup()

javacores_temp_dir_name = javacores_temp_dir.name
for file in files:
# file = file.strip() # Remove leading or trailing space in file path
if os.path.isdir(file):
shutil.copytree(file, javacores_temp_dir_name, dirs_exist_ok=True)
else:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
flask
dicttoxml
py7zr
lxml
Expand Down
17 changes: 17 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<!--
// Assisted by WCA@IBM
// Latest GenAI contribution: ibm/granite-20b-code-instruct-v2
-->
<html>
<head>
<title>Upload Files</title>
</head>
<body>
<h1>Upload Files</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="files" multiple>
<input type="submit" value="Upload">
</form>
</body>
</html>

0 comments on commit b60e879

Please sign in to comment.