def _process_dispose_handler(source, process_stats): """Processes the source dispose handler.""" loggy = local.logger dispose_handler_code = source.dispose_handler if not dispose_handler_code or not dispose_handler_code.strip(): return try: _locals = {'source': source, 'process_stats': process_stats} _globals = {} function_name = 'dispose' exec to_handler_function(dispose_handler_code, function_name) in _locals, _globals result = _globals['__' + function_name]() return _run_workflow_from_handler(result) except: loggy.exception('Error while processing dispose handler.') raise
def _process_init_handler(source): """Processes the source init handler.""" loggy = local.logger init_handler_code = source.init_handler if not init_handler_code or not init_handler_code.strip(): return try: _locals = {'source': source} _globals = {} function_name = 'init' exec to_handler_function(init_handler_code, function_name) \ in _locals, _globals result = _globals['__' + function_name]() return _run_workflow_from_handler(result) except: loggy.exception('Error while processing init handler.') raise
def _process_dispose_handler(source, process_stats): """Processes the source dispose handler.""" loggy = local.logger dispose_handler_code = source.dispose_handler if not dispose_handler_code or not dispose_handler_code.strip(): return try: _locals = {'source': source, 'process_stats': process_stats} _globals = {} function_name = 'dispose' exec to_handler_function( dispose_handler_code, function_name) in _locals, _globals result = _globals['__' + function_name]() return _run_workflow_from_handler(result) except: loggy.exception('Error while processing dispose handler.') raise
def _evaluate_dispatcher(archive_item, file_meta): """Evaluate the dispatcher for a source and dataset couple.""" loggy = local.logger try: ext = ext_to_mime(get_extension(file_meta['out_file'])) except UnknownMIMETypeException: loggy.warning("Unknown file type for %s", file_meta['out_file']) archive_item.delete() # this is to not have useless archiveitems return [] _file = FileMeta( path=file_meta['out_file'], mime_by_ext=ext, mime_by_origin=file_meta['content_type'], ) dispatcher_code = archive_item.dataset.source.dispatcher \ or cnsettings.CONTROLLER_DISPATCHER_DEFAULT try: _locals = { 'UnsupportedDatasetException': UnsupportedDatasetException, 'source': archive_item.dataset.source, 'dataset': archive_item.dataset, 'archive_item': archive_item, 'file': _file, 'recurse': __recurse } _globals = {} function_name = 'dispatch' exec to_handler_function(dispatcher_code, function_name) in _locals, _globals try: result = _globals['__' + function_name]() except UnsupportedDatasetException: loggy.warning("Can't process file %s", file_meta['out_file']) archive_item.delete() # this is to not have useless archiveitems return [] else: return result except Exception: loggy.exception('Error while configuring workflow') raise
def _evaluate_dispatcher(archive_item, file_meta): """Evaluate the dispatcher for a source and dataset couple.""" loggy = local.logger try: ext = ext_to_mime(get_extension(file_meta['out_file'])) except UnknownMIMETypeException: loggy.warning("Unknown file type for %s", file_meta['out_file']) archive_item.delete() # this is to not have useless archiveitems return [] _file = FileMeta( path=file_meta['out_file'], mime_by_ext=ext, mime_by_origin=file_meta['content_type'], ) dispatcher_code = archive_item.dataset.source.dispatcher \ or cnsettings.CONTROLLER_DISPATCHER_DEFAULT try: _locals = { 'UnsupportedDatasetException': UnsupportedDatasetException, 'source': archive_item.dataset.source, 'dataset': archive_item.dataset, 'archive_item': archive_item, 'file': _file, 'recurse': __recurse } _globals = {} function_name = 'dispatch' exec to_handler_function( dispatcher_code, function_name) in _locals, _globals try: result = _globals['__' + function_name]() except UnsupportedDatasetException: loggy.warning("Can't process file %s", file_meta['out_file']) archive_item.delete() # this is to not have useless archiveitems return [] else: return result except Exception: loggy.exception('Error while configuring workflow') raise