コード例 #1
0
ファイル: documents.py プロジェクト: patriotemeritus/LO-PHI
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)
    }
コード例 #2
0
ファイル: documents.py プロジェクト: c0ns0le/LO-PHI
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)
            }
コード例 #3
0
def sample_doc_id(filepath):
    """
        Returns a sample_doc_id to assign to this sample.
        We can use this to look up the documents for this sample in the database

    """
    return documents.sample_doc_id(
        utils.calculate_combined_hash(filepath))