Example #1
0
    def run_import(self, file_path, project_id):
        result = []
        self.check_permissions()
        self.prepare_import()
        xml_file = etree.parse(file_path)
        root = xml_file.getroot()
        episode = shots_service.get_or_create_first_episode(project_id)
        shot_type = shots_service.get_shot_type()

        clips = root.iter('clipitem')
        for clip in clips:
           sequence_name = clip.find('name').text.split('_')[0]
           shot_name = clip.find('name').text.split('_')[1]
           start = clip.find('start').text
           end = clip.find('end').text

           if start == '-1':
               if clip.getprevious().tag == 'transitionitem':
                   start = clip.getprevious().find('start').text

           if end == '-1':
               if clip.getnext().tag == 'transitionitem':
                   end = clip.getnext().find('end').text

           duration = int(end) - int(start)
           self.sequences[sequence_name] = shots_service.get_or_create_sequence(project_id, episode['id'], sequence_name)

           sequence_id = self.get_id_from_cache(self.sequences, sequence_name)
           try:
               entity = Entity.create(
                   name=shot_name,
                   project_id=project_id,
                   parent_id=sequence_id,
                   entity_type_id=shot_type["id"],
                   nb_frames=str(duration)
               )
           except IntegrityError:
                entity = Entity.get_by(
                    name=shot_name,
                    project_id=project_id,
                    parent_id=sequence_id,
                    entity_type_id=shot_type["id"]
                )
           result.append(entity.serialize())

        return result
Example #2
0
    def import_row(self, row, project_id):
        episode_name = row["Episode"]
        sequence_name = row["Sequence"]
        shot_name = row["Name"]
        description = row["Description"]
        frame_in = row["Frame In"]
        frame_out = row["Frame Out"]

        episode_key = "%s-%s" % (project_id, episode_name)
        if episode_key not in self.episodes:
            self.episodes[episode_key] = \
                shots_service.get_or_create_episode(project_id, episode_name)

        sequence_key = "%s-%s-%s" % (project_id, episode_name, sequence_name)
        if sequence_key not in self.sequences:
            episode = self.episodes[episode_key]
            self.sequences[sequence_key] = \
                shots_service.get_or_create_sequence(
                    project_id,
                    episode["id"],
                    sequence_name
                )
        sequence_id = self.get_id_from_cache(self.sequences, sequence_key)

        shot_type = shots_service.get_shot_type()
        try:
            entity = Entity.create(
                name=shot_name,
                description=description,
                project_id=project_id,
                parent_id=sequence_id,
                entity_type_id=shot_type["id"],
                data={
                    "frame_in": frame_in,
                    "frame_out": frame_out
                }
            )
        except IntegrityError:
            entity = Entity.get_by(
                name=shot_name,
                project_id=project_id,
                parent_id=sequence_id,
                entity_type_id=shot_type["id"]
            )

        return entity.serialize()
Example #3
0
    def import_row(self, row, project_id):
        if self.is_tv_show:
            episode_name = row["Episode"]
        sequence_name = row["Sequence"]
        shot_name = row["Name"]
        description = row["Description"]
        nb_frames = row.get("Nb Frames", None) or row.get("Frames", None)
        data = {
            "frame_in": row.get("Frame In", None) or row.get("In", None),
            "frame_out": row.get("Frame Out", None) or row.get("Out", None),
            "fps": row.get("FPS", None),
        }
        for name, field_name in self.descriptor_fields.items():
            if name in row:
                data[field_name] = row[name]

        if self.is_tv_show:
            episode_key = "%s-%s" % (project_id, episode_name)
            if episode_key not in self.episodes:
                self.episodes[
                    episode_key] = shots_service.get_or_create_episode(
                        project_id, episode_name)

            sequence_key = "%s-%s-%s" % (
                project_id,
                episode_name,
                sequence_name,
            )
        else:
            sequence_key = "%s-%s" % (project_id, sequence_name)

        if sequence_key not in self.sequences:
            if self.is_tv_show:
                episode = self.episodes[episode_key]
                self.sequences[
                    sequence_key] = shots_service.get_or_create_sequence(
                        project_id, episode["id"], sequence_name)
            else:
                self.sequences[
                    sequence_key] = shots_service.get_or_create_sequence(
                        project_id, None, sequence_name)
        sequence_id = self.get_id_from_cache(self.sequences, sequence_key)

        shot_type = shots_service.get_shot_type()
        entity = Entity.get_by(
            name=shot_name,
            project_id=project_id,
            parent_id=sequence_id,
            entity_type_id=shot_type["id"],
        )
        if entity is None:
            try:
                if nb_frames is None or len(nb_frames) == 0:
                    entity = Entity.create(
                        name=shot_name,
                        description=description,
                        project_id=project_id,
                        parent_id=sequence_id,
                        entity_type_id=shot_type["id"],
                        data=data,
                    )
                else:
                    entity = Entity.create(
                        name=shot_name,
                        description=description,
                        project_id=project_id,
                        parent_id=sequence_id,
                        entity_type_id=shot_type["id"],
                        nb_frames=nb_frames,
                        data=data,
                    )
            except IntegrityError:
                current_app.logger.error("Row import failed", exc_info=1)

        elif self.is_update:
            entity.update({
                "description": description,
                "nb_frames": nb_frames,
                "data": data
            })

        return entity.serialize()
