Loading circe/__init__.py +26 −1 Original line number Diff line number Diff line import os import sys import uuid import tarfile import zipfile from time import sleep version = "0.0.29" Loading Loading @@ -45,6 +47,21 @@ except AssertionError: AUTH_DB_PATH = "{}/auth.db".format(CONFIG["CIRCE_WORKING_DIR"]) def _convert_targz_to_zip(tgz_path: str, zip_path: str): tar_file = tarfile.open(name=tgz_path, mode="r|gz") zip_file = zipfile.ZipFile( file=zip_path, mode="a", compression=zipfile.ZIP_DEFLATED ) for item in tar_file: if item.name: f = tar_file.extractfile(item) fl = f.read() fn = item.name zip_file.writestr(fn, fl) tar_file.close() zip_file.close() @contextmanager def auth_db(readonly=True): """ Loading Loading @@ -196,6 +213,8 @@ async def job_get(request: sanic.request, job_id: str): return sanic.response.HTTPResponse("Accepted", status=202) result_file_path = "{}/done/{}.tar.gz".format(CONFIG["CIRCE_WORKING_DIR"], job_id) if os.path.isfile(result_file_path): if request.args.get("zip", None): pass # convert tar.gz to zip and return zip return await sanic.response.file(result_file_path) # file_stream is slow ? bad chunk size ? # return await sanic.response.file_stream(result_file_path, chunked=False) Loading Loading @@ -319,8 +338,14 @@ if CONFIG["CIRCE_ENABLE_WEB_UI"]: CONFIG["CIRCE_WORKING_DIR"], job_id ) if os.path.isfile(result_file_path): result_zip_path = "{}done/{}.zip".format( CONFIG["CIRCE_WORKING_DIR"], job_id ) # end users prefer zip files over tar.gz if not os.path.isfile(result_zip_path): _convert_targz_to_zip(result_file_path, result_zip_path) return await sanic.response.file( result_file_path, filename="{}.tar.gz".format(job_id) result_zip_path, filename="{}.zip".format(job_id) ) return sanic.response.HTTPResponse("Not Found", status=404) Loading circe/tasks.py +6 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ from requests.exceptions import ConnectionError, HTTPError import logging from inspect import getmembers, isfunction, isclass, signature import sys import os from pythonjsonlogger import jsonlogger import datetime Loading Loading @@ -148,6 +147,12 @@ def do_transformations(uuid: uuid4, job_archive_path: str): ) move(temp_zip_path, final_archive_path) remove_file.schedule((final_archive_path,), delay=3600) # should the web demo UI be used, there might be an additional zip file to remove if CONFIG.get("CIRCE_ENABLE_WEB_UI"): final_zip_archive_path = "{}/done/{}.zip".format( CONFIG["CIRCE_WORKING_DIR"], uuid.hex ) remove_file.schedule((final_zip_archive_path,), delay=3600) if job_description.get("notify_hook", None): try: requests.post( # request is blocking, maybe try xhttp once stable ? Loading setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="circe-CERTIC", version="0.0.32", version="0.0.33", author="Mickaël Desfrênes", author_email="mickael.desfrenes@unicaen.fr", description="Circe server", Loading Loading
circe/__init__.py +26 −1 Original line number Diff line number Diff line import os import sys import uuid import tarfile import zipfile from time import sleep version = "0.0.29" Loading Loading @@ -45,6 +47,21 @@ except AssertionError: AUTH_DB_PATH = "{}/auth.db".format(CONFIG["CIRCE_WORKING_DIR"]) def _convert_targz_to_zip(tgz_path: str, zip_path: str): tar_file = tarfile.open(name=tgz_path, mode="r|gz") zip_file = zipfile.ZipFile( file=zip_path, mode="a", compression=zipfile.ZIP_DEFLATED ) for item in tar_file: if item.name: f = tar_file.extractfile(item) fl = f.read() fn = item.name zip_file.writestr(fn, fl) tar_file.close() zip_file.close() @contextmanager def auth_db(readonly=True): """ Loading Loading @@ -196,6 +213,8 @@ async def job_get(request: sanic.request, job_id: str): return sanic.response.HTTPResponse("Accepted", status=202) result_file_path = "{}/done/{}.tar.gz".format(CONFIG["CIRCE_WORKING_DIR"], job_id) if os.path.isfile(result_file_path): if request.args.get("zip", None): pass # convert tar.gz to zip and return zip return await sanic.response.file(result_file_path) # file_stream is slow ? bad chunk size ? # return await sanic.response.file_stream(result_file_path, chunked=False) Loading Loading @@ -319,8 +338,14 @@ if CONFIG["CIRCE_ENABLE_WEB_UI"]: CONFIG["CIRCE_WORKING_DIR"], job_id ) if os.path.isfile(result_file_path): result_zip_path = "{}done/{}.zip".format( CONFIG["CIRCE_WORKING_DIR"], job_id ) # end users prefer zip files over tar.gz if not os.path.isfile(result_zip_path): _convert_targz_to_zip(result_file_path, result_zip_path) return await sanic.response.file( result_file_path, filename="{}.tar.gz".format(job_id) result_zip_path, filename="{}.zip".format(job_id) ) return sanic.response.HTTPResponse("Not Found", status=404) Loading
circe/tasks.py +6 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,6 @@ from requests.exceptions import ConnectionError, HTTPError import logging from inspect import getmembers, isfunction, isclass, signature import sys import os from pythonjsonlogger import jsonlogger import datetime Loading Loading @@ -148,6 +147,12 @@ def do_transformations(uuid: uuid4, job_archive_path: str): ) move(temp_zip_path, final_archive_path) remove_file.schedule((final_archive_path,), delay=3600) # should the web demo UI be used, there might be an additional zip file to remove if CONFIG.get("CIRCE_ENABLE_WEB_UI"): final_zip_archive_path = "{}/done/{}.zip".format( CONFIG["CIRCE_WORKING_DIR"], uuid.hex ) remove_file.schedule((final_zip_archive_path,), delay=3600) if job_description.get("notify_hook", None): try: requests.post( # request is blocking, maybe try xhttp once stable ? Loading
setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="circe-CERTIC", version="0.0.32", version="0.0.33", author="Mickaël Desfrênes", author_email="mickael.desfrenes@unicaen.fr", description="Circe server", Loading