Example #1
0
def sample_doc(file_path, file_doc_id, redistribution="none"):
    """
    Returns a dictionary representing a file document

    :param file_path: Path to the sample file.
    :type file_path: str
    :param file_doc_id: File doc id as returned by the upload file db command.
    "type file_doc_id: str
    :param metadata: Dictionary with additional information about the file.
    :type metadata: dict

    :returns: dict -- file document
    """
    uid = utils.calculate_combined_hash(file_path)
    doc_id = sample_doc_id(uid)
    return {'_id': doc_id,
            'uid': uid,
            'file_doc_id': file_doc_id,
            'sample': doc_id,
            'type': 'sample',
            'size': os.path.getsize(file_path),
            'md5': utils.calculate_md5(file_path),
            'sha1': utils.calculate_sha1(file_path),
            'sha256': utils.calculate_sha256(file_path),
            'sha512': utils.calculate_sha512(file_path),
            'first_uploaded': str(datetime.datetime.now()),
            'redistribution': redistribution,
            'original filename': os.path.basename(file_path)
            }
Example #2
0
def sample_doc(file_path, file_doc_id, redistribution="none"):
    """
    Returns a dictionary representing a file document

    :param file_path: Path to the sample file.
    :type file_path: str
    :param file_doc_id: File doc id as returned by the upload file db command.
    "type file_doc_id: str
    :param metadata: Dictionary with additional information about the file.
    :type metadata: dict

    :returns: dict -- file document
    """
    uid = utils.calculate_combined_hash(file_path)
    doc_id = sample_doc_id(uid)
    return {
        '_id': doc_id,
        'uid': uid,
        'file_doc_id': file_doc_id,
        'sample': doc_id,
        'type': 'sample',
        'size': os.path.getsize(file_path),
        'md5': utils.calculate_md5(file_path),
        'sha1': utils.calculate_sha1(file_path),
        'sha256': utils.calculate_sha256(file_path),
        'sha512': utils.calculate_sha512(file_path),
        'first_uploaded': str(datetime.datetime.now()),
        'redistribution': redistribution,
        'original filename': os.path.basename(file_path)
    }
Example #3
0
def file_doc_id(file_path):
    return DELIMITER.join(['file', utils.calculate_sha256(file_path)])
Example #4
0
def file_doc_id(file_path):
    return DELIMITER.join(['file', utils.calculate_sha256(file_path)])
Example #5
0
def tohash(filepath):
    """
        LAMBDA uses SHA-256 to hash its samples as part of the sample doc id
    """
        
    return utils.calculate_sha256(filepath)