Ejemplo n.º 1
0
    def test_run_publishers_is_working_properly(self):
        """testing if the run_publishers() function calls all the publishers
        under given name
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 2
0
    def test_calling_base_callable_multiple_times(self):
        """testing if calling the base publishers will not call the functions
        more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers()
        self.assertEqual(called, ['func4'])
Ejemplo n.º 3
0
    def test_run_publishers_is_working_properly(self):
        """testing if the run_publishers() function calls all the publishers
        under given name
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 4
0
    def test_calling_base_callable_multiple_times(self):
        """testing if calling the base publishers will not call the functions
        more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers()
        self.assertEqual(called, ['func4'])
Ejemplo n.º 5
0
    def test_run_publishers_is_working_properly_with_post_publishers_specified(
            self):
        """testing if the run_publishers() function calls all the post
        publishers under given name
        """
        called = []

        # Register some pre publishers
        @publisher('Test', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func1():
            called.append('pre_func1')

        @publisher('Test', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func2():
            called.append('pre_func2')

        @publisher('Test2', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func3():
            """another publisher for some other type
            """
            called.append('pre_func3')

        @publisher(publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func4():
            """this should run for everything
            """
            called.append('pre_func4')

        # Register some post publishers
        @publisher('Test', publisher_type=POST_PUBLISHER_TYPE)
        def func1():
            called.append('func1')

        @publisher('Test', publisher_type=POST_PUBLISHER_TYPE)
        def func2():
            called.append('func2')

        @publisher('Test2', publisher_type=POST_PUBLISHER_TYPE)
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher(publisher_type=POST_PUBLISHER_TYPE)
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers('Test', publisher_type=POST_PUBLISHER_TYPE)
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 6
0
    def test_run_publishers_is_working_properly_with_post_publishers_specified(self):
        """testing if the run_publishers() function calls all the post
        publishers under given name
        """
        called = []

        # Register some pre publishers
        @publisher('Test', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func1():
            called.append('pre_func1')

        @publisher('Test', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func2():
            called.append('pre_func2')

        @publisher('Test2', publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func3():
            """another publisher for some other type
            """
            called.append('pre_func3')

        @publisher(publisher_type=PRE_PUBLISHER_TYPE)
        def pre_func4():
            """this should run for everything
            """
            called.append('pre_func4')

        # Register some post publishers
        @publisher('Test', publisher_type=POST_PUBLISHER_TYPE)
        def func1():
            called.append('func1')

        @publisher('Test', publisher_type=POST_PUBLISHER_TYPE)
        def func2():
            called.append('func2')

        @publisher('Test2', publisher_type=POST_PUBLISHER_TYPE)
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher(publisher_type=POST_PUBLISHER_TYPE)
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        run_publishers('Test', publisher_type=POST_PUBLISHER_TYPE)
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 7
0
    def test_registering_a_callable_multiple_times(self):
        """testing if registering a callable multiple times will not call the
        function more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # register fun1 and func2 more than one times
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 8
0
    def test_registering_a_callable_multiple_times(self):
        """testing if registering a callable multiple times will not call the
        function more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # register fun1 and func2 more than one times
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Ejemplo n.º 9
0
    def test_registering_to_multiple_types_with_lists(self):
        """testing if it is possible to register one publisher for multiple
        types
        """
        called = []

        @publisher(['Test', 'Test2'])
        def func1():
            called.append('func1')

        @publisher(['Test', 'Test3'])
        def func2():
            called.append('func2')

        @publisher(['Test2', 'Test3'])
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        called = []
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])

        called = []
        run_publishers('Test2')
        self.assertEqual(called, ['func4', 'func1', 'func3'])

        called = []
        run_publishers('Test3')
        self.assertEqual(called, ['func4', 'func2', 'func3'])
Ejemplo n.º 10
0
    def test_registering_to_multiple_types_with_lists(self):
        """testing if it is possible to register one publisher for multiple
        types
        """
        called = []

        @publisher(['Test', 'Test2'])
        def func1():
            called.append('func1')

        @publisher(['Test', 'Test3'])
        def func2():
            called.append('func2')

        @publisher(['Test2', 'Test3'])
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # now run all publishers
        called = []
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])

        called = []
        run_publishers('Test2')
        self.assertEqual(called, ['func4', 'func1', 'func3'])

        called = []
        run_publishers('Test3')
        self.assertEqual(called, ['func4', 'func2', 'func3'])
Ejemplo n.º 11
0
    def save_as(self, version, run_pre_publishers=True):
        """Save as action for Blender

        :param version:
        :param run_pre_publishers:
        :return:
        """
        version.update_paths()
        # set version extension to .blend
        version.extension = self.extensions[0]

        # store what this file is created with
        version.created_with = self.name

        project = version.task.project

        shot = self.get_shot(version)

        fps = None
        imf = None
        if shot:
            self.set_frame_range(shot.cut_in, shot.cut_out)

        fps = shot.fps if shot else project.fps
        imf = shot.image_format if shot else project.image_format

        self.set_render_resolution(imf.width, imf.height, imf.pixel_aspect)
        self.set_fps(fps)

        self.set_render_filename(version)

        # create the folder if it doesn't exists
        try:
            import os
            os.makedirs(version.absolute_path)
        except OSError:
            # already exists
            pass

        # finally save the file
        bpy.ops.wm.save_as_mainfile(filepath=version.absolute_full_path)

        from stalker.db.session import DBSession
        DBSession.add(version)

        # append it to the recent file list
        self.append_to_recent_files(version.absolute_full_path)
        DBSession.commit()

        # create project structure
        self.create_project_structure(version)

        # create a local copy
        self.create_local_copy(version)

        # run post publishers here
        if version.is_published:
            # before doing anything run all publishers
            type_name = ''
            if version.task.type:
                type_name = version.task.type.name

            # before running use the staging area to store the current version
            from anima.publish import staging, run_publishers, POST_PUBLISHER_TYPE
            from anima.exc import PublishError
            staging['version'] = version
            try:
                run_publishers(type_name, publisher_type=POST_PUBLISHER_TYPE)
            except PublishError as e:
                # do not forget to clean up the staging area
                staging.clear()
                raise e

        return True