Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop (#132) #169

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/udpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: steps.update.outputs.update == 'true'
with:
source_branch: version-update
destination_branch: master
destination_branch: develop
pr_reviewer: JulienChampagnol
github_token: ${{ secrets.TOKEN }}

25 changes: 0 additions & 25 deletions GeodeObjects.py

This file was deleted.

23 changes: 19 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import flask_cors
import time

import blueprint_fileconverter
import blueprint_validitychecker
import blueprint_file_converter
import blueprint_validity_checker
import blueprint_crs_converter
import blueprint_ID

import functions

from werkzeug.exceptions import HTTPException


if os.path.isfile('./.env'):
basedir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -63,14 +66,26 @@ def kill_task():
MINUTES_BEFORE_TIMEOUT = float(app.config.get('MINUTES_BEFORE_TIMEOUT'))
SECONDS_BETWEEN_SHUTDOWNS = float(app.config.get('SECONDS_BETWEEN_SHUTDOWNS'))

app.register_blueprint(blueprint_fileconverter.fileconverter_routes, url_prefix=f'/{ID}/fileconverter')
app.register_blueprint(blueprint_validitychecker.validitychecker_routes, url_prefix=f'/{ID}/validitychecker')
app.register_blueprint(blueprint_file_converter.file_converter_routes, url_prefix=f'/{ID}/file_converter')
app.register_blueprint(blueprint_validity_checker.validity_checker_routes, url_prefix=f'/{ID}/validity_checker')
app.register_blueprint(blueprint_crs_converter.crs_converter_routes, url_prefix=f'/{ID}/crs_converter')
app.register_blueprint(blueprint_ID.ID_routes, url_prefix=f'/{ID}')

if FLASK_DEBUG == False:
functions.set_interval(kill_task, SECONDS_BETWEEN_SHUTDOWNS)
flask_cors.CORS(app, origins=ORIGINS)

@app.errorhandler(HTTPException)
def handle_exception(e):
response = e.get_response()
response.data = flask.json.dumps({
"code": e.code,
"name": e.name,
"description": e.description,
})
response.content_type = "application/json"
return response

@app.route('/tools/createbackend', methods=['POST'])
def create_backend():
return flask.make_response({"ID": str("123456")}, 200)
Expand Down
143 changes: 143 additions & 0 deletions blueprint_crs_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import shutil
import flask
import flask_cors
import os
import werkzeug
import functions
import zipfile
import geode_objects


crs_converter_routes = flask.Blueprint('crs_converter_routes', __name__)
flask_cors.CORS(crs_converter_routes)


@crs_converter_routes.before_request
def before_request():
functions.create_lock_file()

@crs_converter_routes.teardown_request
def teardown_request(exception):
functions.remove_lock_file()
functions.create_time_file()

@crs_converter_routes.route('/versions', methods=['GET'])
def crs_converter_versions():
list_packages = ['OpenGeode-core', 'OpenGeode-IO', 'OpenGeode-Geosciences', 'OpenGeode-GeosciencesIO']

return flask.make_response({'versions': functions.get_versions(list_packages)}, 200)

@crs_converter_routes.route('/allowed_files', methods=['GET'])
def crs_converter_allowed_files():
extensions = functions.list_all_input_extensions()

return {'status': 200, 'extensions': extensions}

@crs_converter_routes.route('/allowed_objects', methods=['POST'])
def crs_converter_allowed_objects():
filename = flask.request.form.get('filename')
if filename is None:
return flask.make_response({'error_message': 'No file sent'}, 400)
file_extension = os.path.splitext(filename)[1][1:]
allowed_objects = functions.list_objects(file_extension)

return flask.make_response({'allowed_objects': allowed_objects}, 200)

@crs_converter_routes.route('/geographic_coordinate_systems', methods=['POST'])
def crs_converter_geographic_coordinate_systems():
geode_object = flask.request.form.get('geode_object')
if geode_object is None:
return flask.make_response({'error_message': 'No geode_object sent'}, 400)

infos = functions.get_geographic_coordinate_systems(geode_object)
crs_list = []

for info in infos:
crs = {}
crs['name'] = info.name
crs['code'] = info.code
crs['authority'] = info.authority
crs_list.append(crs)

return flask.make_response({'crs_list': crs_list}, 200)

@crs_converter_routes.route('/output_file_extensions', methods=['POST'])
def crs_converter_output_file_extensions():
geode_object = flask.request.form.get('geode_object')
if geode_object is None:
return flask.make_response({'error_message': 'No geode_object sent'}, 400)
output_file_extensions = functions.list_output_file_extensions(geode_object)

return flask.make_response({'output_file_extensions': output_file_extensions}, 200)

@crs_converter_routes.route('/convert_file', methods=['POST'])
async def crs_converter_convert_file():
UPLOAD_FOLDER = flask.current_app.config['UPLOAD_FOLDER']
geode_object= flask.request.form.get('geode_object')
file = flask.request.form.get('file')
filename = flask.request.form.get('filename')
filesize = flask.request.form.get('filesize')
input_crs_authority = flask.request.form.get('input_crs_authority')
input_crs_code = flask.request.form.get('input_crs_code')
input_crs_name = flask.request.form.get('input_crs_name')
output_crs_authority = flask.request.form.get('output_crs_authority')
output_crs_code = flask.request.form.get('output_crs_code')
output_crs_name = flask.request.form.get('output_crs_name')
extension = flask.request.form.get('extension')

if geode_object is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No geode_object sent' }, 400)
if file is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No file sent' }, 400)
if filename is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No filename sent' }, 400)
if filesize is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No filesize sent' }, 400)
if input_crs_authority is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No input_crs_authority sent' }, 400)
if input_crs_code is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No input_crs_code sent' }, 400)
if input_crs_name is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No input_crs_name sent' }, 400)
if output_crs_authority is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No output_crs_authority sent' }, 400)
if output_crs_code is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No output_crs_code sent' }, 400)
if output_crs_name is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No output_crs_name sent' }, 400)
if extension is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No extension sent' }, 400)

input_crs = {
'authority': input_crs_authority,
'code': input_crs_code,
'name': input_crs_name
}

output_crs = {
'authority': output_crs_authority,
'code': output_crs_code,
'name': output_crs_name
}

uploaded_file = functions.upload_file(file, filename, UPLOAD_FOLDER, filesize)
if not uploaded_file:
flask.make_response({ 'name': 'Internal Server Error','description': 'File not uploaded' }, 500)

secure_filename = werkzeug.utils.secure_filename(filename)
file_path = os.path.join(UPLOAD_FOLDER, secure_filename).replace('\\','/')
data = geode_objects.objects_list()[geode_object]['load'](file_path)
strict_file_name = os.path.splitext(secure_filename)[0]
new_file_name = strict_file_name + '.' + extension

functions.asign_geographic_coordinate_system_info(geode_object, data, input_crs)
functions.convert_geographic_coordinate_system_info(geode_object, data, output_crs)

geode_objects.objects_list()[geode_object]['save'](data, os.path.join(UPLOAD_FOLDER, new_file_name))

response = flask.send_from_directory(directory = UPLOAD_FOLDER, path = new_file_name, as_attachment = True, mimetype = 'application/octet-binary')
response.headers['new-file-name'] = new_file_name
response.headers['Access-Control-Expose-Headers'] = 'new-file-name'

return response

117 changes: 117 additions & 0 deletions blueprint_file_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import shutil
import flask
import flask_cors
import os
import werkzeug
import functions
import zipfile

file_converter_routes = flask.Blueprint('file_converter_routes', __name__)
flask_cors.CORS(file_converter_routes)


@file_converter_routes.before_request
def before_request():
functions.create_lock_file()

@file_converter_routes.teardown_request
def teardown_request(exception):
functions.remove_lock_file()
functions.create_time_file()

@file_converter_routes.route('/versions', methods=['GET'])
def file_converter_versions():
list_packages = ['OpenGeode-core', 'OpenGeode-IO', 'OpenGeode-Geosciences', 'OpenGeode-GeosciencesIO']

return flask.make_response({'versions': functions.get_versions(list_packages)}, 200)

@file_converter_routes.route('/allowed_files', methods=['GET'])
def file_converter_allowed_files():
extensions = functions.list_all_input_extensions()

return {'status': 200, 'extensions': extensions}

@file_converter_routes.route('/allowed_objects', methods=['POST'])
def file_converter_allowed_objects():
filename = flask.request.form.get('filename')
if filename is None:
return flask.make_response({'error_message': 'No file sent'}, 400)
file_extension = os.path.splitext(filename)[1][1:]
allowed_objects = functions.list_objects(file_extension)

return flask.make_response({'allowed_objects': allowed_objects}, 200)

@file_converter_routes.route('/output_file_extensions', methods=['POST'])
def file_converter_output_file_extensions():
geode_object = flask.request.form.get('geode_object')
if geode_object is None:
return flask.make_response({'error_message': 'No geode_object sent'}, 400)
list = functions.list_output_file_extensions(geode_object)

return flask.make_response({'output_file_extensions': list}, 200)

@file_converter_routes.route('/convert_file', methods=['POST'])
async def file_converter_convert_file():
UPLOAD_FOLDER = flask.current_app.config['UPLOAD_FOLDER']
geode_object = flask.request.form.get('geode_object')
file = flask.request.form.get('file')
filename = flask.request.form.get('filename')
filesize = flask.request.form.get('filesize')
extension = flask.request.form.get('extension')

if geode_object is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No geode_object sent' }, 400)
if file is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No file sent' }, 400)
if filename is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No filename sent' }, 400)
if filesize is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No filesize sent' }, 400)
if extension is None:
return flask.make_response({ 'name': 'Bad Request','description': 'No extension sent' }, 400)

uploaded_file = functions.upload_file(file, filename, UPLOAD_FOLDER, filesize)
if not uploaded_file:
flask.make_response({ 'name': 'Internal Server Error','description': 'File not uploaded' }, 500)

secure_filename = werkzeug.utils.secure_filename(filename)
file_path = os.path.join(UPLOAD_FOLDER, secure_filename)
data = functions.geode_objects.objects_list()[geode_object]['load'](file_path)
strict_file_name = os.path.splitext(secure_filename)[0]
new_file_name = strict_file_name + '.' + extension

sub_folder = f'{UPLOAD_FOLDER}/{strict_file_name}/'
if os.path.exists(sub_folder):
shutil.rmtree(sub_folder)

functions.geode_objects.objects_list()[geode_object]['save'](data, os.path.join(UPLOAD_FOLDER, new_file_name))
mimetype = 'application/octet-binary'

list_exceptions = ['triangle', 'vtm']
if extension in list_exceptions:
if extension == 'triangle':
os.mkdir(sub_folder)
os.chdir(sub_folder)
generated_files = f'{UPLOAD_FOLDER}/{strict_file_name}'
shutil.move(generated_files + '.ele', sub_folder)
shutil.move(generated_files + '.neigh', sub_folder)
shutil.move(generated_files + '.node', sub_folder)
os.chdir('..')
elif extension == 'vtm':
generated_files = f'{UPLOAD_FOLDER}/{strict_file_name}'
shutil.move(generated_files + '.vtm', sub_folder)
shutil.move(strict_file_name, subFolder)
new_file_name = strict_file_name + '.zip'
mimetype = 'application/zip'
with zipfile.ZipFile(f'{UPLOAD_FOLDER}/{new_file_name}', 'w') as zipObj:
for folder_name, sub_folders, file_names in os.walk(sub_folder):
for filename in file_names:
file_path = os.path.join(folder_name, filename)
zipObj.write(file_path, os.path.basename(file_path))

response = flask.send_from_directory(directory=UPLOAD_FOLDER, path=new_file_name, as_attachment=True, mimetype = mimetype)
response.headers['new-file-name'] = new_file_name
response.headers['Access-Control-Expose-Headers'] = 'new-file-name'

return response

Loading