Example #4
0
File: shots.py Project: cgwire/zou
    def import_row(self, row, project_id):
        if self.is_tv_show:
            episode_name = row["Episode"]
        sequence_name = row["Sequence"]
        shot_name = row["Name"]

        if self.is_tv_show:
            episode_key = "%s-%s" % (project_id, episode_name)
            if episode_key not in self.episodes:
                self.episodes[
                    episode_key
                ] = shots_service.get_or_create_episode(
                    project_id, episode_name
                )

            sequence_key = "%s-%s-%s" % (
                project_id,
                episode_name,
                sequence_name,
            )
        else:
            sequence_key = "%s-%s" % (project_id, sequence_name)

        if sequence_key not in self.sequences:
            if self.is_tv_show:
                episode = self.episodes[episode_key]
                self.sequences[
                    sequence_key
                ] = shots_service.get_or_create_sequence(
                    project_id, episode["id"], sequence_name
                )
            else:
                self.sequences[
                    sequence_key
                ] = shots_service.get_or_create_sequence(
                    project_id, None, sequence_name
                )
        sequence_id = self.get_id_from_cache(self.sequences, sequence_key)

        shot_type = shots_service.get_shot_type()

        shot_values = {
            "name": shot_name,
            "project_id": project_id,
            "parent_id": sequence_id,
            "entity_type_id": shot_type["id"],
        }

        entity = Entity.get_by(**shot_values)

        shot_new_values = {}

        description = row.get("Description", None)
        if description is not None:
            shot_new_values["description"] = description

        nb_frames = row.get("Nb Frames", None) or row.get("Frames", None)
        if nb_frames is not None:
            shot_new_values["nb_frames"] = nb_frames

        if entity is None or not entity.data:
            shot_new_values["data"] = {}
        else:
            shot_new_values["data"] = entity.data.copy()

        frame_in = row.get("Frame In", None) or row.get("In", None)
        if frame_in is not None:
            shot_new_values["data"]["frame_in"] = frame_in

        frame_out = row.get("Frame Out", None) or row.get("Out", None)
        if frame_out is not None:
            shot_new_values["data"]["frame_out"] = frame_out

        fps = row.get("FPS", None)
        if fps is not None:
            shot_new_values["data"]["fps"] = fps

        for name, field_name in self.descriptor_fields.items():
            if name in row:
                shot_new_values["data"][field_name] = row[name]

        tasks_update = self.get_tasks_update(row)

        if entity is None:
            entity = Entity.create(**{**shot_values, **shot_new_values})
            events.emit(
                "shot:new", {"shot_id": str(entity.id)}, project_id=project_id
            )

            self.create_and_update_tasks(
                tasks_update, entity, shot_creation=True
            )

        elif self.is_update:
            entity.update(shot_new_values)
            events.emit(
                "shot:update",
                {"shot_id": str(entity.id)},
                project_id=project_id,
            )

            self.create_and_update_tasks(
                tasks_update, entity, shot_creation=False
            )

        return entity.serialize()
Example #5
0
    def import_row(self, row, project_id):
        if self.is_tv_show:
            episode_name = row["Episode"]
        sequence_name = row["Sequence"]
        shot_name = row["Name"]
        description = row.get("Description", "")
        nb_frames = row.get("Nb Frames", None) or row.get("Frames", None)
        data = {
            "frame_in": row.get("Frame In", None) or row.get("In", None),
            "frame_out": row.get("Frame Out", None) or row.get("Out", None),
            "fps": row.get("FPS", None),
        }

        if self.is_tv_show:
            episode_key = "%s-%s" % (project_id, episode_name)
            if episode_key not in self.episodes:
                self.episodes[
                    episode_key
                ] = shots_service.get_or_create_episode(
                    project_id, episode_name
                )

            sequence_key = "%s-%s-%s" % (
                project_id,
                episode_name,
                sequence_name,
            )
        else:
            sequence_key = "%s-%s" % (project_id, sequence_name)

        if sequence_key not in self.sequences:
            if self.is_tv_show:
                episode = self.episodes[episode_key]
                self.sequences[
                    sequence_key
                ] = shots_service.get_or_create_sequence(
                    project_id, episode["id"], sequence_name
                )
            else:
                self.sequences[
                    sequence_key
                ] = shots_service.get_or_create_sequence(
                    project_id, None, sequence_name
                )
        sequence_id = self.get_id_from_cache(self.sequences, sequence_key)

        shot_type = shots_service.get_shot_type()
        entity = Entity.get_by(
            name=shot_name,
            project_id=project_id,
            parent_id=sequence_id,
            entity_type_id=shot_type["id"],
        )

        for name, field_name in self.descriptor_fields.items():
            if name in row:
                data[field_name] = row[name]
            elif entity is not None and \
                entity.data is not None and \
                field_name in entity.data:
                data[field_name] = entity.data[field_name]

        if entity is None:
            if nb_frames is None or len(nb_frames) == 0:
                entity = Entity.create(
                    name=shot_name,
                    description=description,
                    project_id=project_id,
                    parent_id=sequence_id,
                    entity_type_id=shot_type["id"],
                    data=data,
                )
            else:
                entity = Entity.create(
                    name=shot_name,
                    description=description,
                    project_id=project_id,
                    parent_id=sequence_id,
                    entity_type_id=shot_type["id"],
                    nb_frames=nb_frames,
                    data=data,
                )
            events.emit(
                "shot:new",
                {"shot_id": str(entity.id)},
                project_id=project_id
            )

        elif self.is_update:
            entity.update({
                "description": description,
                "nb_frames": nb_frames,
                "data": data
            })
            events.emit(
                "shot:update",
                {"shot_id": str(entity.id)},
                project_id=project_id
            )

        return entity.serialize()