+ web_app

This commit is contained in:
oleting
2021-01-14 14:01:02 +01:00
parent f0547890c1
commit b045869591
11 changed files with 21 additions and 20 deletions

5
run.py
View File

@@ -6,10 +6,5 @@
# Gui(theme='DarkGrey11', debug_mode=do_debug) # Gui(theme='DarkGrey11', debug_mode=do_debug)
# Web App
from Web import create_app
app = create_app()
if __name__ == '__main__':
app.run(port=5000 ,debug=True)

7
run_web.py Normal file
View File

@@ -0,0 +1,7 @@
from web_app import create_app
app = create_app()
if __name__ == '__main__':
app.run(port=7467 ,debug=False)

View File

@@ -1,12 +1,12 @@
from flask import Flask from flask import Flask
from Web.config import Config from web_app.config import Config
app = Flask(__name__) app = Flask(__name__)
def create_app(config_class=Config): def create_app(config_class=Config):
app.config.from_object(config_class) app.config.from_object(config_class)
from Web.main.routes import main from web_app.main.routes import main
app.register_blueprint(main) app.register_blueprint(main)

View File

@@ -1,3 +1,2 @@
class Config(): class Config():
SECRET_KEY = '4542bae72a9fefada779b8c3fc68a826' SECRET_KEY = '4542bae72a9fefada779b8c3fc68a826'
UPLOAD_FOLDER = '/path/to/the/uploads'

View File

@@ -1,6 +1,6 @@
from flask.helpers import send_file from flask.helpers import send_file
from flask import render_template, abort, flash, Blueprint from flask import render_template, abort, flash, Blueprint
from Web.main.forms import UploadJavaForm from web_app.main.forms import UploadJavaForm
from random import randint from random import randint
import shutil import shutil
import secrets import secrets
@@ -12,21 +12,19 @@ from interpreter.NassiShneidermann import NassiShneidermanDiagram, OB
main = Blueprint('main', __name__) main = Blueprint('main', __name__)
def deleteFile(path): def deleteFilesInFolder(path):
file_list = os.listdir(path) file_list = os.listdir(path)
for f in file_list: for f in file_list:
try: try:
os.remove(path + '/' +f) os.remove(path + '/' +f)
print("remove " + f) # print("remove " + f)
except: except:
print("fail to remove " + f) try:
shutil.rmtree(path + '/' + f)
# print("remove " + f)
except:
logging.error("fail to remove " + f)
def deleteFolder(path):
try:
shutil.rmtree(path)
print("remove " + path)
except:
print("fail to remove " + path)
def javaDatei(form_file): def javaDatei(form_file):
try: try:
@@ -48,6 +46,7 @@ def generator():
if form.validate_on_submit(): if form.validate_on_submit():
if form.java.data: if form.java.data:
deleteFilesInFolder(os.path.join(os.path.abspath(os.path.join('Web', os.pardir)), f'../tmp/output/'))
input_path = javaDatei(form.java.data) input_path = javaDatei(form.java.data)
output_path = os.path.join(os.path.abspath(os.path.join('Web', os.pardir)), './tmp/input') output_path = os.path.join(os.path.abspath(os.path.join('Web', os.pardir)), './tmp/input')
outputname = str(randint(0, 100) ) outputname = str(randint(0, 100) )
@@ -74,10 +73,11 @@ def generator():
zip_path = os.path.join(os.path.abspath(os.path.join('Web', os.pardir)), f'../tmp/output/{outputname}') zip_path = os.path.join(os.path.abspath(os.path.join('Web', os.pardir)), f'../tmp/output/{outputname}')
shutil.make_archive(zip_path, 'zip', output_directory) shutil.make_archive(zip_path, 'zip', output_directory)
deleteFolder(output_path)
deleteFilesInFolder(output_path)
return send_file(zip_path + '.zip', as_attachment=True) return send_file(zip_path + '.zip', as_attachment=True)
return render_template('upload.html', title='Upload', legend='Upload', form=form ) return render_template('upload.html', title='Upload', legend='Upload', form=form )