[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3712] trunk/py/scripts/addons: code cleanup: python - pass multiple args to string startswith() / endswith() functions rather than calling multiple times.

Campbell Barton ideasman42 at gmail.com
Tue Sep 4 22:31:19 CEST 2012


Revision: 3712
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3712
Author:   campbellbarton
Date:     2012-09-04 20:31:19 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
code cleanup: python - pass multiple args to string startswith() / endswith() functions rather than calling multiple times.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_import_gimp_image_to_scene.py
    trunk/py/scripts/addons/io_scene_obj/import_obj.py
    trunk/py/scripts/addons/netrender/master_html.py

Modified: trunk/py/scripts/addons/io_import_gimp_image_to_scene.py
===================================================================
--- trunk/py/scripts/addons/io_import_gimp_image_to_scene.py	2012-09-04 14:10:54 UTC (rev 3711)
+++ trunk/py/scripts/addons/io_import_gimp_image_to_scene.py	2012-09-04 20:31:19 UTC (rev 3712)
@@ -85,7 +85,7 @@
                 for Segment in Line.split():
                     if Segment.startswith('w/h:'):
                         ResX, ResY = map (int, Segment[4:].split(','))
-            if Line.startswith("b'L") or Line.startswith("b'l"):
+            if Line.startswith(("b'L", "b'l")):
                 
                 """The "nice" method to check if layer has alpha channel
                 sadly GIMP sometimes decides not to export an alpha channel

Modified: trunk/py/scripts/addons/io_scene_obj/import_obj.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/import_obj.py	2012-09-04 14:10:54 UTC (rev 3711)
+++ trunk/py/scripts/addons/io_scene_obj/import_obj.py	2012-09-04 20:31:19 UTC (rev 3712)
@@ -212,7 +212,7 @@
                         context_material.specular_hardness = int((float(line_split[1]) * 0.51))
                     elif line_lower.startswith(b'ni'):  # Refraction index
                         context_material.raytrace_transparency.ior = max(1, min(float(line_split[1]), 3))  # between 1 and 3
-                    elif line_lower.startswith(b'd') or line_lower.startswith(b'tr'):
+                    elif line_lower.startswith((b'd', b'tr')):
                         context_material.alpha = float(line_split[1])
                         context_material.use_transparency = True
                         context_material.transparency_method = 'Z_TRANSPARENCY'
@@ -330,11 +330,11 @@
                         img_filepath = line_value(line.split())
                         if img_filepath:
                             load_material_image(context_material, context_material_name, img_filepath, 'Kd')
-                    elif line_lower.startswith(b'map_bump') or line_lower.startswith(b'bump'):  # 'bump' is incorrect but some files use it.
+                    elif line_lower.startswith((b'map_bump', b'bump')):  # 'bump' is incorrect but some files use it.
                         img_filepath = line_value(line.split())
                         if img_filepath:
                             load_material_image(context_material, context_material_name, img_filepath, 'Bump')
-                    elif line_lower.startswith(b'map_d') or line_lower.startswith(b'map_tr'):  # Alpha map - Dissolve
+                    elif line_lower.startswith((b'map_d', b'map_tr')):  # Alpha map - Dissolve
                         img_filepath = line_value(line.split())
                         if img_filepath:
                             load_material_image(context_material, context_material_name, img_filepath, 'D')

Modified: trunk/py/scripts/addons/netrender/master_html.py
===================================================================
--- trunk/py/scripts/addons/netrender/master_html.py	2012-09-04 14:10:54 UTC (rev 3711)
+++ trunk/py/scripts/addons/netrender/master_html.py	2012-09-04 20:31:19 UTC (rev 3712)
@@ -41,7 +41,7 @@
     for file in job.files:
         if file.filepath.endswith(".bphys"):
            tot_cache += 1
-        elif file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz"):
+        elif file.filepath.endswith((".bobj.gz", ".bvel.gz")):
            tot_fluid += 1
         elif not file == job.files[0]:
            tot_other += 1
@@ -166,10 +166,10 @@
             if file.filepath.endswith(".bphys") and (file_type & CACHE_FILES):
                message.append(filedata);
                continue
-            if (file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz")) and (file_type & FLUID_FILES):
+            if file.filepath.endswith((".bobj.gz", ".bvel.gz")) and (file_type & FLUID_FILES):
                message.append(filedata);
                continue
-            if (not file == job.files[0]) and (file_type &  OTHER_FILES) and ( not (file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz"))) and not file.filepath.endswith(".bphys"):
+            if (not file == job.files[0]) and (file_type & OTHER_FILES) and (not file.filepath.endswith((".bobj.gz", ".bvel.gz"))) and not file.filepath.endswith(".bphys"):
                message.append(filedata);
                continue
                   
@@ -470,7 +470,7 @@
                 if tot_fluid > 0:
                     rowTable("%i fluid bake files" % tot_fluid, class_style = "toggle", extra = "onclick='toggleDisplay(".fluid", "none", "table-row")'")
                     for file in job.files:
-                        if file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz"):
+                        if file.filepath.endswith((".bobj.gz", ".bvel.gz")):
                             rowTable(os.path.split(file.filepath)[1], class_style = "fluid")
     
                 if tot_other > 0:
@@ -478,7 +478,7 @@
                     for file in job.files:
                         if (
                             not file.filepath.endswith(".bphys")
-                            and not file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz")
+                            and not file.filepath.endswith((".bobj.gz", ".bvel.gz"))
                             and not file == job.files[0]
                             ):
 



More information about the Bf-extensions-cvs mailing list