Ejemplo n.º 1
0
    def test_version_number_attribute_is_set_to_a_lower_then_it_should_be(self):
        """testing if the version_number attribute will be set to a correct
        unique value when it is set to a lower number then it should be
        """
        self.test_version.version_number = -1
        self.assertEqual(self.test_version.version_number, 1)

        self.test_version.version_number = -10
        self.assertEqual(self.test_version.version_number, 1)

        DBSession.add(self.test_version)
        DBSession.commit()

        self.test_version.version_number = -100
        # it should be 1 again
        self.assertEqual(self.test_version.version_number, 1)

        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.version_number, 2)

        new_version.version_number = 1
        self.assertEqual(new_version.version_number, 2)

        new_version.version_number = 100
        self.assertEqual(new_version.version_number, 100)
Ejemplo n.º 2
0
    def loads(self, data):
        """Decodes Stalker data

        :param data:
        :return:
        """
        from stalker.db.session import DBSession
        from stalker import Asset, Task, Shot, Sequence, Version, Type

        if isinstance(data, str):
            data = json.loads(data)

        # get the entity_type
        entity_type = data['entity_type']

        # set default entity class to Task
        entity_class = Task
        if entity_type == 'Asset':
            entity_class = Asset
        elif entity_type == 'Shot':
            entity_class = Shot
            # this is a bug
            data['sequences'] = []
        elif entity_type == 'Sequence':
            entity_class = Sequence

        version_data = data['versions']
        data['versions'] = []
        # get the type
        if 'type' in data:
            type_data = data['type']
            if type_data:
                type_name = type_data['name']
                type_ = Type.query.filter(Type.name == type_name).first()
                if not type_:
                    # create a Type
                    type_ = Type(**type_data)
                data['type'] = type_

        data['project'] = self.project
        entity = entity_class(**data)
        DBSession.add(entity)
        DBSession.commit()

        # create Versions
        if version_data:
            for v_data in version_data:
                # get Version info
                v_data['task'] = entity
                v = Version(**v_data)
                # update version_number
                v.version_number = v_data['version_number']
                v.is_published = v_data['is_published']

        # for each child task call a new StalkerEntityDecoder
        for t in data['tasks']:
            child_task = self.loads(t)
            entity.tasks.append(child_task)

        return entity
Ejemplo n.º 3
0
    def get_latest_repr_version(self, take_name):
        """returns the latest published version or creates a new version

        :param str take_name: The take_name
        :return:
        """
        from stalker import Version

        # filter to get the latest published version
        v = Version.query\
            .filter(Version.task == self.version.task)\
            .filter(Version.take_name == take_name)\
            .filter(Version.is_published == True)\
            .order_by(Version.version_number.desc())\
            .first()

        if v is None:
            # create a new version
            v = Version(
                created_by=self.logged_in_user,
                task=self.version.task,
                take_name=take_name
            )
            v.is_published = True
        else:
            # change updated by
            v.updated_by = self.logged_in_user

        return v
Ejemplo n.º 4
0
    def upload_version(self, task, file_object, take_name=None, extension=''):
        """Uploads versions to the Task.path/ folder and creates a Version
        object to there. Again the Version object will have a Repository root
        relative path.

        The filename of the version will be automatically generated by Stalker.

        :param task: The task that a version is uploaded to. Should be an
          instance of :class:`.Task` class.
        :param file_object: A file like object holding the content of the
          version.
        :param str take_name: A string showing the the take name of the
          Version. If skipped defaults.version_take_name will be used.
        :param str extension: The file extension of the version.
        :returns: :class:`.Version` instance.
        """
        from stalker import defaults, Version
        if take_name is None:
            take_name = defaults.version_take_name

        v = Version(task=task,
                    take_name=take_name,
                    created_with='Stalker Pyramid')
        v.update_paths()
        v.extension = extension

        # upload it
        self.upload_file(file_object, v.absolute_path, v.filename)

        return v
Ejemplo n.º 5
0
 def test_parent_attribute_is_working_properly(self):
     """testing if the parent attribute is working properly
     """
     self.kwargs["parent"] = None
     new_version = Version(**self.kwargs)
     self.assertNotEqual(new_version.parent, self.test_version)
     new_version.parent = self.test_version
     self.assertEqual(new_version.parent, self.test_version)
Ejemplo n.º 6
0
    def setUpClass(cls):
        """setup once
        """
        db.setup()
        db.init()

        cls.status_new = Status.query.filter_by(code='NEW').first()
        cls.status_wip = Status.query.filter_by(code='WIP').first()
        cls.status_cmpl = Status.query.filter_by(code='CMPL').first()

        cls.test_project_status_list = StatusList(
            name='Project Statuses',
            target_entity_type='Project',
            statuses=[cls.status_new, cls.status_wip, cls.status_cmpl])

        cls.test_repo = Repository(name='Test Repository')

        cls.test_project = Project(name='Test Project',
                                   code='TP',
                                   repository=cls.test_repo,
                                   status_list=cls.test_project_status_list)

        cls.test_task1 = Task(name='Test Task 1', project=cls.test_project)
        cls.test_task2 = Task(name='Test Task 2', project=cls.test_project)
        cls.test_task3 = Task(name='Test Task 3', project=cls.test_project)

        cls.test_version1 = Version(task=cls.test_task1)
        db.DBSession.add(cls.test_version1)
        db.DBSession.commit()

        cls.test_version2 = Version(task=cls.test_task1)
        db.DBSession.add(cls.test_version2)
        db.DBSession.commit()

        cls.test_version3 = Version(task=cls.test_task1)
        db.DBSession.add(cls.test_version3)
        db.DBSession.commit()

        cls.test_version4 = Version(task=cls.test_task2)
        db.DBSession.add(cls.test_version4)
        db.DBSession.commit()

        cls.test_link1 = Link(original_filename='test_render1.jpg')
        cls.test_link2 = Link(original_filename='test_render2.jpg')
        cls.test_link3 = Link(original_filename='test_render3.jpg')
        cls.test_link4 = Link(original_filename='test_render4.jpg')

        cls.test_version1.outputs = [
            cls.test_link1, cls.test_link2, cls.test_link3
        ]
        cls.test_version4.outputs = [cls.test_link4]

        db.DBSession.add_all([
            cls.test_task1, cls.test_task2, cls.test_task3, cls.test_version1,
            cls.test_version2, cls.test_version3, cls.test_version4,
            cls.test_link1, cls.test_link2, cls.test_link3, cls.test_link4
        ])
        db.DBSession.commit()
Ejemplo n.º 7
0
 def test_parent_attribute_updates_the_children_attribute(self):
     """testing if the parent attribute updates the children attribute of
     the parent Version properly
     """
     self.kwargs["parent"] = None
     new_version = Version(**self.kwargs)
     self.assertNotEqual(new_version.parent, self.test_version)
     new_version.parent = self.test_version
     self.assertTrue(new_version in self.test_version.children)
Ejemplo n.º 8
0
    def test_children_attribute_will_not_allow_circular_dependencies(self):
        """testing if a CircularDependency error will be raised when a parent
        Version is set as a children to its child
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        new_version2 = Version(**self.kwargs)

        new_version1.parent = new_version2
        self.assertRaises(CircularDependencyError, new_version1.children.append, new_version2)
Ejemplo n.º 9
0
    def update_versions(self, reference_resolution):
        """A mock update_versions implementation, does the update indeed but
        partially.

        :param reference_resolution: The reference_resolution dictionary
        :return: a list of new versions
        """
        # first get the resolution list
        new_versions = []
        from stalker import Version

        # store the current version
        current_version = self.get_current_version()

        # loop through 'create' versions and update their references
        # and create a new version for each of them
        for version in reference_resolution['create']:
            local_reference_resolution = self.open(version, force=True)

            # save as a new version
            new_version = Version(
                task=version.task,
                take_name=version.take_name,
                parent=version,
                description='Automatically created with '
                            'Deep Reference Update'
            )
            new_version.is_published = True

            for v in self._version.inputs:
                new_version.inputs.append(v.latest_published_version)

            new_versions.append(new_version)

        # check if we are still in the same scene
        current_version_after_create = self.get_current_version()

        if current_version:
            if current_version != current_version_after_create:
                # so we are in a different scene just reopen the previous scene
                self.open(current_version)
            # we got a new local_reference_resolution but we should have given
            # a previous one, so use it,
            #
            # append all the 'create' items to 'update' items,
            # so we can update them with update_first_level_versions()
            reference_resolution['update'].extend(
                reference_resolution['create']
            )
            self.update_first_level_versions(reference_resolution)

        return new_versions
Ejemplo n.º 10
0
    def test_outputs_attribute_is_working_properly(self):
        """testing if the outputs attribute is working properly
        """
        self.kwargs.pop("outputs")
        new_version = Version(**self.kwargs)

        self.assertFalse(self.test_output_link1 in new_version.outputs)
        self.assertFalse(self.test_output_link2 in new_version.outputs)

        new_version.outputs = [self.test_output_link1, self.test_output_link2]

        self.assertTrue(self.test_output_link1 in new_version.outputs)
        self.assertTrue(self.test_output_link2 in new_version.outputs)
Ejemplo n.º 11
0
        def create_version(task, take_name):
            """Creates a new version
            :param task: the task
            :param take_name: the take_name name
            :return: the version
            """
            # just renew the scene
            #pymel.core.newFile(force=True)

            v = Version(task=task, take_name=take_name)
            v.update_paths()
            db.DBSession.add(v)
            db.DBSession.commit()
            #self.maya_env.save_as(v)
            return v
Ejemplo n.º 12
0
        def create_version(task, take_name):
            """Creates a new version
            :param task: the task
            :param take_name: the take_name name
            :return: the version
            """
            # just renew the scene
            #pymel.core.newFile(force=True)

            v = Version(task=task, take_name=take_name)
            v.update_paths()
            db.DBSession.add(v)
            db.DBSession.commit()
            #self.maya_env.save_as(v)
            return v
Ejemplo n.º 13
0
    def test_walk_hierarchy_is_working_properly_in_DFS_mode(self):
        """testing if the walk_hierarchy() method is working in DFS mode
        correctly
        """
        v1 = Version(task=self.test_task1)
        v2 = Version(task=self.test_task1, parent=v1)
        v3 = Version(task=self.test_task1, parent=v2)
        v4 = Version(task=self.test_task1, parent=v3)
        v5 = Version(task=self.test_task1, parent=v1)

        expected_result = [v1, v2, v3, v4, v5]
        visited_versions = []
        for v in v1.walk_hierarchy():
            visited_versions.append(v)

        self.assertEqual(expected_result, visited_versions)
Ejemplo n.º 14
0
    def setUp(self):
        """set up the test
        """
        db.setup()
        db.init()

        self.temp_path = tempfile.mkdtemp()
        self.repo = Repository(
            name='Test Repository',
            linux_path=self.temp_path,
            windows_path=self.temp_path,
            osx_path=self.temp_path
        )
        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_wip = Status.query.filter_by(code='WIP').first()
        self.status_cmpl = Status.query.filter_by(code='CMPL').first()

        self.project_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()
        self.task_filename_template = FilenameTemplate(
            name='Task Filename Template',
            target_entity_type='Task',
            path='{{project.code}}/{%- for parent_task in parent_tasks -%}'
                 '{{parent_task.nice_name}}/{%- endfor -%}',
            filename='{{version.nice_name}}'
                     '_v{{"%03d"|format(version.version_number)}}{{extension}}'
        )
        self.project_structure = Structure(
            name='Project Structure',
            templates=[self.task_filename_template]
        )
        self.project = Project(
            name='Test Project',
            code='TP',
            status_list=self.project_status_list,
            repository=self.repo,
            structure=self.project_structure
        )

        self.task = Task(
            name='Test Task',
            project=self.project
        )
        from stalker.db.session import DBSession
        DBSession.add(self.task)
        DBSession.commit()

        self.version = Version(
            task=self.task
        )

        self.kwargs = {
            'name': 'Photoshop',
            'extensions': ['psd'],
            'structure': ['Outputs']
        }

        self.external_env = ExternalEnv(**self.kwargs)
Ejemplo n.º 15
0
    def create_version(cls, task, take_name):
        """A helper method for creating a new version

        :param task: the task
        :param take_name: the take_name name
        :return: the version
        """
        v = Version(task=task, take_name=take_name)
        db.DBSession.add(v)
        db.DBSession.commit()
        return v
Ejemplo n.º 16
0
    def test_absolute_full_path_works_properly(self):
        """testing if the absolute_full_path attribute works properly
        """
        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version1.update_paths()
        new_version1.extension = ".ma"
        self.assertEqual(new_version1.extension, ".ma")

        self.assertEqual(new_version1.absolute_full_path, "/mnt/T/tp/SH001/Task1/Task1_TestTake_v001.ma")
Ejemplo n.º 17
0
    def test_latest_published_version_is_working_properly(self):
        """testing if the is_latest_published_version is working properly
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertEqual(new_version1.latest_published_version, new_version4)
        self.assertEqual(new_version2.latest_published_version, new_version4)
        self.assertEqual(new_version3.latest_published_version, new_version4)
        self.assertEqual(new_version4.latest_published_version, new_version4)
        self.assertEqual(new_version5.latest_published_version, new_version4)
Ejemplo n.º 18
0
    def test_update_paths_will_preserve_extension(self):
        """testing if update_paths method will preserve the extension.
        """
        # create a FilenameTemplate for Task instances
        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()
        new_version1.update_paths()

        self.assertEqual(new_version1.path, "tp/SH001/Task1")

        extension = ".ma"
        new_version1.extension = extension
        self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")

        # rename the task and update the paths
        self.test_task1.name = "Task2"

        # now call update_paths and expect the extension to be preserved
        new_version1.update_paths()
        self.assertEqual(new_version1.filename, "Task2_TestTake_v001.ma")
        self.assertEqual(new_version1.extension, extension)
