Example #1
0
    def copy_versions(self):
        """copies versions from one task to another
        """
        # get from task
        from_task = self.get_task_from_tree_view(self.from_task_tree_view)

        # get logged in user
        logged_in_user = self.get_logged_in_user()

        if not from_task:
            QtWidgets.QMessageBox.critical(
                self, 'Error',
                'Please select a task from <b>From Task</b> list')
            return

        # get to task
        to_task = self.get_task_from_tree_view(self.to_task_tree_view)

        if not to_task:
            QtWidgets.QMessageBox.critical(
                self, 'Error', 'Please select a task from <b>To Task</b> list')
            return

        # check if tasks are the same
        if from_task == to_task:
            QtWidgets.QMessageBox.critical(
                self, 'Error', 'Please select two different tasks')
            return

        # get take names and related versions
        # get distinct take names
        from stalker.db.session import DBSession
        from_take_names = map(
            lambda x: x[0],
            DBSession.query(distinct(Version.take_name)).filter(
                Version.task == from_task).order_by(Version.take_name).all())

        # create versions for each take
        answer = QtWidgets.QMessageBox.question(
            self, 'Info', "Will copy %s versions from take names:<br><br>"
            "%s"
            "<br><br>"
            "Is that Ok?" %
            (len(from_take_names), '<br>'.join(from_take_names)),
            QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)

        if answer == QtWidgets.QMessageBox.Yes:
            for take_name in from_take_names:
                latest_version = Version.query\
                    .filter_by(task=from_task)\
                    .filter_by(take_name=take_name)\
                    .order_by(Version.version_number.desc())\
                    .first()

                # create a new version
                new_version = Version(task=to_task, take_name=take_name)
                new_version.created_by = logged_in_user
                new_version.extension = latest_version.extension
                new_version.description = \
                    'Moved from another task (id=%s) with Version Mover' % \
                    latest_version.task.id
                new_version.created_with = latest_version.created_with
                DBSession.add(new_version)
                DBSession.commit()

                # update path
                new_version.update_paths()
                DBSession.add(new_version)
                DBSession.commit()

                # now copy the last_version file to the new_version path
                try:
                    os.makedirs(new_version.absolute_path)
                except OSError:  # path exists
                    pass

                # move the file there
                shutil.copyfile(latest_version.absolute_full_path,
                                new_version.absolute_full_path)

            # inform the user
            QtWidgets.QMessageBox.information(
                self, 'Success',
                'Successfully copied %s versions' % len(from_take_names))
Example #2
0
def assign_version(request):
    """assigns the version to the given entity
    """
    logged_in_user = get_logged_in_user(request)

    # TODO: this should be renamed to create version
    # collect data
    link_ids = get_multi_integer(request, 'link_ids')
    task_id = request.params.get('task_id', -1)

    link = Link.query.filter(Link.id.in_(link_ids)).first()
    task = Task.query.filter_by(id=task_id).first()

    logger.debug('link_ids  : %s' % link_ids)
    logger.debug('link      : %s' % link)
    logger.debug('task_id   : %s' % task_id)
    logger.debug('task      : %s' % task)

    if task and link:
        # delete the link and create a version instead
        full_path = convert_file_link_to_full_path(link.full_path)
        take_name = request.params.get('take_name', defaults.version_take_name)
        publish = bool(request.params.get('publish'))

        logger.debug('publish : %s' % publish)

        path_and_filename, extension = os.path.splitext(full_path)

        version = Version(task=task, take_name=take_name,
                          created_by=logged_in_user)
        version.is_published = publish

        # generate path values
        version.update_paths()
        version.extension = extension

        # specify that this version is created with Stalker Pyramid
        version.created_with = 'StalkerPyramid'  # TODO: that should also be a
                                                 #       config value

        # now move the link file to the version.absolute_full_path
        try:
            os.makedirs(
                os.path.dirname(version.absolute_full_path)
            )
        except OSError:
            # dir exists
            pass

        logger.debug('full_path : %s' % full_path)
        logger.debug('version.absolute_full_path : %s' %
                     version.absolute_full_path)

        shutil.copyfile(full_path, version.absolute_full_path)
        os.remove(full_path)

        # it is now safe to delete the link
        DBSession.add(task)
        DBSession.delete(link)
        DBSession.add(version)

    return HTTPOk()
