Пример #1
0
def file_meta_from_file(file_):
    """Computes the file metadata for a file."""

    # TODO: decoding to prevent invalid chars within archive.
    file_ = file_.decode('utf8')
    try:
        ext = ext_to_mime(get_extension(file_))
    except:  # pylint: disable=W0702
        ext = None
    return {
        'file_name': os.path.basename(file_),
        'content_type': ext,
        'file_size': os.path.getsize(file_),
        'out_file': file_,
        'md5sum': md5_for_file(file_)
    }
Пример #2
0
def file_meta_from_file(file_):
    """Computes the file metadata for a file."""

    # TODO: decoding to prevent invalid chars within archive.
    file_ = file_.decode('utf8')
    try:
        ext = ext_to_mime(get_extension(file_))
    except:  # pylint: disable=W0702
        ext = None
    return {
        'file_name': os.path.basename(file_),
        'content_type': ext,
        'file_size': os.path.getsize(file_),
        'out_file': file_,
        'md5sum': md5_for_file(file_)
    }
Пример #3
0
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
Пример #4
0
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
Пример #5
0
 def ext(self):
     """ the extension of the file associated to this dataset (which could
      be an archive file)
     """
     return get_extension(self.download)
Пример #6
0
 def ext(self):
     """ the extension of the file associated to this dataset (which could
      be an archive file)
     """
     return get_extension(self.download)