|
@@ -1,128 +1,128 @@
|
|
|
-from flask import request, render_template, send_from_directory, jsonify, send_file, abort
|
|
|
-from app import app, forms
|
|
|
-from uuid import uuid4
|
|
|
-import os
|
|
|
-
|
|
|
-
|
|
|
-@app.route('/', methods=['GET', 'POST'])
|
|
|
-def index():
|
|
|
- #
|
|
|
- # web view to upload data files
|
|
|
- #
|
|
|
-
|
|
|
- form = forms.UploadForm()
|
|
|
-
|
|
|
- # get validated form
|
|
|
- if form.validate_on_submit():
|
|
|
- # save file
|
|
|
- uuid = str(uuid4())
|
|
|
- form.file.data.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
- app.logger.info(f'Uploaded file {uuid}')
|
|
|
-
|
|
|
- return render_template('upload.html', form=form, uuid=uuid, filename=form.file.data.filename)
|
|
|
-
|
|
|
- return render_template('upload.html', form=form)
|
|
|
-
|
|
|
-@app.route('/save', methods=['POST'])
|
|
|
-def save_file():
|
|
|
- #
|
|
|
- # save uploaded file and return corresponding UUID
|
|
|
- #
|
|
|
-
|
|
|
- # check for file in request
|
|
|
- file = request.files.get('dataFile')
|
|
|
-
|
|
|
- if file is None:
|
|
|
- app.logger.error('Request does not contain dataFile')
|
|
|
- return jsonify({'error': 'Request does not contain dataFile'}), 400
|
|
|
-
|
|
|
- # save file
|
|
|
- uuid = str(uuid4())
|
|
|
- file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
- app.logger.info(f'Uploaded file {uuid}')
|
|
|
-
|
|
|
- return jsonify({'uuid': uuid}), 200
|
|
|
-
|
|
|
-@app.route('/update/<string:uuid>', methods=['POST'])
|
|
|
-def update_file(uuid):
|
|
|
- #
|
|
|
- # update UUID file by uploaded one and return corresponding UUID
|
|
|
- #
|
|
|
-
|
|
|
- # check for file in request
|
|
|
- file = request.files.get('dataFile')
|
|
|
-
|
|
|
- if file is None:
|
|
|
- app.logger.error('Request does not contain dataFile')
|
|
|
- return jsonify({'error': 'Request does not contain dataFile'}), 400
|
|
|
-
|
|
|
- # update file
|
|
|
- file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
- app.logger.info(f'Updated file {uuid}')
|
|
|
-
|
|
|
- return jsonify({'uuid': uuid}), 200
|
|
|
-
|
|
|
-@app.route('/upload/<string:uuid>', methods=['POST'])
|
|
|
-def upload_files(uuid):
|
|
|
- #
|
|
|
- # save uploaded files to directory 'UUID'
|
|
|
- #
|
|
|
-
|
|
|
- if not request.files:
|
|
|
- app.logger.error('Request does not contain files to upload')
|
|
|
- return jsonify({'error': 'Request does not contain files to upload'}), 400
|
|
|
-
|
|
|
- # create upload dir
|
|
|
- upload_dir = os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid)
|
|
|
- os.makedirs(upload_dir, exist_ok=True)
|
|
|
- app.logger.info(f'Created directory: {upload_dir}')
|
|
|
-
|
|
|
- # save files
|
|
|
- upload_response = {}
|
|
|
- for filename, file in request.files.items():
|
|
|
- file.save(os.path.join(upload_dir, filename))
|
|
|
- upload_response['filename'] = 'OK'
|
|
|
- app.logger.info(f'Uploaded file {filename} to {upload_dir}')
|
|
|
-
|
|
|
- return jsonify({'uuid': uuid, 'files': upload_response}), 200
|
|
|
-
|
|
|
-@app.route('/get/<string:uuid>/<string:file>')
|
|
|
-def get_logfile(uuid, file):
|
|
|
- #
|
|
|
- # retrieve files from folder UUID
|
|
|
- #
|
|
|
-
|
|
|
- # log file
|
|
|
- if file == app.config['TESTRUN_LOGFILE']:
|
|
|
- app.logger.info(f'Requested logfile from {uuid}')
|
|
|
- return send_file(
|
|
|
- '/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_LOGFILE'])),
|
|
|
- mimetype='text/plain',
|
|
|
- attachment_filename=f'{uuid}.log',
|
|
|
- )
|
|
|
-
|
|
|
- # redults file
|
|
|
- elif file == app.config['TESTRUN_RESULTS']:
|
|
|
- app.logger.info(f'Requested output file from {uuid}')
|
|
|
- return send_file(
|
|
|
- '/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_RESULTS'])),
|
|
|
- attachment_filename=f'{uuid}.xlsx',
|
|
|
- as_attachment=True,
|
|
|
- )
|
|
|
-
|
|
|
- abort(404)
|
|
|
-
|
|
|
-
|
|
|
-@app.route('/get/<string:uuid>')
|
|
|
-def get_file(uuid):
|
|
|
- #
|
|
|
- # retrieve a file by UUID
|
|
|
- #
|
|
|
-
|
|
|
- app.logger.info(f'Requested file {uuid}')
|
|
|
- #return send_from_directory(app.config['UPLOAD_FOLDER'], uuid)
|
|
|
- return send_file(
|
|
|
- '/'.join((app.config['UPLOAD_FOLDER'], uuid)),
|
|
|
- attachment_filename=f'{uuid}.xlsx',
|
|
|
- as_attachment=True,
|
|
|
- )
|
|
|
+from flask import request, render_template, send_from_directory, jsonify, send_file, abort
|
|
|
+from app import app, forms
|
|
|
+from uuid import uuid4
|
|
|
+import os
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/', methods=['GET', 'POST'])
|
|
|
+def index():
|
|
|
+ #
|
|
|
+ # web view to upload data files
|
|
|
+ #
|
|
|
+
|
|
|
+ form = forms.UploadForm()
|
|
|
+
|
|
|
+ # get validated form
|
|
|
+ if form.validate_on_submit():
|
|
|
+ # save file
|
|
|
+ uuid = str(uuid4())
|
|
|
+ form.file.data.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
+ app.logger.info(f'Uploaded file {uuid}')
|
|
|
+
|
|
|
+ return render_template('upload.html', form=form, uuid=uuid, filename=form.file.data.filename)
|
|
|
+
|
|
|
+ return render_template('upload.html', form=form)
|
|
|
+
|
|
|
+@app.route('/save', methods=['POST'])
|
|
|
+def save_file():
|
|
|
+ #
|
|
|
+ # save uploaded file and return corresponding UUID
|
|
|
+ #
|
|
|
+
|
|
|
+ # check for file in request
|
|
|
+ file = request.files.get('dataFile')
|
|
|
+
|
|
|
+ if file is None:
|
|
|
+ app.logger.error('Request does not contain dataFile')
|
|
|
+ return jsonify({'error': 'Request does not contain dataFile'}), 400
|
|
|
+
|
|
|
+ # save file
|
|
|
+ uuid = str(uuid4())
|
|
|
+ file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
+ app.logger.info(f'Uploaded file {uuid}')
|
|
|
+
|
|
|
+ return jsonify({'uuid': uuid}), 200
|
|
|
+
|
|
|
+@app.route('/update/<string:uuid>', methods=['POST'])
|
|
|
+def update_file(uuid):
|
|
|
+ #
|
|
|
+ # update UUID file by uploaded one and return corresponding UUID
|
|
|
+ #
|
|
|
+
|
|
|
+ # check for file in request
|
|
|
+ file = request.files.get('dataFile')
|
|
|
+
|
|
|
+ if file is None:
|
|
|
+ app.logger.error('Request does not contain dataFile')
|
|
|
+ return jsonify({'error': 'Request does not contain dataFile'}), 400
|
|
|
+
|
|
|
+ # update file
|
|
|
+ file.save(os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid))
|
|
|
+ app.logger.info(f'Updated file {uuid}')
|
|
|
+
|
|
|
+ return jsonify({'uuid': uuid}), 200
|
|
|
+
|
|
|
+@app.route('/upload/<string:uuid>', methods=['POST'])
|
|
|
+def upload_files(uuid):
|
|
|
+ #
|
|
|
+ # save uploaded files to directory 'UUID'
|
|
|
+ #
|
|
|
+
|
|
|
+ if not request.files:
|
|
|
+ app.logger.error('Request does not contain files to upload')
|
|
|
+ return jsonify({'error': 'Request does not contain files to upload'}), 400
|
|
|
+
|
|
|
+ # create upload dir
|
|
|
+ upload_dir = os.path.join(os.path.dirname(__file__), app.config['UPLOAD_FOLDER'], uuid)
|
|
|
+ os.makedirs(upload_dir, exist_ok=True)
|
|
|
+ app.logger.info(f'Created directory: {upload_dir}')
|
|
|
+
|
|
|
+ # save files
|
|
|
+ upload_response = {}
|
|
|
+ for filename, file in request.files.items():
|
|
|
+ file.save(os.path.join(upload_dir, filename))
|
|
|
+ upload_response['filename'] = 'OK'
|
|
|
+ app.logger.info(f'Uploaded file {filename} to {upload_dir}')
|
|
|
+
|
|
|
+ return jsonify({'uuid': uuid, 'files': upload_response}), 200
|
|
|
+
|
|
|
+@app.route('/get/<string:uuid>/<string:file>')
|
|
|
+def get_logfile(uuid, file):
|
|
|
+ #
|
|
|
+ # retrieve files from folder UUID
|
|
|
+ #
|
|
|
+
|
|
|
+ # log file
|
|
|
+ if file == app.config['TESTRUN_LOGFILE']:
|
|
|
+ app.logger.info(f'Requested logfile from {uuid}')
|
|
|
+ return send_file(
|
|
|
+ '/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_LOGFILE'])),
|
|
|
+ mimetype='text/plain',
|
|
|
+ attachment_filename=f'{uuid}.log',
|
|
|
+ )
|
|
|
+
|
|
|
+ # redults file
|
|
|
+ elif file == app.config['TESTRUN_RESULTS']:
|
|
|
+ app.logger.info(f'Requested output file from {uuid}')
|
|
|
+ return send_file(
|
|
|
+ '/'.join((app.config['UPLOAD_FOLDER'], uuid, app.config['TESTRUN_RESULTS'])),
|
|
|
+ attachment_filename=f'{uuid}.xlsx',
|
|
|
+ as_attachment=True,
|
|
|
+ )
|
|
|
+
|
|
|
+ abort(404)
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/get/<string:uuid>')
|
|
|
+def get_file(uuid):
|
|
|
+ #
|
|
|
+ # retrieve a file by UUID
|
|
|
+ #
|
|
|
+
|
|
|
+ app.logger.info(f'Requested file {uuid}')
|
|
|
+ #return send_from_directory(app.config['UPLOAD_FOLDER'], uuid)
|
|
|
+ return send_file(
|
|
|
+ '/'.join((app.config['UPLOAD_FOLDER'], uuid)),
|
|
|
+ attachment_filename=f'{uuid}.xlsx',
|
|
|
+ as_attachment=True,
|
|
|
+ )
|