Ejemplo n.º 19
0
    def create_version(cls, task, take_name):
        """A helper method for creating a new version

        :param task: the task
        :param take_name: the take_name name
        :return: the version
        """
        from stalker import Version
        from stalker.db.session import DBSession
        v = Version(task=task, take_name=take_name)
        DBSession.add(v)
        DBSession.commit()
        return v
Ejemplo n.º 20
0
    def test_walk_inputs_is_working_properly_in_DFS_mode(self):
        """testing if the walk_inputs() method is working in DFS mode correctly
        """
        v1 = Version(task=self.test_task1)
        v2 = Version(task=self.test_task1)
        v3 = Version(task=self.test_task1)
        v4 = Version(task=self.test_task1)
        v5 = Version(task=self.test_task1)

        v5.inputs = [v4]
        v4.inputs = [v3, v2]
        v3.inputs = [v1]
        v2.inputs = [v1]

        expected_result = [v5, v4, v3, v1, v2, v1]
        visited_versions = []
        for v in v5.walk_inputs():
            visited_versions.append(v)

        self.assertEqual(expected_result, visited_versions)
Ejemplo n.º 21
0
    def test_upload_version_output_is_working_properly(self):
        """testing if MediaManager.upload_version_output() is working properly
        """
        v = Version(task=self.test_task2)
        db.DBSession.add(v)
        db.DBSession.commit()

        v.update_paths()
        db.DBSession.add(v)
        db.DBSession.commit()

        # upload an image file as an output to a version of test_task2
        with open(self.test_video_path_mp4) as f:
            link = self.test_media_manager.upload_version_output(
                v, f, 'test_video.mp4')

        # now expect the return_val to be a Link instance
        self.assertIsInstance(link, Link)

        # expect the Link full_path to be:
        #   Version.path/Outputs/Stalker_Pyramid/
        self.assertEqual(os.path.dirname(link.full_path),
                         os.path.join(v.path, 'Outputs/Stalker_Pyramid'))

        # expect the Link.thumbnail.full_path to be in
        #  Version.path/Outputs/Stalker_Pyramid/ForWeb/
        self.assertEqual(
            os.path.dirname(link.thumbnail.full_path),
            os.path.join(v.path, 'Outputs/Stalker_Pyramid/ForWeb'))

        # and expect the Link.thumbnail.thumbnail.full_path to be in
        #  Version.path/Outputs/Stalker_Pyramid/Thumbnail/
        self.assertEqual(
            os.path.dirname(link.thumbnail.thumbnail.full_path),
            os.path.join(self.test_task2.path,
                         'Outputs/Stalker_Pyramid/Thumbnail'))
Ejemplo n.º 22
0
    def create_version(self, task, take_name):
        """A helper method for creating a new version

        :param task: the task
        :param take_name: the take_name name
        :return: the Version instance
        """
        # just renew the scene
        v = Version(task=task, take_name=take_name)
        v.update_paths()

        DBSession.add(v)
        DBSession.commit()

        # create a file
        try:
            os.makedirs(os.path.dirname(v.absolute_full_path))
        except OSError:  # dir exists
            pass

        with open(v.absolute_full_path, 'w+'):
            pass

        return v
Ejemplo n.º 23
0
    def create_version(self, task, take_name):
        """A helper method for creating a new version

        :param task: the task
        :param take_name: the take_name name
        :return: the Version instance
        """
        # just renew the scene
        v = Version(task=task, take_name=take_name)
        v.update_paths()

        db.DBSession.add(v)
        db.DBSession.commit()

        # create a file
        try:
            os.makedirs(os.path.dirname(v.absolute_full_path))
        except OSError:  # dir exists
            pass

        with open(v.absolute_full_path, 'w+'):
            pass

        return v
Ejemplo n.º 24
0
    def add_take(self, take_name):
        """adds a new take to the takes list
        """
        # condition the input
        from stalker import Version
        take_name = Version._format_take_name(take_name)

        # if the given take name is in the list don't add it
        if take_name not in self._take_names:
            # add the item via property
            new_take_list = self._take_names
            new_take_list.append(take_name)
            new_take_list.sort()
            self.take_names = new_take_list

            # select the newly added take name
            index = self.findText(take_name, QtCore.Qt.MatchExactly)
            if index:
                self.setCurrentIndex(index)
Ejemplo n.º 25
0
    def save_as(self, shot_name, child_task_name='Previs'):
        """saves the file under the given shot name
        """
        # first find the shot
        from stalker import Version, Shot, Task
        shot = Shot.query.filter(Shot.name == shot_name).first()
        if not shot:
            raise RuntimeError('No shot found with shot name: %s' % shot_name)

        # get the child task
        child_task = Task.query\
            .filter(Task.parent == shot)\
            .filter(Task.name == child_task_name)\
            .first()

        logged_in_user = LocalSession().logged_in_user

        v = Version(task=child_task, created_by=logged_in_user)
        self.m_env.save_as(v)
Ejemplo n.º 26
0
    def add_take(self, take_name):
        """adds a new take to the takes list
        """
        # condition the input
        take_name = Version._format_take_name(take_name)

        # if the given take name is in the list don't add it
        if take_name not in self._take_names:
            # add the item via property
            new_take_list = self._take_names
            new_take_list.append(take_name)
            new_take_list.sort()
            self.take_names = new_take_list

            # select the newly added take name
            items = self.findItems(take_name, QtCore.Qt.MatchExactly)
            if items:
                item = items[0]
                # set the take to the new one
                self.setCurrentItem(item)
Ejemplo n.º 27
0
def export_camera():
    """exports camera and the related shot node
    """
    from stalker import Task, Version
    from anima.env import mayaEnv

    m = mayaEnv.Maya()

    v = m.get_current_version()

    shot = pm.ls(type='shot')[0]
    try:
        sequencer = pm.ls(shot.message.connections(), type='sequencer')[0]
    except IndexError:
        sequencer = None

    camera = None
    if shot:
        camera = shot.currentCamera.get()

    camera_task = \
        Task.query\
            .filter(Task.parent == v.task.parent)\
            .filter(Task.name == 'Camera').first()

    if camera_task:
        from stalker import LocalSession
        local_session = LocalSession()
        logged_in_user = local_session.logged_in_user

        cam_v = Version(task=camera_task,
                        description='Exported from %s task on Publish' %
                        v.task.name)
        cam_v.update_paths()
        cam_v.extension = '.ma'
        cam_v.is_published = True
        cam_v.created_by = cam_v.updated_by = logged_in_user

        pm.select([shot, camera, sequencer])

        m.export_as(cam_v)
