Exemple #1
0
def _artifact_from_data(raw_data):
    tmpfile = PulpTemporaryUploadedFile("tmpfile", "application/octet-stream",
                                        len(raw_data), "", "")
    tmpfile.write(raw_data)

    artifact_serializer = ArtifactSerializer(data={"file": tmpfile})
    artifact_serializer.is_valid(raise_exception=True)

    return artifact_serializer.save()
Exemple #2
0
def _artifact_from_data(raw_data):
    tmpfile = PulpTemporaryUploadedFile("", "application/octet-stream",
                                        len(raw_data), "", "")
    tmpfile.write(raw_data)
    for hasher in Artifact.DIGEST_FIELDS:
        tmpfile.hashers[hasher].update(raw_data)

    artifact = Artifact()
    artifact.file = tmpfile
    artifact.size = tmpfile.size
    for hasher in Artifact.DIGEST_FIELDS:
        setattr(artifact, hasher, tmpfile.hashers[hasher].hexdigest())

    artifact.save()
    return artifact