[Piglit] [PATCH 12/45] interpolation-qualifier...: use if __name__ == '__main__' pattern

Dylan Baker baker.dylan.c at gmail.com
Wed Nov 12 15:45:54 PST 2014


By pulling all of the loops into a single function we also get the
advantage of combining some code.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 .../interpolation-qualifier-built-in-variable.py   | 212 +++++++++------------
 1 file changed, 92 insertions(+), 120 deletions(-)

diff --git a/generated_tests/interpolation-qualifier-built-in-variable.py b/generated_tests/interpolation-qualifier-built-in-variable.py
index 9b0313a..efb7171 100644
--- a/generated_tests/interpolation-qualifier-built-in-variable.py
+++ b/generated_tests/interpolation-qualifier-built-in-variable.py
@@ -62,142 +62,114 @@ vertex_shader_to_fragment_shader_variable_map = {
 }
 
 
-for fs_mode in interpolation_modes:
-    for vs_mode in interpolation_modes:
-        if vs_mode == fs_mode:
-            continue
-
-        for var in vertex_shader_variables:
-            filename = os.path.join(
-                'spec',
-                'glsl-1.30',
-                'linker',
-                'interpolation-qualifiers',
-                '{0}-{1}-{2}-{3}.shader_test'.format(
-                    vs_mode, var, fs_mode,
-                    vertex_shader_to_fragment_shader_variable_map[var]))
-            print(filename)
-
-            dirname = os.path.dirname(filename)
-            if not os.path.exists(dirname):
-                os.makedirs(dirname)
-
-            with open(filename, 'w') as f:
-                f.write(TEMPLATES.get_template('vs-fs.shader_test.mako').render(
-                    vs_mode=vs_mode,
-                    vs_variable=var,
-                    fs_mode=fs_mode,
-                    fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
-
-
-for vs_mode in interpolation_modes:
-    if vs_mode == 'default':
-        continue
-
-    for var in vertex_shader_variables:
-        filename = os.path.join(
-            'spec',
-            'glsl-1.30',
-            'linker',
-            'interpolation-qualifiers',
-            '{0}-{1}-unused-{2}.shader_test'.format(vs_mode, var,
-                vertex_shader_to_fragment_shader_variable_map[var]))
-        print(filename)
-
-        dirname = os.path.dirname(filename)
-        if not os.path.exists(dirname):
-            os.makedirs(dirname)
-
-        with open(filename, 'w') as f:
-            f.write(
-                TEMPLATES.get_template('vs-unused.shader_test.mako').render(
-                    vs_mode=vs_mode,
-                    vs_variable=var))
-
-
-for fs_mode in interpolation_modes:
-    if fs_mode == 'default':
-        continue
-
-    for var in vertex_shader_variables_front_only:
-        filename = os.path.join(
-            'spec',
-            'glsl-1.30',
-            'linker',
-            'interpolation-qualifiers',
-            'unused-{0}-{1}-{2}.shader_test'.format(
-                var, fs_mode,
-                vertex_shader_to_fragment_shader_variable_map[var]))
-        print(filename)
-
-        dirname = os.path.dirname(filename)
-        if not os.path.exists(dirname):
-            os.makedirs(dirname)
-
-        with open(filename, 'w') as f:
-            f.write(TEMPLATES.get_template('fs-unused.shader_test.mako').render(
-                vs_mode=vs_mode,
-                vs_variable=var,
-                fs_mode=fs_mode,
-                fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
-
+def main():
+    """main function."""
+    dirname = os.path.join('spec', 'glsl-1.30', 'linker',
+                           'interpolation-qualifiers')
+
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+
+    for fs_mode in interpolation_modes:
+        for vs_mode in interpolation_modes:
+            if vs_mode == fs_mode:
+                continue
+
+            for var in vertex_shader_variables:
+                filename = os.path.join(
+                    dirname,
+                    '{0}-{1}-{2}-{3}.shader_test'.format(
+                        vs_mode, var, fs_mode,
+                        vertex_shader_to_fragment_shader_variable_map[var]))
+                print(filename)
+
+                with open(filename, 'w') as f:
+                    f.write(TEMPLATES.get_template('vs-fs.shader_test.mako').render(
+                        vs_mode=vs_mode,
+                        vs_variable=var,
+                        fs_mode=fs_mode,
+                        fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
 
 
-for fs_mode in interpolation_modes:
     for vs_mode in interpolation_modes:
-        if vs_mode == fs_mode:
+        if vs_mode == 'default':
             continue
 
         for var in vertex_shader_variables:
             filename = os.path.join(
-                'spec',
-                'glsl-1.30',
-                'linker',
-                'interpolation-qualifiers',
-                'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
-                    vs_mode, var, fs_mode,
+                dirname,
+                '{0}-{1}-unused-{2}.shader_test'.format(vs_mode, var,
                     vertex_shader_to_fragment_shader_variable_map[var]))
             print(filename)
 
-            dirname = os.path.dirname(filename)
-            if not os.path.exists(dirname):
-                os.makedirs(dirname)
-
             with open(filename, 'w') as f:
-                f.write(TEMPLATES.get_template(
-                    'fs-vs-unused.shader_test.mako').render(
+                f.write(
+                    TEMPLATES.get_template('vs-unused.shader_test.mako').render(
                         vs_mode=vs_mode,
-                        vs_variable=var,
-                        fs_mode=fs_mode,
-                        fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
-
+                        vs_variable=var))
 
-
-for fs_mode in interpolation_modes:
-    for vs_mode in interpolation_modes:
-        if vs_mode == fs_mode:
+    for fs_mode in interpolation_modes:
+        if fs_mode == 'default':
             continue
 
-        for this_side in vertex_shader_variables:
-            other_side = other_side_map[this_side]
+        for var in vertex_shader_variables_front_only:
             filename = os.path.join(
-                'spec',
-                'glsl-1.30',
-                'linker',
-                'interpolation-qualifiers',
-                '{0}-{1}-{2}-{3}.shader_test'.format(
-                    vs_mode, this_side, fs_mode, other_side))
+                dirname,
+                'unused-{0}-{1}-{2}.shader_test'.format(
+                    var, fs_mode,
+                    vertex_shader_to_fragment_shader_variable_map[var]))
             print(filename)
 
-            dirname = os.path.dirname(filename)
-            if not os.path.exists(dirname):
-                os.makedirs(dirname)
-
             with open(filename, 'w') as f:
-                f.write(TEMPLATES.get_template(
-                    'vs-fs-flip.shader_test.mako').render(
-                        vs_mode=vs_mode,
-                        this_side_variable=this_side,
-                        other_side_variable=other_side,
-                        fs_mode=fs_mode,
-                        fs_variable=vertex_shader_to_fragment_shader_variable_map[this_side]))
+                f.write(TEMPLATES.get_template('fs-unused.shader_test.mako').render(
+                    vs_mode=vs_mode,
+                    vs_variable=var,
+                    fs_mode=fs_mode,
+                    fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
+
+    for fs_mode in interpolation_modes:
+        for vs_mode in interpolation_modes:
+            if vs_mode == fs_mode:
+                continue
+
+            for var in vertex_shader_variables:
+                filename = os.path.join(
+                    dirname,
+                    'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
+                        vs_mode, var, fs_mode,
+                        vertex_shader_to_fragment_shader_variable_map[var]))
+                print(filename)
+
+                with open(filename, 'w') as f:
+                    f.write(TEMPLATES.get_template(
+                        'fs-vs-unused.shader_test.mako').render(
+                            vs_mode=vs_mode,
+                            vs_variable=var,
+                            fs_mode=fs_mode,
+                            fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
+
+    for fs_mode in interpolation_modes:
+        for vs_mode in interpolation_modes:
+            if vs_mode == fs_mode:
+                continue
+
+            for this_side in vertex_shader_variables:
+                other_side = other_side_map[this_side]
+                filename = os.path.join(
+                    dirname,
+                    '{0}-{1}-{2}-{3}.shader_test'.format(
+                        vs_mode, this_side, fs_mode, other_side))
+                print(filename)
+
+                with open(filename, 'w') as f:
+                    f.write(TEMPLATES.get_template(
+                        'vs-fs-flip.shader_test.mako').render(
+                            vs_mode=vs_mode,
+                            this_side_variable=this_side,
+                            other_side_variable=other_side,
+                            fs_mode=fs_mode,
+                            fs_variable=vertex_shader_to_fragment_shader_variable_map[this_side]))
+
+
+if __name__ == '__main__':
+    main()
-- 
2.1.3



More information about the Piglit mailing list