Exemple #1
0
def check_deposit_record_files(deposit, deposit_expected, record,
                               record_expected):
    """Check deposit and record files expected."""
    # check deposit
    deposit_objs = [
        obj.key for obj in ObjectVersion.query_heads_by_bucket(
            deposit.files.bucket).all()
    ]
    assert sorted(deposit_expected) == sorted(deposit_objs)
    assert deposit.files.bucket.locked is False
    # check record
    record_objs = [
        obj.key for obj in ObjectVersion.query_heads_by_bucket(
            record.files.bucket).all()
    ]
    assert sorted(record_expected) == sorted(record_objs)
    assert record.files.bucket.locked is True
Exemple #2
0
def dump_generic_object(obj, data):
    """Dump a generic object (master, subtitles, ..) avoid depending objs."""
    obj_dump = dump_object(obj)
    # if it's a master, get all the depending object and add them inside
    # <context_type> as a list order by key.
    for slave in ObjectVersion.query_heads_by_bucket(
        bucket=obj.bucket).join(ObjectVersion.tags).filter(
            ObjectVersion.file_id.isnot(None),
            ObjectVersionTag.key == 'master',
            ObjectVersionTag.value == str(obj.version_id)
    ).order_by(func.length(ObjectVersion.key), ObjectVersion.key):
        obj_dump.setdefault(
            slave.get_tags()['context_type'], []).append(dump_object(slave))
    # Sort slaves by key within their lists
    data.update(obj_dump)
Exemple #3
0
    def _force_sync_deposit_bucket(record):
        """Replace deposit bucket with a copy of the record bucket."""
        deposit = Video.get_record(record.depid.object_uuid)
        # if deposit['_deposit']['status'] == 'draft':
        #     raise RuntimeError('Deposit in edit mode: {0}'.format(deposit.id))
        deposit_old_bucket = deposit.files.bucket
        # create a copy of record bucket
        new_bucket = record.files.bucket.snapshot()
        new_bucket.locked = False
        db.session.commit()
        rb = RecordsBuckets.query.filter(
            RecordsBuckets.bucket_id == deposit_old_bucket.id).one()
        rb.bucket = new_bucket
        db.session.add(rb)
        db.session.commit()

        # Put tags correctly pointing to the right object
        master_file = CDSVideosFilesIterator.get_master_video_file(record)
        if master_file:
            master_deposit_obj = ObjectVersion.get(new_bucket,
                                                   master_file['key'])

            for slave in ObjectVersion.query_heads_by_bucket(
                    bucket=new_bucket).join(ObjectVersion.tags).filter(
                        ObjectVersion.file_id.isnot(None),
                        ObjectVersionTag.key == 'master'):
                ObjectVersionTag.create_or_update(
                    slave, 'master', str(master_deposit_obj.version_id))
                db.session.add(slave)
                db.session.commit()

        # Delete the old bucket
        deposit_old_bucket.locked = False
        _ = deposit_old_bucket.remove()

        deposit['_buckets']['deposit'] = str(new_bucket.id)
        record['_buckets']['deposit'] = str(new_bucket.id)
        record['_deposit'] = deposit['_deposit']
        deposit['_files'] = deposit.files.dumps()
        deposit.commit()
        record.commit()
        db.session.commit()

        return deposit_old_bucket.id, new_bucket.id