예제 #1
0
    def hydrate(self, bundle):
        if 'attached_file' in bundle.data:
            # have POSTed file
            newfile = bundle.data['attached_file'][0]
            compute_md5 = getattr(settings, 'COMPUTE_MD5', True)
            compute_sha512 = getattr(settings, 'COMPUTE_SHA512', True)
            if (compute_md5 and 'md5sum' not in bundle.data) or \
                    (compute_sha512 and 'sha512sum' not in bundle.data):
                checksums = compute_checksums(
                    newfile,
                    compute_md5=compute_md5,
                    compute_sha512=compute_sha512,
                    close_file=False)
                if compute_md5:
                    bundle.data['md5sum'] = checksums['md5sum']
                if compute_sha512:
                    bundle.data['sha512sum'] = checksums['sha512sum']

            if 'replicas' in bundle.data:
                for replica in bundle.data['replicas']:
                    replica.update({'file_object': newfile})
            else:
                bundle.data['replicas'] = [{'file_object': newfile}]

            del(bundle.data['attached_file'])
        return bundle
예제 #2
0
파일: api.py 프로젝트: jasonrig/mytardis
    def hydrate(self, bundle):
        if 'attached_file' in bundle.data:
            # have POSTed file
            newfile = bundle.data['attached_file'][0]
            if 'md5sum' not in bundle.data and 'sha512sum' not in bundle.data:
                checksums = compute_checksums(newfile, close_file=False)
                bundle.data['md5sum'] = checksums['md5sum']
                bundle.data['sha512sum'] = checksums['sha512sum']

            if 'replicas' in bundle.data:
                for replica in bundle.data['replicas']:
                    replica.update({'file_object': newfile})
            else:
                bundle.data['replicas'] = [{'file_object': newfile}]

            del(bundle.data['attached_file'])
        return bundle
예제 #3
0
    def hydrate(self, bundle):
        if 'attached_file' in bundle.data:
            # have POSTed file
            newfile = bundle.data['attached_file'][0]
            if 'md5sum' not in bundle.data and 'sha512sum' not in bundle.data:
                checksums = compute_checksums(newfile, close_file=False)
                bundle.data['md5sum'] = checksums['md5sum']
                bundle.data['sha512sum'] = checksums['sha512sum']

            if 'replicas' in bundle.data:
                for replica in bundle.data['replicas']:
                    replica.update({'file_object': newfile})
            else:
                bundle.data['replicas'] = [{'file_object': newfile}]

            del (bundle.data['attached_file'])
        return bundle
예제 #4
0
 def get_file_details(self, top, filename):
     fullpath = os.path.join(top, filename)
     try:
         fo = self.sq_inst.open(fullpath)
         size = fo.size
         checksums = compute_checksums(fo)
     except IOError as e:
         log.debug('squash parse error')
         log.debug(e)
         if os.path.islink(self.sq_inst.path(fullpath)):
             return {}
         raise
     return {
         'size': str(size),
         'md5sum': checksums['md5sum'],
         'sha512sum': checksums['sha512sum']
     }
예제 #5
0
def _create_datafile():
    user = User.objects.create_user('testuser', '*****@*****.**', 'pwd')
    user.save()

    full_access = Experiment.PUBLIC_ACCESS_FULL
    experiment = Experiment.objects.create(title="IIIF Test",
                                           created_by=user,
                                           public_access=full_access)
    experiment.save()
    ObjectACL(content_object=experiment,
              pluginId='django_user',
              entityId=str(user.id),
              isOwner=True,
              canRead=True,
              canWrite=True,
              canDelete=True,
              aclOwnershipType=ObjectACL.OWNER_OWNED).save()
    dataset = Dataset()
    dataset.save()
    dataset.experiments.add(experiment)
    dataset.save()

    # Create new Datafile
    tempfile = TemporaryUploadedFile('iiif_stored_file', None, None, None)
    with Image(filename='magick:rose') as img:
        img.format = 'tiff'
        img.save(file=tempfile.file)
        tempfile.file.flush()
    datafile = DataFile(dataset=dataset,
                        size=os.path.getsize(tempfile.file.name),
                        filename='iiif_named_file',
                        mimetype='image/tiff')
    compute_md5 = getattr(settings, 'COMPUTE_MD5', True)
    compute_sha512 = getattr(settings, 'COMPUTE_SHA512', True)
    checksums = compute_checksums(open(tempfile.file.name, 'r'),
                                  compute_md5=compute_md5,
                                  compute_sha512=compute_sha512)
    if compute_md5:
        datafile.md5sum = checksums['md5sum']
    if compute_sha512:
        datafile.sha512sum = checksums['sha512sum']
    datafile.save()
    datafile.file_object = tempfile
    return datafile
예제 #6
0
    def hydrate(self, bundle):
        if 'attached_file' in bundle.data:
            # have POSTed file
            newfile = bundle.data['attached_file'][0]
            compute_md5 = getattr(settings, 'COMPUTE_MD5', True)
            compute_sha512 = getattr(settings, 'COMPUTE_SHA512', True)
            if (compute_md5 and 'md5sum' not in bundle.data) or \
                    (compute_sha512 and 'sha512sum' not in bundle.data):
                checksums = compute_checksums(newfile, close_file=False)
                if compute_md5:
                    bundle.data['md5sum'] = checksums['md5sum']
                if compute_sha512:
                    bundle.data['sha512sum'] = checksums['sha512sum']

            if 'replicas' in bundle.data:
                for replica in bundle.data['replicas']:
                    replica.update({'file_object': newfile})
            else:
                bundle.data['replicas'] = [{'file_object': newfile}]

            del(bundle.data['attached_file'])
        return bundle
예제 #7
0
def _create_datafile():
    user = User.objects.create_user("testuser", "*****@*****.**", "pwd")
    user.save()

    full_access = Experiment.PUBLIC_ACCESS_FULL
    experiment = Experiment.objects.create(title="IIIF Test", created_by=user, public_access=full_access)
    experiment.save()
    ObjectACL(
        content_object=experiment,
        pluginId="django_user",
        entityId=str(user.id),
        isOwner=True,
        canRead=True,
        canWrite=True,
        canDelete=True,
        aclOwnershipType=ObjectACL.OWNER_OWNED,
    ).save()
    dataset = Dataset()
    dataset.save()
    dataset.experiments.add(experiment)
    dataset.save()

    # Create new Datafile
    tempfile = TemporaryUploadedFile("iiif_stored_file", None, None, None)
    with Image(filename="magick:rose") as img:
        img.format = "tiff"
        img.save(file=tempfile.file)
        tempfile.file.flush()
    datafile = DataFile(
        dataset=dataset, size=os.path.getsize(tempfile.file.name), filename="iiif_named_file", mimetype="image/tiff"
    )
    checksums = compute_checksums(open(tempfile.file.name, "r"))
    datafile.md5sum = checksums["md5sum"]
    datafile.sha512sum = checksums["sha512sum"]
    datafile.save()
    datafile.file_object = tempfile
    return datafile