diff options
Diffstat (limited to 'megapixels/app/server/tasks/blur.py')
| -rw-r--r-- | megapixels/app/server/tasks/blur.py | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/megapixels/app/server/tasks/blur.py b/megapixels/app/server/tasks/blur.py index d1f67f54..42977097 100644 --- a/megapixels/app/server/tasks/blur.py +++ b/megapixels/app/server/tasks/blur.py @@ -9,6 +9,8 @@ import numpy as np from app.utils.im_utils import ensure_np, ensure_pil from flask import current_app as app +import app.settings.app_cfg as cfg + from app.server.tasks import celery from celery.utils.log import get_task_logger @@ -19,57 +21,58 @@ import imutils def blur_task(self, uuid_name, fn): """Process image and update during""" celery_logger.debug('process_image_task, uuid: {}'.format(uuid_name)) + celery_logger.debug('fn: {}'.format(fn)) files = [] + meta = { + 'step': 0, + 'total': 3, + 'message': 'Starting', + 'uuid': uuid_name, + 'data': {}, + } + self.update_state(state='PROCESSING', meta=meta) + im = Image.open(fn).convert('RGB') + os.remove(fn) - self.update_state( - state = 'PROCESSING', - meta = { - 'percent': 0.25, - 'message': 'Applying blur', - 'uuid': uuid_name - }) + meta['step'] += 1 + meta['message'] = 'Applying blur' + self.update_state(state='PROCESSING', meta=meta) im_np = ensure_np(im) im_blur = cv.blur(im_np, (5,5), 1.0) im_blur_pil = ensure_pil(im_blur) fn = uuid_name + '_blur.jpg' - # fpath = os.path.join(render_dir, fn) - # im_blur_pil.save(fpath, 'JPEG', quality=95) + fpath = os.path.join(cfg.DIR_SITE_USER_CONTENT, fn) + im_blur_pil.save(fpath, 'JPEG', quality=80) + celery_logger.debug('fpath: {}'.format(fpath)) + print('fpath: {}'.format(fpath)) # files.append({ # 'title': 'Blurred image', # 'fn': render_uri + uuid_name + '_blur.jpg' # }) + meta['step'] += 1 + meta['message'] = 'Applying blur' + meta['data']['blur_fn'] = os.path.join('/user_content/', fn) + self.update_state(state='PROCESSING', meta=meta) time.sleep(3) - self.update_state( - state = 'PROCESSING', - meta = { - 'percent': 0.75, - 'message': 'Sleeping some more', - 'uuid': uuid_name - }) - time.sleep(2) + if os.path.exists(fpath): + os.remove(fpath) - data = { - 'uuid': uuid_name, - 'date': str(datetime.datetime.now()), - 'files': files - } + meta['step'] += 1 + meta['message'] = 'Securely deleting user content' + self.update_state(state='PROCESSING', meta=meta) + time.sleep(2) - # json_path = os.path.join(json_dir, uuid_name + '.json') - # with open(json_path, 'w') as json_file: - # json.dump(data, json_file) + celery_logger.debug('done!!') + + meta['step'] = meta['total'] + meta['state'] = 'complete' + return meta - celery_logger.debug('ok') - - return { - 'percent': 100, - 'state': 'complete', - 'uuid': uuid_name, - } |