Example #3
0
    def copy_versions(self):
        """copies versions from one task to another
        """
        # get from task
        from_task = self.get_task_from_tree_view(self.from_task_tree_view)

        # get logged in user
        logged_in_user = self.get_logged_in_user()

        if not from_task:
            QtWidgets.QMessageBox.critical(
                self,
                'Error',
                'Please select a task from <b>From Task</b> list'
            )
            return

        # get to task
        to_task = self.get_task_from_tree_view(self.to_task_tree_view)

        if not to_task:
            QtWidgets.QMessageBox.critical(
                self,
                'Error',
                'Please select a task from <b>To Task</b> list'
            )
            return

        # check if tasks are the same
        if from_task == to_task:
            QtWidgets.QMessageBox.critical(
                self,
                'Error',
                'Please select two different tasks'
            )
            return

        # get take names and related versions
        # get distinct take names
        from_take_names = map(
            lambda x: x[0],
            db.DBSession.query(distinct(Version.take_name))
            .filter(Version.task == from_task)
            .order_by(Version.take_name)
            .all()
        )

        # create versions for each take
        answer = QtWidgets.QMessageBox.question(
            self,
            'Info',
            "Will copy %s versions from take names:<br><br>"
            "%s"
            "<br><br>"
            "Is that Ok?" % (
                len(from_take_names),
                '<br>'.join(from_take_names)
            ),
            QtWidgets.QMessageBox.Yes,
            QtWidgets.QMessageBox.No
        )

        if answer == QtWidgets.QMessageBox.Yes:
            for take_name in from_take_names:
                latest_version = Version.query\
                    .filter_by(task=from_task)\
                    .filter_by(take_name=take_name)\
                    .order_by(Version.version_number.desc())\
                    .first()

                # create a new version
                new_version = Version(
                    task=to_task,
                    take_name=take_name
                )
                new_version.created_by = logged_in_user
                new_version.extension = latest_version.extension
                new_version.description = \
                    'Moved from another task (id=%s) with Version Mover' % \
                    latest_version.task.id
                new_version.created_with = latest_version.created_with
                db.DBSession.add(new_version)
                db.DBSession.commit()

                # update path
                new_version.update_paths()
                db.DBSession.add(new_version)
                db.DBSession.commit()

                # now copy the last_version file to the new_version path
                try:
                    os.makedirs(new_version.absolute_path)
                except OSError:  # path exists
                    pass

                # move the file there
                shutil.copyfile(
                    latest_version.absolute_full_path,
                    new_version.absolute_full_path
                )

            # inform the user
            QtWidgets.QMessageBox.information(
                self,
                'Success',
                'Successfully copied %s versions' % len(from_take_names)
            )
Example #4
0
    def create_shot_hierarchy(self):
        """creates the related shot hierarchy
        """
        logged_in_user = self.get_logged_in_user()

        from stalker import Task
        from stalker.db.session import DBSession
        shot = self.get_shot()
        if not shot:
            shot = self.create_shot()

        # creat shot tasks
        # Anim
        anim_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Anim').first()
        if not anim_task:
            anim_task = Task(
                name='Anim',
                parent=shot,
                type=self.get_type('Animation'),
                bid_timing=10,
                bid_unit='min',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            DBSession.add(anim_task)

        # Camera
        camera_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Camera').first()
        if not camera_task:
            camera_task = Task(
                name='Camera',
                parent=shot,
                type=self.get_type('Camera'),
                bid_timing=10,
                bid_unit='min',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            DBSession.add(camera_task)

        # Cleanup
        cleanup_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Cleanup').first()
        if not cleanup_task:
            cleanup_task = Task(
                name='Cleanup',
                parent=shot,
                type=self.get_type('Cleanup'),
                bid_timing=10,
                bid_unit='min',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            DBSession.add(cleanup_task)

        # Comp
        comp_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Comp').first()
        if not comp_task:
            comp_task = Task(
                name='Comp',
                parent=shot,
                type=self.get_type('Comp'),
                bid_timing=10,
                bid_unit='min',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            DBSession.add(comp_task)

        # Lighting
        lighting_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Lighting').first()
        if not lighting_task:
            lighting_task = Task(
                name='Lighting',
                parent=shot,
                type=self.get_type('Lighting'),
                bid_timing=10,
                bid_unit='min',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            DBSession.add(lighting_task)

        # Plate
        plate_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Plate').first()
        if not plate_task:
            import datetime
            import pytz
            from stalker import defaults
            utc_now = datetime.datetime.now(pytz.utc)
            plate_task = Task(
                name='Plate',
                parent=shot,
                type=self.get_type('Plate'),
                schedule_timing=10,
                schedule_unit='min',
                schedule_model='duration',
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
                start=utc_now,  # this will be rounded to the timing resolution
                duration=defaults.timing_resolution
            )
            DBSession.add(plate_task)

        # Create a dummy version if there is non
        from stalker import Version
        all_versions = Version.query.filter(Version.task == plate_task).all()
        if not all_versions:
            v = Version(
                task=plate_task,
                take_name='Main',  # TODO: use the track name as take
                created_by=logged_in_user,
                updated_by=logged_in_user,
                description='Autocreated by Resolve',
            )
            from anima.env import blackmagic
            resolve = blackmagic.get_resolve()
            version_info = resolve.GetVersion()
            v.created_with = 'Resolve%s.%s' % (version_info[0], version_info[1])
            DBSession.add(v)

        # set the status the task
        with DBSession.no_autoflush:
            from stalker import Status
            cmpl = Status.query.filter(Status.code == 'CMPL').first()
            plate_task.status = cmpl

        # add dependency relation
        camera_task.depends = [plate_task]
        anim_task.depends = [camera_task]
        lighting_task.depends = [anim_task, camera_task]
        cleanup_task.depends = [plate_task]
        comp_task.depends = [lighting_task, cleanup_task]

        DBSession.commit()

        return shot