Ejemplo n.º 28
0
    def test_inequality_operator(self):
        """testing inequality of two Version instances
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertTrue(new_version1 != new_version2)
        self.assertTrue(new_version1 != new_version3)
        self.assertTrue(new_version1 != new_version4)
        self.assertTrue(new_version1 != new_version5)

        self.assertTrue(new_version2 != new_version3)
        self.assertTrue(new_version2 != new_version4)
        self.assertTrue(new_version2 != new_version5)

        self.assertTrue(new_version3 != new_version4)
        self.assertTrue(new_version3 != new_version5)

        self.assertTrue(new_version4 != new_version5)
Ejemplo n.º 29
0
    def test_get_version_from_full_path_with_multiple_repositories(self):
        """testing if the get version from full path is working fine with
        multiple repositories and with same version names
        """
        repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/")
        DBSession.add(repo1)

        repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/")
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="$REPO{{project.repository.id}}/{{project.code}}/"
            "{%- for parent_task in parent_tasks -%}"
            "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name="Commercial Project Structure", templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name="Status 1", code="STS1")
        status2 = Status(name="Status 2", code="STS2")
        status3 = Status(name="Status 3", code="STS3")
        DBSession.add_all([status1, status2, status3])

        proj_status_list = StatusList(
            name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3]
        )
        DBSession.add(proj_status_list)

        task_status_list = StatusList(
            name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3]
        )
        DBSession.add(task_status_list)

        version_status_list = StatusList(
            name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3]
        )
        DBSession.add(version_status_list)

        project1 = Project(
            name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list
        )
        DBSession.add(project1)

        project2 = Project(
            name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list
        )
        DBSession.add(project2)

        task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task2, status_list=version_status_list)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        DBSession.commit()
        logger.debug("version1.full_path : %s" % version1.full_path)
        logger.debug("version2.full_path : %s" % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        # version1
        version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version1_found, version1)

        # version2
        version2_found = env.get_version_from_full_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version2_found, version2)

        # version1 in windows
        version1_found = env.get_version_from_full_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version1_found, version1)

        # version2 in windows
        version2_found = env.get_version_from_full_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version2_found, version2)

        # version1 in linux
        version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version1_found, version1)

        # version2 in linux
        version2_found = env.get_version_from_full_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version2_found, version2)

        # version1 in osx
        version1_found = env.get_version_from_full_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version1_found, version1)

        # version2 in osx
        version2_found = env.get_version_from_full_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(version2_found, version2)
Ejemplo n.º 30
0
    def setUp(self):
        """setup the test
        """
        DBSession.remove()
        db.setup()

        # statuses
        self.test_status1 = Status(name="Status1", code="STS1")
        self.test_status2 = Status(name="Status2", code="STS2")
        self.test_status3 = Status(name="Status3", code="STS3")
        self.test_status4 = Status(name="Status4", code="STS4")
        self.test_status5 = Status(name="Status5", code="STS5")

        # status lists
        self.test_project_status_list = StatusList(
            name="Project Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Project,
        )

        self.test_sequence_status_list = StatusList(
            name="Sequence Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Sequence,
        )

        self.test_shot_status_list = StatusList(
            name="Shot Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Shot,
        )

        self.test_task_status_list = StatusList(
            name="Task Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Task,
        )

        self.test_version_status_list = StatusList(
            name="Version Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Version,
        )

        # repository
        self.test_repo = Repository(
            name="Test Repository", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/"
        )

        # a project type
        self.test_project_type = Type(name="Test", code="test", target_entity_type=Project)

        # create a structure
        self.test_structure = Structure(name="Test Project Structure")

        # create a project
        self.test_project = Project(
            name="Test Project",
            code="tp",
            type=self.test_project_type,
            status_list=self.test_project_status_list,
            repository=self.test_repo,
            structure=self.test_structure,
        )

        # create a sequence
        self.test_sequence = Sequence(
            name="Test Sequence", code="SEQ1", project=self.test_project, status_list=self.test_sequence_status_list
        )

        # create a shot
        self.test_shot1 = Shot(
            name="SH001",
            code="SH001",
            project=self.test_project,
            sequences=[self.test_sequence],
            status_list=self.test_shot_status_list,
        )

        # create a group of Tasks for the shot
        self.test_task1 = Task(name="Task1", parent=self.test_shot1, status_list=self.test_task_status_list)

        # a Link for the input file
        self.test_input_link1 = Link(
            name="Input Link 1",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_beauty_v001.###.exr",
        )

        self.test_input_link2 = Link(
            name="Input Link 2",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_occ_v001.###.exr",
        )

        # a Link for the output file
        self.test_output_link1 = Link(
            name="Output Link 1",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_beauty_v001.###.exr",
        )

        self.test_output_link2 = Link(
            name="Output Link 2",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_occ_v001.###.exr",
        )

        # now create a version for the Task
        self.kwargs = {
            "take_name": "TestTake",
            "inputs": [self.test_input_link1, self.test_input_link2],
            "outputs": [self.test_output_link1, self.test_output_link2],
            "task": self.test_task1,
            "status_list": self.test_version_status_list,
            "created_with": "Houdini",
        }

        self.take_name_test_values = [
            ("Take Name", "Take_Name"),
            ("TakeName", "TakeName"),
            ("take name", "take_name"),
            ("  take_name", "take_name"),
            ("take_name   ", "take_name"),
            ("   take   name   ", "take_name"),
            ("TakeName", "TakeName"),
            ("Take___Name", "Take___Name"),
        ]

        # and the Version
        self.test_version = Version(**self.kwargs)

        # set the published to False
        self.test_version.is_published = False
Ejemplo n.º 31
0
    def test_trim_repo_path_with_multiple_repositories(self):
        """testing if the trim_repo_path is working fine with multiple
        repositories and with same version names
        """
        repo0 = Repository(
            name="Test Repo 0",
            linux_path="/mnt/T/with_a_very_long_path_which_will_cause_errors/",
            windows_path="T:/with_a_very_long_path_which_will_cause_errors/",
            osx_path="/Volumes/T/" "with_a_very_long_path_which_will_cause_errors/",
        )
        DBSession.add(repo0)

        repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/")
        DBSession.add(repo1)

        repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/")
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name="Commercial Project Structure", templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name="Status 1", code="STS1")
        status2 = Status(name="Status 2", code="STS2")
        status3 = Status(name="Status 3", code="STS3")
        DBSession.add_all([status1, status2, status3])

        proj_status_list = StatusList(
            name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3]
        )
        DBSession.add(proj_status_list)

        task_status_list = StatusList(
            name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3]
        )
        DBSession.add(task_status_list)

        version_status_list = StatusList(
            name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3]
        )
        DBSession.add(version_status_list)

        project1 = Project(
            name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list
        )
        DBSession.add(project1)

        project2 = Project(
            name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list
        )
        DBSession.add(project2)

        task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        version3 = Version(task=task2, status_list=version_status_list)
        DBSession.add(version3)
        DBSession.commit()
        version3.update_paths()

        version4 = Version(task=task2, status_list=version_status_list)
        DBSession.add(version4)
        DBSession.commit()
        version4.update_paths()

        DBSession.commit()
        logger.debug("version1.full_path : %s" % version1.full_path)
        logger.debug("version2.full_path : %s" % version2.full_path)
        logger.debug("version3.full_path : %s" % version2.full_path)
        logger.debug("version4.full_path : %s" % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        expected_value1 = "TP1/Test_Task_1/Test_Task_1_Main_v001"
        expected_value2 = "TP2/Test_Task_1/Test_Task_1_Main_v001"

        # version1 native
        trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value1)

        # version2 native
        trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value2)

        # version1 windows
        trimmed_path = env.trim_repo_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value1)

        # version2 windows
        trimmed_path = env.trim_repo_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value2)

        # version1 linux
        trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value1)

        # version2 linux
        trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value2)

        # version1 osx
        trimmed_path = env.trim_repo_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value1)

        # version2 osx
        trimmed_path = env.trim_repo_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
        self.assertEqual(trimmed_path, expected_value2)
Ejemplo n.º 32
0
    def setUp(self):
        super(DailyDBTestDBCase, self).setUp()

        from stalker import Status, StatusList
        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_wfd = Status.query.filter_by(code='WFD').first()
        self.status_rts = Status.query.filter_by(code='RTS').first()
        self.status_wip = Status.query.filter_by(code='WIP').first()
        self.status_prev = Status.query.filter_by(code='PREV').first()
        self.status_hrev = Status.query.filter_by(code='HREV').first()
        self.status_drev = Status.query.filter_by(code='DREV').first()
        self.status_cmpl = Status.query.filter_by(code='CMPL').first()

        self.status_open = Status.query.filter_by(code='OPEN').first()
        self.status_cls = Status.query.filter_by(code='CLS').first()

        self.daily_status_list = \
            StatusList.query.filter_by(target_entity_type='Daily').first()

        self.task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()

        from stalker import Repository, Project
        self.test_repo = Repository(name='Test Repository', code='TR')
        from stalker.db.session import DBSession
        DBSession.add(self.test_repo)

        self.test_project = Project(
            name='Test Project',
            code='TP',
            repository=self.test_repo,
        )
        DBSession.add(self.test_project)

        from stalker import Task
        self.test_task1 = Task(name='Test Task 1',
                               project=self.test_project,
                               status_list=self.task_status_list)
        DBSession.add(self.test_task1)
        self.test_task2 = Task(name='Test Task 2',
                               project=self.test_project,
                               status_list=self.task_status_list)
        DBSession.add(self.test_task2)
        self.test_task3 = Task(name='Test Task 3',
                               project=self.test_project,
                               status_list=self.task_status_list)
        DBSession.add(self.test_task3)
        DBSession.commit()

        from stalker import Version
        self.test_version1 = Version(task=self.test_task1)
        DBSession.add(self.test_version1)
        DBSession.commit()
        self.test_version2 = Version(task=self.test_task1)
        DBSession.add(self.test_version2)
        DBSession.commit()
        self.test_version3 = Version(task=self.test_task1)
        DBSession.add(self.test_version3)
        DBSession.commit()
        self.test_version4 = Version(task=self.test_task2)
        DBSession.add(self.test_version4)
        DBSession.commit()

        from stalker import Link
        self.test_link1 = Link(original_filename='test_render1.jpg')
        self.test_link2 = Link(original_filename='test_render2.jpg')
        self.test_link3 = Link(original_filename='test_render3.jpg')
        self.test_link4 = Link(original_filename='test_render4.jpg')
        DBSession.add_all([
            self.test_link1, self.test_link2, self.test_link3, self.test_link4
        ])

        self.test_version1.outputs = [
            self.test_link1, self.test_link2, self.test_link3
        ]
        self.test_version4.outputs = [self.test_link4]
        DBSession.commit()
    status_list=proj_statuses,
    repository=repo,
    structure=flat_struct
)

# now lets create a Task
t1 = Task(name='Building 1', project=p1)
t2 = Task(name='Model', parent=t1)
t3 = Task(name='Lighting', parent=t1, depends=[t2])

# store all the data in the database
db.DBSession.add_all([t1, t2, t3])  # this is enough to store the rest


# lets create a Maya file for the Model task
t2_v1 = Version(task=t1)
t2_v1.update_paths()  # for now this is needed to render the template, but will
                   # remove it later on
t2_v1.extension = '.ma'  # set the extension for maya

# lets create a new version for Lighting
t3_v1 = Version(task=t3)
t3_v1.update_paths()
t3_v1.extension = '.ma'

# you should see that all are in the same folder
print(t2_v1.absolute_full_path)
print(t3_v1.absolute_full_path)

#
# Lets create a second Project that use some other folder structure
Ejemplo n.º 34
0
    def setUp(self):
        """create test data
        """
        database_url = 'sqlite:///:memory:'
        db.setup({'sqlalchemy.url': database_url})
        db.init()

        self.temp_repo_path = tempfile.mkdtemp()

        self.user1 = User(name='User 1',
                          login='******',
                          email='*****@*****.**',
                          password='******')

        self.repo1 = Repository(name='Test Project Repository',
                                linux_path=self.temp_repo_path,
                                windows_path=self.temp_repo_path,
                                osx_path=self.temp_repo_path)

        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_wip = Status.query.filter_by(code='WIP').first()
        self.status_comp = Status.query.filter_by(code='CMPL').first()

        self.task_template = FilenameTemplate(
            name='Task Template',
            target_entity_type='Task',
            path='{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/'
            '{%- endfor -%}',
            filename='{{version.nice_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )

        self.asset_template = FilenameTemplate(
            name='Asset Template',
            target_entity_type='Asset',
            path='{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/'
            '{%- endfor -%}',
            filename='{{version.nice_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )

        self.shot_template = FilenameTemplate(
            name='Shot Template',
            target_entity_type='Shot',
            path='{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/'
            '{%- endfor -%}',
            filename='{{version.nice_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )

        self.sequence_template = FilenameTemplate(
            name='Sequence Template',
            target_entity_type='Sequence',
            path='{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/'
            '{%- endfor -%}',
            filename='{{version.nice_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )

        self.structure = Structure(name='Project Struture',
                                   templates=[
                                       self.task_template, self.asset_template,
                                       self.shot_template,
                                       self.sequence_template
                                   ])

        self.project_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()

        self.image_format = ImageFormat(name='HD 1080',
                                        width=1920,
                                        height=1080,
                                        pixel_aspect=1.0)

        # create a test project
        self.project = Project(name='Test Project',
                               code='TP',
                               repository=self.repo1,
                               status_list=self.project_status_list,
                               structure=self.structure,
                               image_format=self.image_format)

        # create task hierarchy
        #
        # ASSETS
        #
        self.assets = Task(name='Assets',
                           project=self.project,
                           responsible=[self.user1])

        #
        # SEQUENCES
        #
        self.sequences = Task(name='Sequences',
                              project=self.project,
                              responsible=[self.user1])

        self.seq001 = Sequence(name='Seq001',
                               code='Seq001',
                               parent=self.sequences)

        self.scene_task = Task(name='001_IST', parent=self.seq001)

        self.scene_previs_type = Type(name='Scene Previs',
                                      code='Scene Previs',
                                      target_entity_type='Task')

        self.scene_previs = Task(name='Scene Previs',
                                 parent=self.scene_task,
                                 type=self.scene_previs_type)

        self.shots = Task(name='Shots', parent=self.scene_task)

        self.shot1 = Shot(name='Seq001_001_IST_0010',
                          code='Seq001_001_IST_0010',
                          parent=self.shots)

        # create shot tasks
        self.previs = Task(name='Previs', parent=self.shot1)

        self.camera = Task(name='Camera', parent=self.shot1)

        self.animation = Task(name='Animation', parent=self.shot1)

        self.scene_assembly = Task(name='SceneAssembly', parent=self.shot1)

        self.lighting = Task(name='Lighting', parent=self.shot1)

        self.comp = Task(name='Comp', parent=self.shot1)

        # create maya files
        self.maya_env = Maya()
        pm.newFile(force=True)

        sm = pm.PyNode('sequenceManager1')

        seq1 = sm.create_sequence('001_IST')

        # create 3 shots
        shot1 = seq1.create_shot('shot1')
        shot2 = seq1.create_shot('shot2')
        shot3 = seq1.create_shot('shot3')

        # set shot ranges
        shot1.startFrame.set(1)
        shot1.endFrame.set(100)

        shot2.startFrame.set(101)
        shot2.endFrame.set(200)
        shot2.sequenceStartFrame.set(101)

        shot3.startFrame.set(201)
        shot3.endFrame.set(300)
        shot3.sequenceStartFrame.set(201)

        # save the file under scene previs
        v = Version(task=self.scene_previs)

        self.maya_env.save_as(v)
        pm.newFile(force=1)
        print(v.absolute_full_path)
Ejemplo n.º 35
0
    def test_update_paths_will_render_the_appropriate_template_from_the_related_project(self):
        """testing if update_paths method will update the Version.full_path by
        rendering the related Project FilenameTemplate.
        """
        # create a FilenameTemplate for Task instances

        # A Template for Assets
        # ......../Assets/{{asset.type.name}}/{{asset.nice_name}}/{{task.type.name}}/
        #
        # Project1/Assets/Character/Sero/Modeling/Sero_Modeling_Main_v001.ma
        #
        # + Project1
        # |
        # +-+ Assets (Task)
        # | |
        # | +-+ Characters
        # |   |
        # |   +-+ Sero (Asset)
        # |     |
        # |     +-> Version 1
        # |     |
        # |     +-+ Modeling (Task)
        # |       |
        # |       +-+ Body Modeling (Task)
        # |         |
        # |         +-+ Coarse Modeling (Task)
        # |         | |
        # |         | +-> Version 1 (Version)
        # |         |
        # |         +-+ Fine Modeling (Task)
        # |           |
        # |           +-> Version 1 (Version): Fine_Modeling_Main_v001.ma
        # |                                  Assets/Sero/Modeling/Body_Modeling/Fine_Modeling/Fine_Modeling_Main_v001.ma
        # |
        # +-+ Shots (Task)
        #   |
        #   +-+ Shot 10 (Shot)
        #   | |
        #   | +-+ Layout (Task)
        #   |   |
        #   |   +-> Version 1 (Version): Layout_v001.ma
        #   |                            Shots/Shot_1/Layout/Layout_Main_v001.ma
        #   |
        #   +-+ Shot 2 (Shot)
        #     |
        #     +-+ FX (Task)
        #       |
        #       +-> Version 1 (Version)

        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()
        new_version1.update_paths()

        self.assertEqual(new_version1.path, "tp/SH001/Task1")

        new_version1.extension = ".ma"
        self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")
Ejemplo n.º 36
0
    def setUpClass(cls):
        """setup once
        """
        # remove the transaction manager
        db.DBSession.remove()

        cls.repo_path = tempfile.mkdtemp()

        defaults.local_storage_path = tempfile.mktemp()

        db.setup({
            'sqlalchemy.url': 'sqlite:///:memory:',
            'sqlalchemy.echo': 'false'
        })
        db.init()

        # create Power Users Group
        cls.power_users_group = Group(name='Power Users')
        db.DBSession.add(cls.power_users_group)
        db.DBSession.commit()

        # create a LocalSession first
        cls.admin = User.query.all()[0]
        cls.lsession = LocalSession()
        cls.lsession.store_user(cls.admin)
        cls.lsession.save()

        # create a repository
        cls.test_repo1 = Repository(name='Test Repository',
                                    windows_path='T:/TestRepo/',
                                    linux_path='/mnt/T/TestRepo/',
                                    osx_path='/Volumes/T/TestRepo/')

        cls.test_structure1 = Structure(name='Test Project Structure',
                                        templates=[],
                                        custom_template='')

        cls.status_new = Status.query.filter_by(code='NEW').first()
        cls.status_wip = Status.query.filter_by(code='WIP').first()
        cls.status_cmpl = Status.query.filter_by(code='CMPL').first()

        cls.project_status_list = StatusList(
            name='Project Statuses',
            statuses=[cls.status_new, cls.status_wip, cls.status_cmpl],
            target_entity_type=Project)

        # create a couple of projects
        cls.test_project1 = Project(name='Project 1',
                                    code='P1',
                                    repository=cls.test_repo1,
                                    structure=cls.test_structure1,
                                    status_list=cls.project_status_list)

        cls.test_project2 = Project(name='Project 2',
                                    code='P2',
                                    repository=cls.test_repo1,
                                    structure=cls.test_structure1,
                                    status_list=cls.project_status_list)

        cls.test_project3 = Project(name='Project 3',
                                    code='P3',
                                    repository=cls.test_repo1,
                                    structure=cls.test_structure1,
                                    status_list=cls.project_status_list)

        cls.projects = [
            cls.test_project1, cls.test_project2, cls.test_project3
        ]

        cls.test_user1 = User(
            name='Test User',
            # groups=[self.power_users_group],
            login='******',
            email='*****@*****.**',
            password='******')
        db.DBSession.add(cls.test_user1)
        db.DBSession.commit()

        cls.admin.projects.append(cls.test_project1)
        cls.admin.projects.append(cls.test_project2)
        cls.admin.projects.append(cls.test_project3)
        cls.test_user1.projects.append(cls.test_project1)
        cls.test_user1.projects.append(cls.test_project2)
        cls.test_user1.projects.append(cls.test_project3)

        # project 1
        cls.test_task1 = Task(
            name='Test Task 1',
            project=cls.test_project1,
            resources=[cls.admin],
        )

        cls.test_task2 = Task(
            name='Test Task 2',
            project=cls.test_project1,
            resources=[cls.admin],
        )

        cls.test_task3 = Task(
            name='Test Task 2',
            project=cls.test_project1,
            resources=[cls.admin],
        )

        # project 2
        cls.test_task4 = Task(
            name='Test Task 4',
            project=cls.test_project2,
            resources=[cls.admin],
        )

        cls.test_task5 = Task(
            name='Test Task 5',
            project=cls.test_project2,
            resources=[cls.admin],
        )

        cls.test_task6 = Task(
            name='Test Task 6',
            parent=cls.test_task5,
            resources=[cls.admin],
        )

        cls.test_task7 = Task(
            name='Test Task 7',
            parent=cls.test_task5,
            resources=[],
        )

        cls.test_task8 = Task(
            name='Test Task 8',
            parent=cls.test_task5,
            resources=[],
        )

        cls.test_task9 = Task(
            name='Test Task 9',
            parent=cls.test_task5,
            resources=[],
        )

        # +-> Project 1
        # | |
        # | +-> Task1
        # | |
        # | +-> Task2
        # | |
        # | +-> Task3
        # |
        # +-> Project 2
        # | |
        # | +-> Task4
        # | |
        # | +-> Task5
        # |   |
        # |   +-> Task6
        # |   |
        # |   +-> Task7 (no resource)
        # |   |
        # |   +-> Task8 (no resource)
        # |   |
        # |   +-> Task9 (no resource)
        # |
        # +-> Project 3

        # record them all to the db
        db.DBSession.add_all([
            cls.admin, cls.test_project1, cls.test_project2, cls.test_project3,
            cls.test_task1, cls.test_task2, cls.test_task3, cls.test_task4,
            cls.test_task5, cls.test_task6, cls.test_task7, cls.test_task8,
            cls.test_task9
        ])
        db.DBSession.commit()

        cls.all_tasks = [
            cls.test_task1, cls.test_task2, cls.test_task3, cls.test_task4,
            cls.test_task5, cls.test_task6, cls.test_task7, cls.test_task8,
            cls.test_task9
        ]

        # create versions
        cls.test_version1 = Version(cls.test_task1,
                                    created_by=cls.admin,
                                    created_with='Test',
                                    description='Test Description')
        db.DBSession.add(cls.test_version1)
        db.DBSession.commit()

        cls.test_version2 = Version(cls.test_task1,
                                    created_by=cls.admin,
                                    created_with='Test',
                                    description='Test Description')
        db.DBSession.add(cls.test_version2)
        db.DBSession.commit()

        cls.test_version3 = Version(cls.test_task1,
                                    created_by=cls.admin,
                                    created_with='Test',
                                    description='Test Description')
        cls.test_version3.is_published = True
        db.DBSession.add(cls.test_version3)
        db.DBSession.commit()

        cls.test_version4 = Version(cls.test_task1,
                                    take_name='Main@GPU',
                                    created_by=cls.admin,
                                    created_with='Test',
                                    description='Test Description')
        cls.test_version4.is_published = True
        db.DBSession.add(cls.test_version4)
        db.DBSession.commit()

        if not QtGui.QApplication.instance():
            logger.debug('creating a new QApplication')
            cls.app = QtGui.QApplication(sys.argv)
        else:
            logger.debug('using the present QApplication: %s' % QtGui.qApp)
            # self.app = QtGui.qApp
            cls.app = QtGui.QApplication.instance()

        # cls.test_environment = TestEnvironment()
        cls.dialog = version_creator.MainDialog()
Ejemplo n.º 37
0
def test_readme_tutorial_code(setup_sqlite3):
    """Tests the tutorial code in README.rst
    """
    from stalker import db
    db.setup()
    db.init()

    from stalker.db.session import DBSession
    assert str(DBSession.connection().engine.url) == 'sqlite://'

    from stalker import User
    me = User(name='Erkan Ozgur Yilmaz',
              login='******',
              email='*****@*****.**',
              password='******')

    # Save the user to database
    DBSession.save(me)

    from stalker import Repository
    repo = Repository(name='Commercial Projects Repository',
                      code='CPR',
                      windows_path='Z:/Projects',
                      linux_path='/mnt/Z/Projects',
                      osx_path='/Volumes/Z/Projects')

    from stalker import FilenameTemplate

    task_template = FilenameTemplate(
        name='Standard Task Filename Template',
        target_entity_type='Task',  # This is for files saved for Tasks
        path='{{project.repository.path}}/{{project.code}}/'
        '{%- for parent_task in parent_tasks -%}'
        '{{parent_task.nice_name}}/'
        '{%- endfor -%}',  # This is Jinja2 template code
        filename=
        '{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}')

    from stalker import Structure
    standard_folder_structure = Structure(
        name='Standard Project Folder Structure',
        templates=[task_template],
        custom_template=
        '{{project.code}}/References'  # If you need extra folders
    )

    from stalker import Project
    new_project = Project(
        name='Test Project',
        code='TP',
        structure=standard_folder_structure,
        repositories=[repo
                      ],  # if you have more than one repository you can do it
    )

    from stalker import ImageFormat
    hd1080 = ImageFormat(name='1080p', width=1920, height=1080)

    new_project.image_format = hd1080

    # Save the project and all the other data it is connected to it
    DBSession.save(new_project)

    from stalker import Task, Asset, Shot, Type

    # define Character asset type
    char_type = Type(name='Character', code='CHAR', target_entity_type='Asset')

    character1 = Asset(name='Character 1',
                       code='CHAR1',
                       type=char_type,
                       project=new_project)

    # Save the Asset
    DBSession.save(character1)

    model = Task(name='Model', parent=character1)

    rigging = Task(
        name='Rig',
        parent=character1,
        depends=[model
                 ],  # For project management, define that Rig can not start
        # before Model ends.
    )

    # Save the new tasks
    DBSession.save([model, rigging])

    # A shot and some tasks for it
    shot = Shot(name='SH001', code='SH001', project=new_project)

    # Save the Shot
    DBSession.save(shot)

    animation = Task(
        name='Animation',
        parent=shot,
    )

    lighting = Task(
        name='Lighting',
        parent=shot,
        depends=[animation],  # Lighting can not start before Animation ends,
        schedule_timing=1,
        schedule_unit='d',  # The task expected to take 1 day to complete
        resources=[me])
    DBSession.save([animation, lighting])

    from stalker import Version

    new_version = Version(task=animation)
    new_version.update_paths()  # to render the naming convention template
    new_version.extension = '.ma'  # let's say that we have created under Maya

    assert new_version.absolute_full_path == \
        "%sTP/SH001/Animation/SH001_Animation_Main_v001.ma" % \
        repo.path
    assert new_version.version_number == 1

    new_version2 = Version(task=animation)
    new_version2.update_paths()  # to render the naming convention template
    new_version2.extension = '.ma'  # let's say that we have created under Maya

    assert new_version2.version_number == 2
Ejemplo n.º 38
0
    def setUp(self):
        """set up the test
        """
        super(TicketTester, self).setUp()

        # create statuses
        from stalker import Status
        self.test_status1 = Status(name='N', code='N')
        self.test_status2 = Status(name='R', code='R')

        # get the ticket types
        from stalker import Type
        ticket_types = Type.query \
            .filter(Type.target_entity_type == 'Ticket').all()
        self.ticket_type_1 = ticket_types[0]
        self.ticket_type_2 = ticket_types[1]

        # create a User
        from stalker import User
        self.test_user = User(name='Test User',
                              login='******',
                              email='*****@*****.**',
                              password='******')

        # create a Repository
        from stalker import Repository
        self.test_repo = Repository(name="Test Repo")

        # create a Project Type
        self.test_project_type = Type(
            name='Commercial Project',
            code='comm',
            target_entity_type='Project',
        )

        # create a Project StatusList
        self.test_project_status1 = Status(name='PrjStat1', code='PrjStat1')
        self.test_project_status2 = Status(name='PrjStat2', code='PrjStat2')

        from stalker import StatusList
        self.test_project_status_list = StatusList(
            name="Project Status List",
            target_entity_type='Project',
            statuses=[
                self.test_project_status1,
                self.test_project_status2,
            ])

        self.test_task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()

        # create a Project
        from stalker import Project
        self.test_project = Project(name="Test Project 1",
                                    code="TEST_PROJECT_1",
                                    type=self.test_project_type,
                                    repository=self.test_repo,
                                    status_list=self.test_project_status_list)

        # create an Asset
        self.test_asset_status_list = StatusList.query\
            .filter_by(target_entity_type='Asset').first()

        self.test_asset_type = Type(name='Character Asset',
                                    code='char',
                                    target_entity_type='Asset')

        from stalker import Asset
        self.test_asset = Asset(name="Test Asset",
                                code='ta',
                                project=self.test_project,
                                status_list=self.test_asset_status_list,
                                type=self.test_asset_type)

        # create a Task
        from stalker import Task
        self.test_task = Task(name="Modeling of Asset 1",
                              resources=[self.test_user],
                              status_list=self.test_task_status_list,
                              parent=self.test_asset)

        # create a Version
        self.test_version_status_list = StatusList(
            name='Version Statuses',
            target_entity_type='Version',
            statuses=[self.test_status1, self.test_status2])

        from stalker import Version
        self.test_version = Version(name='Test Version',
                                    task=self.test_task,
                                    status_list=self.test_version_status_list,
                                    version=1,
                                    full_path='some/path')

        # create the Ticket
        self.kwargs = {
            'project': self.test_project,
            'links': [self.test_version],
            'summary': 'This is a test ticket',
            'description': 'This is the long description',
            'priority': 'TRIVIAL',
            'reported_by': self.test_user,
        }

        from stalker import db, Ticket
        self.test_ticket = Ticket(**self.kwargs)
        db.DBSession.add(self.test_ticket)
        db.DBSession.commit()

        # get the Ticket Statuses
        self.status_new = Status.query.filter_by(name='New').first()
        self.status_accepted = Status.query.filter_by(name='Accepted').first()
        self.status_assigned = Status.query.filter_by(name='Assigned').first()
        self.status_reopened = Status.query.filter_by(name='Reopened').first()
        self.status_closed = Status.query.filter_by(name='Closed').first()
Ejemplo n.º 39
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()
Ejemplo n.º 40
0
    def setUp(self):
        super(DailyTestBase, self).setUp()

        from stalker import db, Status, StatusList
        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_wip = Status.query.filter_by(code='WIP').first()
        self.status_cmpl = Status.query.filter_by(code='CMPL').first()

        self.test_project_status_list = StatusList(
            name='Project Statuses',
            target_entity_type='Project',
            statuses=[self.status_new, self.status_wip, self.status_cmpl])
        db.DBSession.add(self.test_project_status_list)

        from stalker import Repository, Project
        self.test_repo = Repository(name='Test Repository')
        db.DBSession.add(self.test_repo)

        self.test_project = Project(name='Test Project',
                                    code='TP',
                                    repository=self.test_repo,
                                    status_list=self.test_project_status_list)
        db.DBSession.add(self.test_project)

        from stalker import Task
        self.test_task1 = Task(name='Test Task 1', project=self.test_project)
        db.DBSession.add(self.test_task1)
        self.test_task2 = Task(name='Test Task 2', project=self.test_project)
        db.DBSession.add(self.test_task2)
        self.test_task3 = Task(name='Test Task 3', project=self.test_project)
        db.DBSession.add(self.test_task3)

        from stalker import Version
        self.test_version1 = Version(task=self.test_task1)
        db.DBSession.add(self.test_version1)
        db.DBSession.commit()

        self.test_version2 = Version(task=self.test_task1)
        db.DBSession.add(self.test_version2)
        db.DBSession.commit()

        self.test_version3 = Version(task=self.test_task1)
        db.DBSession.add(self.test_version3)
        db.DBSession.commit()

        self.test_version4 = Version(task=self.test_task2)
        db.DBSession.add(self.test_version4)
        db.DBSession.commit()

        from stalker import Link
        self.test_link1 = Link(original_filename='test_render1.jpg')
        self.test_link2 = Link(original_filename='test_render2.jpg')
        self.test_link3 = Link(original_filename='test_render3.jpg')
        self.test_link4 = Link(original_filename='test_render4.jpg')

        self.test_version1.outputs = [
            self.test_link1, self.test_link2, self.test_link3
        ]
        self.test_version4.outputs = [self.test_link4]

        db.DBSession.add_all([
            self.test_task1, self.test_task2, self.test_task3,
            self.test_version1, self.test_version2, self.test_version3,
            self.test_version4, self.test_link1, self.test_link2,
            self.test_link3, self.test_link4
        ])
        db.DBSession.commit()
Ejemplo n.º 41
0
    def save_previs_to_shots(self, take_name):
        """exports previs to animation shots
        """
        self.pre_publish_previs()

        shot_tasks = self.scene_shot_tasks
        shot_nodes = self.shot_list
        shots_to_export = []

        for shot_node in shot_nodes:
            for shot_task in shot_tasks:
                for task in shot_task.tasks:
                    if task.type == self.anim_type:
                        shot_number = shot_task.name.split('_')[-1]
                        if shot_node.getShotName() == shot_number:
                            shots_to_export.append(
                                [shot_node, task, shot_number])

        from anima.env import mayaEnv
        from stalker import Version
        from anima.ui.progress_dialog import ProgressDialogManager
        pdm = ProgressDialogManager()
        pdm.close()

        m_env = mayaEnv.Maya()

        versions = []
        description = 'Auto Created By Shot Exporter'
        # create versions to save and show in pop-up window
        for shot_info in shots_to_export:
            version = Version(task=shot_info[1],
                              description=description,
                              take_name=take_name,
                              created_by=self.logged_in_user)
            versions.append(version)

        if len(versions) != len(shots_to_export):
            from stalker.db.session import DBSession
            DBSession.rollback()
            raise RuntimeError(
                'Something is critically wrong. Contact Mehmet ERER.')

        # pop-up a window to show everything will be saved properly before actually doing it
        message = 'Shots will be Saved as Below:\r\n'
        message += '\r'
        index = 0
        for shot_info in shots_to_export:
            v = versions[index]
            message += 'shot[ %s ] -> %s\n' % (shot_info[2], v)
            index += 1
        dialog = pm.confirmDialog(
            title='Important Warning',
            message=message,
            button=['OK, Start Saving Shots', 'STOP, wrong paths!'])
        if dialog == 'OK, Start Saving Shots':
            pass
        else:
            from stalker.db.session import DBSession
            DBSession.rollback()
            raise RuntimeError('Process Interrupted by User.')

        previs_version = self.current_version

        errored_shots = []
        ind = 0
        caller = pdm.register(
            len(shots_to_export),
            'Batch Saving Previs Shot Nodes to Animation Shot Tasks...')
        from anima.env.mayaEnv import toolbox
        from stalker.db.session import DBSession
        for shot_info in shots_to_export:
            shot_task = versions[ind].task.parent
            try:
                # open previs version
                m_env.open(previs_version,
                           force=True,
                           reference_depth=3,
                           skip_update_check=True)

                # clear scene
                except_this_shot = pm.PyNode(shot_info[0].name())
                self.clear_scene(except_this_shot)

                # set frame range before save
                anima.env.mayaEnv.animation.Animation.set_range_from_shot()

                # update shot.cut_in and shot.cut_out info
                cut_in = pm.playbackOptions(q=1, min=1)
                cut_out = pm.playbackOptions(q=1, max=1)
                shot_task.cut_in = int(cut_in)
                shot_task.cut_out = int(cut_out)

                # save it
                m_env.save_as(versions[ind])
            except:
                errored_shots.append(shot_info[2])
            else:
                # store information to database
                DBSession.add(shot_task)
                DBSession.add(versions[ind])
                DBSession.commit()
            ind += 1

            caller.step()

        if errored_shots:
            message = 'Shots could not be saved:\r\n'
            message += '\r'
            for shot in errored_shots:
                message += '[ %s ]\n' % shot
            pm.confirmDialog(title='Error', message=message, button='OK')
            DBSession.rollback()
            raise RuntimeError(
                'Some Shots could not be saved. Contact Mehmet ERER.')

        # leave it as empty new file
        pm.newFile(force=True)
        message = 'Previs to Shots\r\n'
        message += '\r'
        message += 'Completed Succesfully.\r\n'
        pm.confirmDialog(title='Info', message=message, button='OK')
Ejemplo n.º 42
0
    def loads(self, data, parent=None):
        """Decodes Stalker data

        :param data:
        :return:
        """
        from stalker.db.session import DBSession
        from stalker import Asset, Task, Shot, Sequence, Version, Type

        if isinstance(data, str):
            data = json.loads(data)

        # get the entity_type
        entity_type = data['entity_type']

        # set default entity class to Task
        entity_class = Task
        if entity_type == 'Asset':
            entity_class = Asset
        elif entity_type == 'Shot':
            entity_class = Shot
            # this is a bug
            data['sequences'] = []
        elif entity_type == 'Sequence':
            entity_class = Sequence

        # get the type
        if 'type' in data:
            type_data = data['type']
            if type_data and not isinstance(type_data, Type):
                type_name = type_data['name']
                type_ = Type.query.filter(Type.name == type_name).first()
                if not type_:
                    # create a Type
                    type_ = Type(**type_data)
                data['type'] = type_

        # store version data
        version_data = sorted(data['versions'], key=lambda x: x["version_number"])
        data['versions'] = []

        data['project'] = self.project

        # check if the data exists before creating it
        entity = entity_class.query\
            .filter(entity_class.project==self.project)\
            .filter(entity_class.parent==parent)\
            .filter(entity_class.name==data['name'])\
            .first()

        if not entity:
            # then create it
            entity = entity_class(**data)
            DBSession.add(entity)
            DBSession.commit()

        # create Versions
        if version_data:
            for v_data in version_data:

                # check version number and take name
                # if there is a version with the same version_number
                # don't create it
                take_name = v_data['take_name']
                version_number = v_data['version_number']

                v = Version.query\
                    .filter(Version.task==entity)\
                    .filter(Version.take_name==take_name)\
                    .filter(Version.version_number==version_number)\
                    .first()

                if not v:
                    # then create it
                    # get Version info
                    v_data['task'] = entity
                    v = Version(**v_data)
                    # update version_number
                    v.version_number = v_data['version_number']
                    v.is_published = v_data['is_published']

            DBSession.commit()

        # for each child task call a new StalkerEntityDecoder
        for t in data['tasks']:
            self.loads(t, parent=entity)

        if parent:
            entity.parent = parent

        return entity
Ejemplo n.º 43
0
p1 = Project(name='Flat Project Example',
             code='FPE',
             status_list=proj_statuses,
             repository=repo,
             structure=flat_struct)

# now lets create a Task
t1 = Task(name='Building 1', project=p1)
t2 = Task(name='Model', parent=t1)
t3 = Task(name='Lighting', parent=t1, depends=[t2])

# store all the data in the database
db.DBSession.add_all([t1, t2, t3])  # this is enough to store the rest

# lets create a Maya file for the Model task
t2_v1 = Version(task=t1)
t2_v1.update_paths()  # for now this is needed to render the template, but will
# remove it later on
t2_v1.extension = '.ma'  # set the extension for maya

# lets create a new version for Lighting
t3_v1 = Version(task=t3)
t3_v1.update_paths()
t3_v1.extension = '.ma'

# you should see that all are in the same folder
print(t2_v1.absolute_full_path)
print(t3_v1.absolute_full_path)

#
# Lets create a second Project that use some other folder structure
Ejemplo n.º 44
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)
            )
Ejemplo n.º 45
0
    def publish_model_as_look_dev(cls):
        """Publishes Model versions as LookDev versions of the same task.

        Also handles references etc.
        """
        #
        # Create LookDev for Current Model Task
        #

        from stalker import Task, Version, Type, LocalSession
        from stalker.db.session import DBSession
        from anima import defaults
        from anima.env import mayaEnv

        do_db_setup()
        m = mayaEnv.Maya()

        local_session = LocalSession()
        logged_in_user = local_session.logged_in_user
        if not logged_in_user:
            raise RuntimeError('Please login to Stalker')

        model_type = Type.query.filter(Type.name=="Model").first()
        look_dev_type = \
            Type.query.filter(Type.name=="Look Development").first()

        current_version = m.get_current_version()
        model_task = current_version.task

        if model_task.type != model_type:
            raise RuntimeError('This is not a Model version')

        if not current_version.is_published:
            raise RuntimeError('Please Publish this maya scene')

        if current_version.take_name != 'Main':
            raise RuntimeError('This is not the Main take')

        # find lookDev
        look_dev = Task.query\
            .filter(Task.parent == model_task.parent)\
            .filter(Task.type == look_dev_type).first()

        if not look_dev:
            raise RuntimeError(
                'There is no LookDev task, please inform your Stalker admin'
            )

        previous_look_dev_version = \
            Version.query\
                .filter(Version.task == look_dev)\
                .filter(Version.take_name == 'Main')\
                .first()

        description = 'Auto Created By %s ' % logged_in_user.name
        take_name = defaults.version_take_name
        if not previous_look_dev_version:
            # do the trick
            pm.newFile(f=1)

            # create a new version
            new_version = Version(
                task=look_dev,
                description=description,
                take_name=take_name,
                created_by=logged_in_user
            )
            new_version.is_published = True

            m.save_as(new_version)

            # reference the model version
            pm.createReference(
                current_version.absolute_full_path,
                gl=True,
                namespace=current_version.nice_name,
                options='v=0'
            )

            pm.saveFile()
            DBSession.add(new_version)

        else:
            latest_look_dev_version = previous_look_dev_version.latest_version
            reference_resolution = m.open(latest_look_dev_version, force=True,
                                          skip_update_check=True)
            m.update_versions(reference_resolution)

            if reference_resolution['update'] \
               or reference_resolution['create']:
                # create a new version
                new_version = Version(
                    task=look_dev,
                    description=description,
                    take_name=take_name,
                    created_by=logged_in_user,
                    parent=latest_look_dev_version
                )
                new_version.is_published = True

                m.save_as(new_version)

        # reopen model scene
        m.open(current_version, force=True, skip_update_check=True)
Ejemplo n.º 46
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))
Ejemplo n.º 47
0
    def test_trim_repo_path_with_multiple_repositories(self):
        """testing if the trim_repo_path is working fine with multiple
        repositories and with same version names
        """
        repo0 = Repository(
            name='Test Repo 0',
            linux_path='/mnt/T/with_a_very_long_path_which_will_cause_errors/',
            windows_path='T:/with_a_very_long_path_which_will_cause_errors/',
            osx_path='/Volumes/T/'
            'with_a_very_long_path_which_will_cause_errors/')
        DBSession.add(repo0)

        repo1 = Repository(name='Test Repo 1',
                           linux_path='/mnt/T/',
                           windows_path='T:/',
                           osx_path='/Volumes/T/')
        DBSession.add(repo1)

        repo2 = Repository(name='Test Repo 2',
                           linux_path='/mnt/S/',
                           windows_path='S:/',
                           osx_path='/Volumes/S/')
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name='Task Filename Template',
            target_entity_type='Task',
            path='{{project.code}}/{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/{%- endfor -%}',
            filename='{{task.nice_name}}_{{version.take_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name='Commercial Project Structure',
                               templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name='Status 1', code='STS1')
        status2 = Status(name='Status 2', code='STS2')
        status3 = Status(name='Status 3', code='STS3')
        DBSession.add_all([status1, status2, status3])

        proj_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()

        task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()
        DBSession.add(task_status_list)

        project1 = Project(name='Test Project 1',
                           code='TP1',
                           repositories=[repo1],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project1)

        project2 = Project(name='Test Project 2',
                           code='TP2',
                           repositories=[repo2],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project2)

        task1 = Task(name='Test Task 1',
                     code='TT1',
                     project=project1,
                     status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name='Test Task 1',
                     code='TT1',
                     project=project2,
                     status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task1)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        version3 = Version(task=task2)
        DBSession.add(version3)
        DBSession.commit()
        version3.update_paths()

        version4 = Version(task=task2)
        DBSession.add(version4)
        DBSession.commit()
        version4.update_paths()

        DBSession.commit()
        logger.debug('version1.full_path : %s' % version1.full_path)
        logger.debug('version2.full_path : %s' % version2.full_path)
        logger.debug('version3.full_path : %s' % version2.full_path)
        logger.debug('version4.full_path : %s' % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        expected_value1 = 'TP1/Test_Task_1/Test_Task_1_Main_v001'
        expected_value2 = 'TP2/Test_Task_1/Test_Task_1_Main_v001'

        # version1 native
        trimmed_path = env.trim_repo_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 native
        trimmed_path = env.trim_repo_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 windows
        trimmed_path = env.trim_repo_path(
            'T:/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 windows
        trimmed_path = env.trim_repo_path(
            'S:/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 linux
        trimmed_path = env.trim_repo_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 linux
        trimmed_path = env.trim_repo_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)

        # version1 osx
        trimmed_path = env.trim_repo_path(
            '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value1)

        # version2 osx
        trimmed_path = env.trim_repo_path(
            '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(trimmed_path, expected_value2)
Ejemplo n.º 48
0
    def test_get_version_from_full_path_with_multiple_repositories(self):
        """testing if the get version from full path is working fine with
        multiple repositories and with same version names
        """
        repo1 = Repository(name='Test Repo 1',
                           linux_path='/mnt/T/',
                           windows_path='T:/',
                           osx_path='/Volumes/T/')
        DBSession.add(repo1)

        repo2 = Repository(name='Test Repo 2',
                           linux_path='/mnt/S/',
                           windows_path='S:/',
                           osx_path='/Volumes/S/')
        DBSession.add(repo2)

        task_ft = FilenameTemplate(
            name='Task Filename Template',
            target_entity_type='Task',
            path='$REPO{{project.repository.code}}/{{project.code}}/'
            '{%- for parent_task in parent_tasks -%}'
            '{{parent_task.nice_name}}/{%- endfor -%}',
            filename='{{task.nice_name}}_{{version.take_name}}'
            '_v{{"%03d"|format(version.version_number)}}',
        )
        DBSession.add(task_ft)

        structure1 = Structure(name='Commercial Project Structure',
                               templates=[task_ft])
        DBSession.add(structure1)

        status1 = Status(name='Status 1', code='STS1')
        status2 = Status(name='Status 2', code='STS2')
        status3 = Status(name='Status 3', code='STS3')
        DBSession.add_all([status1, status2, status3])

        proj_status_list = \
            StatusList.query.filter_by(target_entity_type='Project').first()

        task_status_list = \
            StatusList.query.filter_by(target_entity_type='Task').first()

        version_status_list = StatusList(name='Version Statuses',
                                         target_entity_type='Version',
                                         statuses=[status1, status2, status3])
        DBSession.add(version_status_list)

        project1 = Project(name='Test Project 1',
                           code='TP1',
                           repositories=[repo1],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project1)

        project2 = Project(name='Test Project 2',
                           code='TP2',
                           repositories=[repo2],
                           structure=structure1,
                           status_list=proj_status_list)
        DBSession.add(project2)

        task1 = Task(name='Test Task 1',
                     code='TT1',
                     project=project1,
                     status_list=task_status_list)
        DBSession.add(task1)

        task2 = Task(name='Test Task 1',
                     code='TT1',
                     project=project2,
                     status_list=task_status_list)
        DBSession.add(task2)

        DBSession.commit()

        # now create versions
        version1 = Version(task=task1, status_list=version_status_list)
        DBSession.add(version1)
        DBSession.commit()
        version1.update_paths()

        version2 = Version(task=task2, status_list=version_status_list)
        DBSession.add(version2)
        DBSession.commit()
        version2.update_paths()

        DBSession.commit()
        logger.debug('version1.full_path : %s' % version1.full_path)
        logger.debug('version2.full_path : %s' % version2.full_path)

        # now try to get the versions with an EnvironmentBase instance
        env = EnvironmentBase()

        # version1
        version1_found = env.get_version_from_full_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2
        version2_found = env.get_version_from_full_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in windows
        version1_found = env.get_version_from_full_path(
            'T:/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in windows
        version2_found = env.get_version_from_full_path(
            'S:/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in linux
        version1_found = env.get_version_from_full_path(
            '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in linux
        version2_found = env.get_version_from_full_path(
            '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)

        # version1 in osx
        version1_found = env.get_version_from_full_path(
            '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version1_found, version1)

        # version2 in osx
        version2_found = env.get_version_from_full_path(
            '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001')
        self.assertEqual(version2_found, version2)
Ejemplo n.º 49
0
    name='Task Template for Commercials',
    target_entity_type='Task',
    path=
    '$REPO{{project.repository.id}}/{{project.code}}/{%- for p in parent_tasks -%}{{p.nice_name}}/{%- endfor -%}',
    filename='{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}'
)

# and append it to our project structure
commercial_project_structure.templates.append(task_template)

# commit to database
DBSession.commit()  # no need to add anything, project is already on db

from stalker import Version

vers1 = Version(task=comp)

# we need to update the paths
vers1.update_paths()

# check the path and filename
print(vers1.path)  # '$REPO33/FC/SH001/comp'
print(vers1.filename)  # 'SH001_comp_Main_v001'
print(vers1.full_path)  # '$REPO33/FC/SH001/comp/SH001_comp_Main_v001'
# now the absolute values, values with repository root
# because I'm running this code in a Linux laptop, my results are using the
# linux path of the repository
print(vers1.absolute_path)  # '/mnt/M/commercials/FC/SH001/comp'
print(vers1.absolute_full_path
      )  # '/mnt/M/commercials/FC/SH001/comp/SH001_comp_Main_v001'
Ejemplo n.º 50
0
class VersionTester(unittest.TestCase):
    """tests stalker.models.version.Version class
    """

    @classmethod
    def setUpClass(cls):
        """setting up the test in class level
        """
        DBSession.remove()

    @classmethod
    def tearDownClass(cls):
        """clean up the test in class level
        """
        DBSession.remove()

    def setUp(self):
        """setup the test
        """
        DBSession.remove()
        db.setup()

        # statuses
        self.test_status1 = Status(name="Status1", code="STS1")
        self.test_status2 = Status(name="Status2", code="STS2")
        self.test_status3 = Status(name="Status3", code="STS3")
        self.test_status4 = Status(name="Status4", code="STS4")
        self.test_status5 = Status(name="Status5", code="STS5")

        # status lists
        self.test_project_status_list = StatusList(
            name="Project Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Project,
        )

        self.test_sequence_status_list = StatusList(
            name="Sequence Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Sequence,
        )

        self.test_shot_status_list = StatusList(
            name="Shot Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Shot,
        )

        self.test_task_status_list = StatusList(
            name="Task Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Task,
        )

        self.test_version_status_list = StatusList(
            name="Version Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5],
            target_entity_type=Version,
        )

        # repository
        self.test_repo = Repository(
            name="Test Repository", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/"
        )

        # a project type
        self.test_project_type = Type(name="Test", code="test", target_entity_type=Project)

        # create a structure
        self.test_structure = Structure(name="Test Project Structure")

        # create a project
        self.test_project = Project(
            name="Test Project",
            code="tp",
            type=self.test_project_type,
            status_list=self.test_project_status_list,
            repository=self.test_repo,
            structure=self.test_structure,
        )

        # create a sequence
        self.test_sequence = Sequence(
            name="Test Sequence", code="SEQ1", project=self.test_project, status_list=self.test_sequence_status_list
        )

        # create a shot
        self.test_shot1 = Shot(
            name="SH001",
            code="SH001",
            project=self.test_project,
            sequences=[self.test_sequence],
            status_list=self.test_shot_status_list,
        )

        # create a group of Tasks for the shot
        self.test_task1 = Task(name="Task1", parent=self.test_shot1, status_list=self.test_task_status_list)

        # a Link for the input file
        self.test_input_link1 = Link(
            name="Input Link 1",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_beauty_v001.###.exr",
        )

        self.test_input_link2 = Link(
            name="Input Link 2",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_occ_v001.###.exr",
        )

        # a Link for the output file
        self.test_output_link1 = Link(
            name="Output Link 1",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_beauty_v001.###.exr",
        )

        self.test_output_link2 = Link(
            name="Output Link 2",
            full_path="/mnt/M/JOBs/TestProj/Seqs/TestSeq/Shots/SH001/FX/" "Outputs/SH001_occ_v001.###.exr",
        )

        # now create a version for the Task
        self.kwargs = {
            "take_name": "TestTake",
            "inputs": [self.test_input_link1, self.test_input_link2],
            "outputs": [self.test_output_link1, self.test_output_link2],
            "task": self.test_task1,
            "status_list": self.test_version_status_list,
            "created_with": "Houdini",
        }

        self.take_name_test_values = [
            ("Take Name", "Take_Name"),
            ("TakeName", "TakeName"),
            ("take name", "take_name"),
            ("  take_name", "take_name"),
            ("take_name   ", "take_name"),
            ("   take   name   ", "take_name"),
            ("TakeName", "TakeName"),
            ("Take___Name", "Take___Name"),
        ]

        # and the Version
        self.test_version = Version(**self.kwargs)

        # set the published to False
        self.test_version.is_published = False

    def tearDown(self):
        """clean up test
        """
        DBSession.remove()

    def test___auto_name__class_attribute_is_set_to_True(self):
        """testing if the __auto_name__ class attribute is set to True for
        Version class
        """
        self.assertTrue(Version.__auto_name__)

    def test_take_name_argument_is_skipped_defaults_to_default_value(self):
        """testing if the take_name argument is skipped the take attribute is
        going to be set to the default value which is
        stalker.conf.defaults.DEFAULT_VERSION_TAKE_NAME
        """
        self.kwargs.pop("take_name")
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.take_name, defaults.version_take_name)

    def test_take_name_argument_is_None(self):
        """testing if a TypeError will be raised when the take_name argument is
        None
        """
        self.kwargs["take_name"] = None
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_take_name_attribute_is_None(self):
        """testing if a TypeError will be raised when the take_name attribute
        is set to None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "take_name", None)

    def test_take_name_argument_is_empty_string(self):
        """testing if a ValueError will be raised when the take_name argument
        is given as an empty string
        """
        self.kwargs["take_name"] = ""
        self.assertRaises(ValueError, Version, **self.kwargs)

    def test_take_name_attribute_is_empty_string(self):
        """testing if a ValueError will be raised when the take_name attribute
        is set to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_version, "take_name", "")

    def test_take_name_argument_is_not_a_string(self):
        """testing if a TypeError will be raised when the given take_name
        argument is not a string
        """
        test_values = [1, 1.2, ["a list"], {"a": "dict"}]

        for test_value in test_values:
            self.kwargs["take_name"] = test_value
            with self.assertRaises(TypeError):
                Version(**self.kwargs)

    def test_take_name_attribute_is_not_a_string(self):
        """testing if a TypeError will be raised when take_name attribute is
        set to a value other than a string
        """
        test_values = [1, 1.2, ["a list"], {"a": "dict"}]

        for test_value in test_values:
            with self.assertRaises(TypeError):
                self.test_version.take_name = test_value

    def test_take_name_argument_is_formatted_to_empty_string(self):
        """testing if a ValueError will be raised when the take_name argument
        string is formatted to an empty string
        """
        self.kwargs["take_name"] = "##$½#$"
        self.assertRaises(ValueError, Version, **self.kwargs)

    def test_take_name_attribute_is_formatted_to_empty_string(self):
        """testing if a ValueError will be raised when the take_name argument
        string is formatted to an empty string
        """
        self.assertRaises(ValueError, setattr, self.test_version, "take_name", "##$½#$")

    def test_take_name_argument_is_formatted_correctly(self):
        """testing if the take_name argument value is formatted correctly
        """
        for test_value in self.take_name_test_values:
            self.kwargs["take_name"] = test_value[0]
            new_version = Version(**self.kwargs)
            self.assertEqual(new_version.take_name, test_value[1])

    def test_take_name_attribute_is_formatted_correctly(self):
        """testing if the take_name attribute value is formatted correctly
        """
        for test_value in self.take_name_test_values:
            self.test_version.take_name = test_value[0]
            self.assertEqual(self.test_version.take_name, test_value[1])

    def test_task_argument_is_skipped(self):
        """testing if a TypeError will be raised when the task argument
        is skipped
        """
        self.kwargs.pop("task")
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_task_argument_is_None(self):
        """testing if a TypeError will be raised when the task argument
        is None
        """
        self.kwargs["task"] = None
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_task_attribute_is_None(self):
        """testing if a TypeError will be raised when the task attribute
        is None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "task", None)

    def test_task_argument_is_not_a_Task(self):
        """testing if a TypeError will be raised when the task argument
        is not a Task instance
        """
        self.kwargs["task"] = "a task"
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_task_attribute_is_not_a_Task(self):
        """testing if a TypeError will be raised when the task attribute
        is not a Task instance
        """
        self.assertRaises(TypeError, setattr, self.test_version, "task", "a task")

    def test_task_attribute_is_working_properly(self):
        """testing if the task attribute is working properly
        """
        new_task = Task(name="New Test Task", parent=self.test_shot1, status_list=self.test_task_status_list)

        self.assertTrue(self.test_version.task is not new_task)
        self.test_version.task = new_task
        self.assertTrue(self.test_version.task is new_task)

    def test_version_number_attribute_is_automatically_generated(self):
        """testing if the version_number attribute is automatically generated
        """
        self.assertEqual(self.test_version.version_number, 1)
        DBSession.add(self.test_version)
        DBSession.commit()

        new_version = Version(**self.kwargs)
        DBSession.add(new_version)
        DBSession.commit()

        self.assertEqual(self.test_version.task, new_version.task)
        self.assertEqual(self.test_version.take_name, new_version.take_name)

        self.assertEqual(new_version.version_number, 2)

        new_version = Version(**self.kwargs)
        DBSession.add(new_version)
        DBSession.commit()

        self.assertEqual(self.test_version.task, new_version.task)
        self.assertEqual(self.test_version.take_name, new_version.take_name)

        self.assertEqual(new_version.version_number, 3)

        new_version = Version(**self.kwargs)
        DBSession.add(new_version)
        DBSession.commit()

        self.assertEqual(self.test_version.task, new_version.task)
        self.assertEqual(self.test_version.take_name, new_version.take_name)

        self.assertEqual(new_version.version_number, 4)

    def test_version_number_attribute_is_starting_from_1(self):
        """testing if the version_number attribute is starting from 1
        """
        self.assertEqual(self.test_version.version_number, 1)

    def test_version_number_attribute_is_set_to_a_lower_then_it_should_be(self):
        """testing if the version_number attribute will be set to a correct
        unique value when it is set to a lower number then it should be
        """
        self.test_version.version_number = -1
        self.assertEqual(self.test_version.version_number, 1)

        self.test_version.version_number = -10
        self.assertEqual(self.test_version.version_number, 1)

        DBSession.add(self.test_version)
        DBSession.commit()

        self.test_version.version_number = -100
        # it should be 1 again
        self.assertEqual(self.test_version.version_number, 1)

        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.version_number, 2)

        new_version.version_number = 1
        self.assertEqual(new_version.version_number, 2)

        new_version.version_number = 100
        self.assertEqual(new_version.version_number, 100)

    def test_inputs_argument_is_skipped(self):
        """testing if the inputs attribute will be an empty list when the
        inputs argument is skipped
        """
        self.kwargs.pop("inputs")
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.inputs, [])

    def test_inputs_argument_is_None(self):
        """testing if the inputs attribute will be an empty list when the
        inputs argument is None
        """
        self.kwargs["inputs"] = None
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.inputs, [])

    def test_inputs_attribute_is_None(self):
        """testing if a TypeError will be raised when the inputs argument is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "inputs", None)

    def test_inputs_argument_is_not_a_list_of_Link_instances(self):
        """testing if a TypeError will be raised when the inputs attribute is
        set to something other than a Link instance
        """
        test_value = [132, "231123"]
        self.kwargs["inputs"] = test_value
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_inputs_attribute_is_not_a_list_of_Link_instances(self):
        """testing if a TypeError will be raised when the inputs attribute is
        set to something other than a Link instance
        """
        test_value = [132, "231123"]
        self.assertRaises(TypeError, setattr, self.test_version, "inputs", test_value)

    def test_inputs_attribute_is_working_properly(self):
        """testing if the inputs attribute is working properly
        """
        self.kwargs.pop("inputs")
        new_version = Version(**self.kwargs)

        self.assertFalse(self.test_input_link1 in new_version.inputs)
        self.assertFalse(self.test_input_link2 in new_version.inputs)

        new_version.inputs = [self.test_input_link1, self.test_input_link2]

        self.assertTrue(self.test_input_link1 in new_version.inputs)
        self.assertTrue(self.test_input_link2 in new_version.inputs)

    def test_outputs_argument_is_skipped(self):
        """testing if the outputs attribute will be an empty list when the
        outputs argument is skipped
        """
        self.kwargs.pop("outputs")
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.outputs, [])

    def test_outputs_argument_is_None(self):
        """testing if the outputs attribute will be an empty list when the
        outputs argument is None
        """
        self.kwargs["outputs"] = None
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.outputs, [])

    def test_outputs_attribute_is_None(self):
        """testing if a TypeError will be raised when the outputs argument is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "outputs", None)

    def test_outputs_argument_is_not_a_list_of_Link_instances(self):
        """testing if a TypeError will be raised when the outputs attribute is
        set to something other than a Link instance
        """
        test_value = [132, "231123"]
        self.kwargs["outputs"] = test_value
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_outputs_attribute_is_not_a_list_of_Link_instances(self):
        """testing if a TypeError will be raised when the outputs attribute is
        set to something other than a Link instance
        """
        test_value = [132, "231123"]
        self.assertRaises(TypeError, setattr, self.test_version, "outputs", test_value)

    def test_outputs_attribute_is_working_properly(self):
        """testing if the outputs attribute is working properly
        """
        self.kwargs.pop("outputs")
        new_version = Version(**self.kwargs)

        self.assertFalse(self.test_output_link1 in new_version.outputs)
        self.assertFalse(self.test_output_link2 in new_version.outputs)

        new_version.outputs = [self.test_output_link1, self.test_output_link2]

        self.assertTrue(self.test_output_link1 in new_version.outputs)
        self.assertTrue(self.test_output_link2 in new_version.outputs)

    def test_is_published_attribute_is_False_by_default(self):
        """testing if the is_published attribute is False by default
        """
        self.assertEqual(self.test_version.is_published, False)

    def test_is_published_attribute_is_working_properly(self):
        """testing if the is_published attribute is working properly
        """
        self.test_version.is_published = True
        self.assertEqual(self.test_version.is_published, True)

        self.test_version.is_published = False
        self.assertEqual(self.test_version.is_published, False)

    def test_parent_argument_is_skipped(self):
        """testing if the parent attribute will be None if the parent argument
        is skipped
        """
        try:
            self.kwargs.pop("parent")
        except KeyError:
            pass
        new_version = Version(**self.kwargs)
        self.assertTrue(new_version.parent is None)

    def test_parent_argument_is_None(self):
        """testing if the parent attribute will be None if the parent argument
        is skipped
        """
        self.kwargs["parent"] = None
        new_version = Version(**self.kwargs)
        self.assertTrue(new_version.parent is None)

    def test_parent_attribute_is_None(self):
        """testing if the parent attribute value will be None if it is set to
        None
        """
        self.test_version.parent = None
        self.assertTrue(self.test_version.parent is None)

    def test_parent_argument_is_not_a_Version_instance(self):
        """testing if a TypeError will be raised when the parent argument is
        not a Version instance
        """
        self.kwargs["parent"] = "not a version instance"
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_parent_attribute_is_not_set_to_a_Version_instance(self):
        """testing if a TypeError will be raised when the parent attribute is
        not set to a Version instance
        """
        self.assertRaises(TypeError, setattr, self.test_version, "parent", "not a version instance")

    def test_parent_argument_is_working_properly(self):
        """testing if the parent argument is working properly
        """
        self.kwargs["parent"] = self.test_version
        new_version = Version(**self.kwargs)
        self.assertEqual(new_version.parent, self.test_version)

    def test_parent_attribute_is_working_properly(self):
        """testing if the parent attribute is working properly
        """
        self.kwargs["parent"] = None
        new_version = Version(**self.kwargs)
        self.assertNotEqual(new_version.parent, self.test_version)
        new_version.parent = self.test_version
        self.assertEqual(new_version.parent, self.test_version)

    def test_parent_argument_updates_the_children_attribute(self):
        """testing if the parent argument updates the children attribute of the
        parent Version properly
        """
        self.kwargs["parent"] = self.test_version
        new_version = Version(**self.kwargs)
        self.assertTrue(new_version in self.test_version.children)

    def test_parent_attribute_updates_the_children_attribute(self):
        """testing if the parent attribute updates the children attribute of
        the parent Version properly
        """
        self.kwargs["parent"] = None
        new_version = Version(**self.kwargs)
        self.assertNotEqual(new_version.parent, self.test_version)
        new_version.parent = self.test_version
        self.assertTrue(new_version in self.test_version.children)

    def test_parent_attribute_will_not_allow_circular_dependencies(self):
        """testing if a CircularDependency will be raised when the given
        Version to the parent attribute is a children of the current Version
        """
        self.kwargs["parent"] = self.test_version
        version1 = Version(**self.kwargs)
        self.assertRaises(CircularDependencyError, setattr, self.test_version, "parent", version1)

    def test_parent_attribute_will_not_allow_deeper_circular_dependencies(self):
        """testing if a CircularDependency will be raised when the given
        Version is a parent of the current parent
        """
        self.kwargs["parent"] = self.test_version
        version1 = Version(**self.kwargs)

        self.kwargs["parent"] = version1
        version2 = Version(**self.kwargs)

        # now create circular dependency
        self.assertRaises(CircularDependencyError, setattr, self.test_version, "parent", version2)

    def test_children_attribute_is_set_to_None(self):
        """testing if a TypeError will be raised when the children attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "children", None)

    def test_children_attribute_is_not_set_to_a_list(self):
        """testing if a TypeError will be raised when the children attribute is
        not set to a list
        """
        self.assertRaises(TypeError, setattr, self.test_version, "children", "not a list of Version instances")

    def test_children_attribute_is_not_set_to_a_list_of_Version_instances(self):
        """testing if a TypeError will be raised when the children attribute is
        not set to a list of Version instances
        """
        self.assertRaises(TypeError, setattr, self.test_version, "children", ["not a Version instance", 3])

    def test_children_attribute_is_working_properly(self):
        """testing if the children attribute is working properly
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        self.test_version.children = [new_version1]
        self.assertTrue(new_version1 in self.test_version.children)

        new_version2 = Version(**self.kwargs)
        self.test_version.children.append(new_version2)
        self.assertTrue(new_version2 in self.test_version.children)

    def test_children_attribute_updates_parent_attribute(self):
        """testing if the children attribute updates the parent attribute of
        the children Versions
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        self.test_version.children = [new_version1]
        self.assertEqual(new_version1.parent, self.test_version)

        new_version2 = Version(**self.kwargs)
        self.test_version.children.append(new_version2)
        self.assertEqual(new_version2.parent, self.test_version)

    def test_children_attribute_will_not_allow_circular_dependencies(self):
        """testing if a CircularDependency error will be raised when a parent
        Version is set as a children to its child
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        new_version2 = Version(**self.kwargs)

        new_version1.parent = new_version2
        self.assertRaises(CircularDependencyError, new_version1.children.append, new_version2)

    def test_children_attribute_will_not_allow_deeper_circular_dependencies(self):
        """testing if a CircularDependency error will be raised when the a
        parent Version of a parent Version is set as a children to its grand
        child
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        new_version2 = Version(**self.kwargs)
        new_version3 = Version(**self.kwargs)

        new_version1.parent = new_version2
        new_version2.parent = new_version3

        self.assertRaises(CircularDependencyError, new_version1.children.append, new_version3)

    def test_update_paths_will_render_the_appropriate_template_from_the_related_project(self):
        """testing if update_paths method will update the Version.full_path by
        rendering the related Project FilenameTemplate.
        """
        # create a FilenameTemplate for Task instances

        # A Template for Assets
        # ......../Assets/{{asset.type.name}}/{{asset.nice_name}}/{{task.type.name}}/
        #
        # Project1/Assets/Character/Sero/Modeling/Sero_Modeling_Main_v001.ma
        #
        # + Project1
        # |
        # +-+ Assets (Task)
        # | |
        # | +-+ Characters
        # |   |
        # |   +-+ Sero (Asset)
        # |     |
        # |     +-> Version 1
        # |     |
        # |     +-+ Modeling (Task)
        # |       |
        # |       +-+ Body Modeling (Task)
        # |         |
        # |         +-+ Coarse Modeling (Task)
        # |         | |
        # |         | +-> Version 1 (Version)
        # |         |
        # |         +-+ Fine Modeling (Task)
        # |           |
        # |           +-> Version 1 (Version): Fine_Modeling_Main_v001.ma
        # |                                  Assets/Sero/Modeling/Body_Modeling/Fine_Modeling/Fine_Modeling_Main_v001.ma
        # |
        # +-+ Shots (Task)
        #   |
        #   +-+ Shot 10 (Shot)
        #   | |
        #   | +-+ Layout (Task)
        #   |   |
        #   |   +-> Version 1 (Version): Layout_v001.ma
        #   |                            Shots/Shot_1/Layout/Layout_Main_v001.ma
        #   |
        #   +-+ Shot 2 (Shot)
        #     |
        #     +-+ FX (Task)
        #       |
        #       +-> Version 1 (Version)

        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()
        new_version1.update_paths()

        self.assertEqual(new_version1.path, "tp/SH001/Task1")

        new_version1.extension = ".ma"
        self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")

    def test_update_paths_will_preserve_extension(self):
        """testing if update_paths method will preserve the extension.
        """
        # create a FilenameTemplate for Task instances
        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()
        new_version1.update_paths()

        self.assertEqual(new_version1.path, "tp/SH001/Task1")

        extension = ".ma"
        new_version1.extension = extension
        self.assertEqual(new_version1.filename, "Task1_TestTake_v001.ma")

        # rename the task and update the paths
        self.test_task1.name = "Task2"

        # now call update_paths and expect the extension to be preserved
        new_version1.update_paths()
        self.assertEqual(new_version1.filename, "Task2_TestTake_v001.ma")
        self.assertEqual(new_version1.extension, extension)

    def test_update_paths_will_raise_a_RuntimeError_if_there_is_no_suitable_FilenameTemplate(self):
        """testing if update_paths method will raise a RuntimeError if there is
        no suitable FilenameTemplate instance found
        """
        self.kwargs["parent"] = None
        new_version1 = Version(**self.kwargs)
        self.assertRaises(RuntimeError, new_version1.update_paths)

    def test_template_variables_project(self):
        """testing if the project in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["project"], self.test_version.task.project)

    def test_template_variables_sequences(self):
        """testing if the sequences in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["sequences"], [])

    def test_template_variables_scenes(self):
        """testing if the scenes in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["scenes"], [])

    def test_template_variables_shot(self):
        """testing if the shot in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["shot"], self.test_version.task)

    def test_template_variables_asset(self):
        """testing if the asset in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["asset"], self.test_version.task)

    def test_template_variables_task(self):
        """testing if the task in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["task"], self.test_version.task)

    def test_template_variables_parent_tasks(self):
        """testing if the parent_tasks in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        parents = self.test_version.task.parents
        parents.append(self.test_version.task)
        self.assertEqual(kwargs["parent_tasks"], parents)

    def test_template_variables_version(self):
        """testing if the version in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["version"], self.test_version)

    def test_template_variables_type(self):
        """testing if the type in template variables is correct
        """
        kwargs = self.test_version._template_variables()
        self.assertEqual(kwargs["type"], self.test_version.type)

    def test_absolute_full_path_works_properly(self):
        """testing if the absolute_full_path attribute works properly
        """
        ft = FilenameTemplate(
            name="Task Filename Template",
            target_entity_type="Task",
            path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
            filename="{{task.nice_name}}_{{version.take_name}}"
            '_v{{"%03d"|format(version.version_number)}}{{extension}}',
        )
        self.test_project.structure.templates.append(ft)
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version1.update_paths()
        new_version1.extension = ".ma"
        self.assertEqual(new_version1.extension, ".ma")

        self.assertEqual(new_version1.absolute_full_path, "/mnt/T/tp/SH001/Task1/Task1_TestTake_v001.ma")

    def test_latest_published_version_is_read_only(self):
        """testing if the latest_published_version is a read only attribute
        """
        self.assertRaises(AttributeError, setattr, self.test_version, "latest_published_version", True)

    def test_latest_published_version_is_working_properly(self):
        """testing if the is_latest_published_version is working properly
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertEqual(new_version1.latest_published_version, new_version4)
        self.assertEqual(new_version2.latest_published_version, new_version4)
        self.assertEqual(new_version3.latest_published_version, new_version4)
        self.assertEqual(new_version4.latest_published_version, new_version4)
        self.assertEqual(new_version5.latest_published_version, new_version4)

    def test_is_latest_published_version_is_working_properly(self):
        """testing if the is_latest_published_version is working properly
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertFalse(new_version1.is_latest_published_version())
        self.assertFalse(new_version2.is_latest_published_version())
        self.assertFalse(new_version3.is_latest_published_version())
        self.assertTrue(new_version4.is_latest_published_version())
        self.assertFalse(new_version5.is_latest_published_version())

    def test_equality_operator(self):
        """testing equality of two Version instances
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertFalse(new_version1 == new_version2)
        self.assertFalse(new_version1 == new_version3)
        self.assertFalse(new_version1 == new_version4)
        self.assertFalse(new_version1 == new_version5)

        self.assertFalse(new_version2 == new_version3)
        self.assertFalse(new_version2 == new_version4)
        self.assertFalse(new_version2 == new_version5)

        self.assertFalse(new_version3 == new_version4)
        self.assertFalse(new_version3 == new_version5)

        self.assertFalse(new_version4 == new_version5)

    def test_inequality_operator(self):
        """testing inequality of two Version instances
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        new_version1.is_published = True
        new_version3.is_published = True
        new_version4.is_published = True

        self.assertTrue(new_version1 != new_version2)
        self.assertTrue(new_version1 != new_version3)
        self.assertTrue(new_version1 != new_version4)
        self.assertTrue(new_version1 != new_version5)

        self.assertTrue(new_version2 != new_version3)
        self.assertTrue(new_version2 != new_version4)
        self.assertTrue(new_version2 != new_version5)

        self.assertTrue(new_version3 != new_version4)
        self.assertTrue(new_version3 != new_version5)

        self.assertTrue(new_version4 != new_version5)

    def test_created_with_argument_can_be_skipped(self):
        """testing if the created_with argument can be skipped
        """
        self.kwargs.pop("created_with")
        Version(**self.kwargs)

    def test_created_with_argument_can_be_None(self):
        """testing if the created_with argument can be None
        """
        self.kwargs["created_with"] = None
        Version(**self.kwargs)

    def test_created_with_attribute_can_be_set_to_None(self):
        """testing if the created with attribute can be set to None
        """
        self.test_version.created_with = None

    def test_created_with_argument_accepts_only_string_or_None(self):
        """testing if a TypeError will be raised if the created_with argument
        is something other than a string or None
        """
        self.kwargs["created_with"] = 234
        self.assertRaises(TypeError, Version, **self.kwargs)

    def test_created_with_attribute_accepts_only_string_or_None(self):
        """testing if a TypeError will be raised if the created_with attribute
        is set to a value other than a string or None
        """
        self.assertRaises(TypeError, setattr, self.test_version, "created_with", 234)

    def test_created_with_argument_is_working_properly(self):
        """testing if the created_with argument value is passed to created_with
        attribute properly
        """
        test_value = "Maya"
        self.kwargs["created_with"] = test_value
        test_version = Version(**self.kwargs)
        self.assertEqual(test_version.created_with, test_value)

    def test_created_with_attribute_is_working_properly(self):
        """testing if created_with attribute is working properly
        """
        test_value = "Maya"
        self.assertNotEqual(self.test_version.created_with, test_value)
        self.test_version.created_with = test_value
        self.assertEqual(self.test_version.created_with, test_value)

    def test_max_version_number_attribute_is_read_only(self):
        """testing if the max_version_number attribute is read only
        """
        self.assertRaises(AttributeError, setattr, self.test_version, "max_version_number", 20)

    def test_max_version_number_attribute_is_working_properly(self):
        """testing if the max_version_number attribute is working properly
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        self.assertEqual(new_version5.version_number, 5)

        self.assertEqual(new_version1.max_version_number, 5)
        self.assertEqual(new_version2.max_version_number, 5)
        self.assertEqual(new_version3.max_version_number, 5)
        self.assertEqual(new_version4.max_version_number, 5)
        self.assertEqual(new_version5.max_version_number, 5)

    def test_latest_version_attribute_is_read_only(self):
        """testing if the last_version attribute is a read only attribute
        """
        self.assertRaises(AttributeError, setattr, self.test_version, "latest_version", 3453)

    def test_latest_version_attribute_is_working_properly(self):
        """testing if the last_version attribute is working properly
        """
        new_version1 = Version(**self.kwargs)
        DBSession.add(new_version1)
        DBSession.commit()

        new_version2 = Version(**self.kwargs)
        DBSession.add(new_version2)
        DBSession.commit()

        new_version3 = Version(**self.kwargs)
        DBSession.add(new_version3)
        DBSession.commit()

        new_version4 = Version(**self.kwargs)
        DBSession.add(new_version4)
        DBSession.commit()

        new_version5 = Version(**self.kwargs)
        DBSession.add(new_version5)
        DBSession.commit()

        self.assertEqual(new_version5.version_number, 5)

        self.assertEqual(new_version1.latest_version, new_version5)
        self.assertEqual(new_version2.latest_version, new_version5)
        self.assertEqual(new_version3.latest_version, new_version5)
        self.assertEqual(new_version4.latest_version, new_version5)
        self.assertEqual(new_version5.latest_version, new_version5)

    def test_naming_parents_attribute_is_a_read_only_property(self):
        """testing if the naming_parents attribute is a read only property
        """
        self.assertRaises(AttributeError, setattr, self.test_version, "naming_parents", [self.test_task1])

    def test_naming_parents_attribute_is_working_properly(self):
        """testing if the naming_parents attribute is working properly
        """
        # for self.test_version
        self.assertEqual(self.test_version.naming_parents, [self.test_shot1, self.test_task1])

        # for a new version of a task
        task1 = Task(name="Test Task 1", project=self.test_project, status_list=self.test_task_status_list)

        task2 = Task(name="Test Task 2", parent=task1, status_list=self.test_task_status_list)

        task3 = Task(name="Test Task 3", parent=task2, status_list=self.test_task_status_list)
        DBSession.add_all([task1, task2, task3])
        DBSession.commit()

        version1 = Version(task=task3)
        DBSession.add(version1)
        DBSession.commit()

        self.assertEqual(version1.naming_parents, [task1, task2, task3])

        # for a an asset version
        asset_statuses = StatusList(
            target_entity_type="Asset", statuses=[self.test_status1, self.test_status2, self.test_status3]
        )
        character_type = Type(target_entity_type="Asset", name="Character", code="Char")
        asset1 = Asset(name="Asset1", code="Asset1", parent=task1, status_list=asset_statuses, type=character_type)
        version2 = Version(task=asset1)
        self.assertEqual(version2.naming_parents, [asset1])

        # for a version of a task of a shot
        shot2 = Shot(name="SH002", code="SH002", parent=task3, status_list=self.test_shot_status_list)

        task4 = Task(name="Test Task 4", parent=shot2, status_list=self.test_task_status_list)

        version3 = Version(task=task4)

        self.assertEqual(version3.naming_parents, [shot2, task4])

        # for an asset of a shot
        asset2 = Asset(name="Asset2", code="Asset2", parent=shot2, status_list=asset_statuses, type=character_type)
        version4 = Version(task=asset2)
        self.assertEqual(version4.naming_parents, [asset2])

    def test_nice_name_attribute_is_working_properly(self):
        """testing if the nice_name attribute is working properly
        """
        # for self.test_version
        self.assertEqual(self.test_version.naming_parents, [self.test_shot1, self.test_task1])

        # for a new version of a task
        task1 = Task(name="Test Task 1", project=self.test_project, status_list=self.test_task_status_list)

        task2 = Task(name="Test Task 2", parent=task1, status_list=self.test_task_status_list)

        task3 = Task(name="Test Task 3", parent=task2, status_list=self.test_task_status_list)
        DBSession.add_all([task1, task2, task3])
        DBSession.commit()

        version1 = Version(task=task3, take_name="Take1")
        DBSession.add(version1)
        DBSession.commit()

        self.assertEqual(
            version1.nice_name, "%s_%s_%s_%s" % (task1.nice_name, task2.nice_name, task3.nice_name, version1.take_name)
        )

        # for a an asset version
        asset_statuses = StatusList(
            target_entity_type="Asset", statuses=[self.test_status1, self.test_status2, self.test_status3]
        )
        character_type = Type(target_entity_type="Asset", name="Character", code="Char")
        asset1 = Asset(name="Asset1", code="Asset1", parent=task1, status_list=asset_statuses, type=character_type)
        version2 = Version(task=asset1)
        self.assertEqual(version2.nice_name, "%s_%s" % (asset1.nice_name, version2.take_name))

        # for a version of a task of a shot
        shot2 = Shot(name="SH002", code="SH002", parent=task3, status_list=self.test_shot_status_list)

        task4 = Task(name="Test Task 4", parent=shot2, status_list=self.test_task_status_list)

        version3 = Version(task=task4)

        self.assertEqual(version3.nice_name, "%s_%s_%s" % (shot2.nice_name, task4.nice_name, version3.take_name))

        # for an asset of a shot
        asset2 = Asset(name="Asset2", code="Asset2", parent=shot2, status_list=asset_statuses, type=character_type)
        version4 = Version(task=asset2)
        self.assertEqual(version4.nice_name, "%s_%s" % (asset2.nice_name, version4.take_name))

    def test_string_representation_is_a_little_bit_meaningful(self):
        """testing if the __str__ or __repr__ result is meaningfull
        """
        self.assertEqual("<tp_SH001_Task1_TestTake_v001 (Version)>", "%s" % self.test_version)

    def test_walk_hierarchy_is_working_properly_in_DFS_mode(self):
        """testing if the walk_hierarchy() method is working in DFS mode
        correctly
        """
        v1 = Version(task=self.test_task1)
        v2 = Version(task=self.test_task1, parent=v1)
        v3 = Version(task=self.test_task1, parent=v2)
        v4 = Version(task=self.test_task1, parent=v3)
        v5 = Version(task=self.test_task1, parent=v1)

        expected_result = [v1, v2, v3, v4, v5]
        visited_versions = []
        for v in v1.walk_hierarchy():
            visited_versions.append(v)

        self.assertEqual(expected_result, visited_versions)

    def test_walk_inputs_is_working_properly_in_DFS_mode(self):
        """testing if the walk_inputs() method is working in DFS mode correctly
        """
        v1 = Version(task=self.test_task1)
        v2 = Version(task=self.test_task1)
        v3 = Version(task=self.test_task1)
        v4 = Version(task=self.test_task1)
        v5 = Version(task=self.test_task1)

        v5.inputs = [v4]
        v4.inputs = [v3, v2]
        v3.inputs = [v1]
        v2.inputs = [v1]

        expected_result = [v5, v4, v3, v1, v2, v1]
        visited_versions = []
        for v in v5.walk_inputs():
            visited_versions.append(v)

        self.assertEqual(expected_result, visited_versions)
