generated from IBM/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #8 Generate Flask application. Uploading file added.
Signed-off-by: Krzysztof Kaźmierczyk <kazm@ibm.com>
- Loading branch information
1 parent
29c552c
commit b60e879
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
flask | ||
dicttoxml | ||
py7zr | ||
lxml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |