diff --git a/.gitignore b/.gitignore index 8b2eea3..acc3a63 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ config data cache +__pycache__ +*.pyc diff --git a/readme.md b/readme.md index 01897ae..eb8fdf4 100755 --- a/readme.md +++ b/readme.md @@ -46,3 +46,8 @@ cd src ./app_video.py ``` +or +``` +SANIC_REST_PORT=15080 ./src/app_video.py +``` + diff --git a/src/__pycache__/data_global_elements.cpython-38.pyc b/src/__pycache__/data_global_elements.cpython-38.pyc deleted file mode 100644 index a1ec7e1..0000000 Binary files a/src/__pycache__/data_global_elements.cpython-38.pyc and /dev/null differ diff --git a/src/__pycache__/data_interface.cpython-38.pyc b/src/__pycache__/data_interface.cpython-38.pyc deleted file mode 100644 index b387e94..0000000 Binary files a/src/__pycache__/data_interface.cpython-38.pyc and /dev/null differ diff --git a/src/__pycache__/tools.cpython-38.pyc b/src/__pycache__/tools.cpython-38.pyc deleted file mode 100644 index c390417..0000000 Binary files a/src/__pycache__/tools.cpython-38.pyc and /dev/null differ diff --git a/src/app_video.py b/src/app_video.py index f8cc8e9..c05c3d9 100755 --- a/src/app_video.py +++ b/src/app_video.py @@ -10,6 +10,8 @@ #pip install flask --user #pip install flask_restful --user #pip install python-dateutil --user +#pip install sanic --user +#pip install sanic_simple_swagger --user from sanic import Sanic from sanic import response @@ -30,13 +32,10 @@ import datetime import time, threading import realog.debug as debug -import config import tools import data_interface import data_global_elements -rest_config = config.get_rest_config() - app = Sanic("REST_video") app.config['API_VERSION'] = '1.0.0' @@ -46,7 +45,16 @@ app.config['API_CONTACT_EMAIL'] = "yui.heero@gmail.com" app.config['API_LICENSE_NAME'] = 'MPL 2.0' app.config['API_LICENSE_URL'] = 'https://www.mozilla.org/en-US/MPL/2.0/' app.config['schemes'] = ['http', 'https'] - +if "REST_TMP_DATA" not in app.config.keys(): + app.config['REST_TMP_DATA'] = "tmp" +if "REST_MEDIA_DATA" not in app.config.keys(): + app.config['REST_MEDIA_DATA'] = os.path.join("data", "media") +if "REST_DATA" not in app.config.keys(): + app.config['REST_DATA'] = "data" +if "REST_HOST" not in app.config.keys(): + app.config['REST_HOST'] = "localhost" +if "REST_PORT" not in app.config.keys(): + app.config['REST_PORT'] = "80" app.blueprint(openapi_blueprint) app.blueprint(swagger_blueprint) @@ -65,7 +73,7 @@ async def test(request): def add_interface(_name): - data_global_elements.add_interface(_name, data_interface.DataInterface(_name, os.path.join(tools.get_run_path(), "data", "bdd_" + _name + ".json"))) + data_global_elements.add_interface(_name, data_interface.DataInterface(_name, os.path.join(tools.get_run_path(), app.config['REST_DATA'], "bdd_" + _name + ".json"))) API_TYPE = "type" add_interface(API_TYPE) @@ -358,11 +366,11 @@ def add_data(_app, _name_api): async def streaming(_response): debug.info("streaming " + str(_response)); total_size = 0 - temporary_file = os.path.join(rest_config["tmp_data"], str(tmp_value) + ".tmp") - if not os.path.exists(rest_config["tmp_data"]): - os.makedirs(rest_config["tmp_data"]) - if not os.path.exists(rest_config["data_media"]): - os.makedirs(rest_config["data_media"]) + temporary_file = os.path.join(app.config['REST_TMP_DATA'], str(tmp_value) + ".tmp") + if not os.path.exists(app.config['REST_TMP_DATA']): + os.makedirs(app.config['REST_TMP_DATA']) + if not os.path.exists(app.config['REST_MEDIA_DATA']): + os.makedirs(app.config['REST_MEDIA_DATA']) file_stream = open(temporary_file,"wb") sha1 = hashlib.sha512() while True: @@ -376,7 +384,7 @@ def add_data(_app, _name_api): sha1.update(body) file_stream.close() print("SHA512: " + str(sha1.hexdigest())) - destination_filename = os.path.join(rest_config["data_media"], str(sha1.hexdigest())) + destination_filename = os.path.join(app.config['REST_MEDIA_DATA'], str(sha1.hexdigest())) if os.path.isfile(destination_filename) == True: answer_data = { "size": total_size, @@ -425,9 +433,9 @@ import shutil if __name__ == "__main__": - debug.info("Start REST application: " + str(rest_config["host"]) + ":" + str(rest_config["port"])) + debug.info("Start REST application: " + str(app.config['REST_HOST']) + ":" + str(app.config['REST_PORT'])) app.config.REQUEST_MAX_SIZE=10*1024*1024*1024 - app.run(host=rest_config["host"], port=int(rest_config["port"])) + app.run(host=app.config['REST_HOST'], port=int(app.config['REST_PORT'])) debug.info("END program"); sys.exit(0)