Ejemplo n.º 51
0
    def setUp(self):
        super(DailyTestBase, self).setUp()

        from stalker import Status, StatusList
        self.status_new = Status(name='Mew', code='NEW')
        self.status_wfd = Status(name='Waiting For Dependency', code='WFD')
        self.status_rts = Status(name='Ready To Start', code='RTS')
        self.status_wip = Status(name='Work In Progress', code='WIP')
        self.status_prev = Status(name='Pending Review', code='PREV')
        self.status_hrev = Status(name='Has Revision', code='HREV')
        self.status_drev = Status(name='Dependency Has Revision', code='DREV')
        self.status_cmpl = Status(name='Completed', code='CMPL')

        self.status_open = Status(name='Open', code='OPEN')
        self.status_cls = Status(name='Closed', code='CLS')

        self.daily_status_list = StatusList(
            name='Daily Statuses',
            statuses=[self.status_open, self.status_cls],
            target_entity_type='Daily')

        self.task_status_list = StatusList(
            name='Task Statuses',
            statuses=[
                self.status_wfd, self.status_rts, self.status_wip,
                self.status_prev, self.status_hrev, self.status_drev,
                self.status_cmpl
            ],
            target_entity_type='Task')

        self.test_project_status_list = StatusList(
            name='Project Statuses',
            target_entity_type='Project',
            statuses=[self.status_new, self.status_wip, self.status_cmpl])

        from stalker import Repository, Project
        self.test_repo = Repository(name='Test Repository', code='TR')

        self.test_project = Project(name='Test Project',
                                    code='TP',
                                    repository=self.test_repo,
                                    status_list=self.test_project_status_list)

        from stalker import Task
        self.test_task1 = Task(name='Test Task 1',
                               project=self.test_project,
                               status_list=self.task_status_list)
        self.test_task2 = Task(name='Test Task 2',
                               project=self.test_project,
                               status_list=self.task_status_list)
        self.test_task3 = Task(name='Test Task 3',
                               project=self.test_project,
                               status_list=self.task_status_list)

        from stalker import Version
        self.test_version1 = Version(task=self.test_task1)
        self.test_version2 = Version(task=self.test_task1)
        self.test_version3 = Version(task=self.test_task1)
        self.test_version4 = Version(task=self.test_task2)

        from stalker import Link
        self.test_link1 = Link(original_filename='test_render1.jpg')
        self.test_link2 = Link(original_filename='test_render2.jpg')
        self.test_link3 = Link(original_filename='test_render3.jpg')
        self.test_link4 = Link(original_filename='test_render4.jpg')

        self.test_version1.outputs = [
            self.test_link1, self.test_link2, self.test_link3
        ]
        self.test_version4.outputs = [self.test_link4]
Ejemplo n.º 52
0
    name='Task Template for Commercials',
    target_entity_type='Task',
    path='$REPO{{project.repository.id}}/{{project.code}}/{%- for p in parent_tasks -%}{{p.nice_name}}/{%- endfor -%}',
    filename='{{version.nice_name}}_v{{"%03d"|format(version.version_number)}}'
)

# and append it to our project structure
commercial_project_structure.templates.append(task_template)

# commit to database
db.DBSession.commit()  # no need to add anything, project is already on db

from stalker import Version

vers1 = Version(
    task=comp
)

# we need to update the paths
vers1.update_paths()

# check the path and filename
print(vers1.path)                # '$REPO33/FC/SH001/comp'
print(vers1.filename)            # 'SH001_comp_Main_v001'
print(vers1.full_path)           # '$REPO33/FC/SH001/comp/SH001_comp_Main_v001'
# now the absolute values, values with repository root
# because I'm running this code in a Linux laptop, my results are using the
# linux path of the repository
print(vers1.absolute_path)       # '/mnt/M/commercials/FC/SH001/comp'
print(vers1.absolute_full_path)  # '/mnt/M/commercials/FC/SH001/comp/SH001_comp_Main_v001'