[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3970] contrib/py/scripts/addons/ online_mat_lib/__init__.py: Bugfix: Add-on was defaulting to Bundled library's materials

Peter Cassetta peter at fingertipsoft.com
Thu Nov 15 04:16:58 CET 2012


Revision: 3970
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3970
Author:   petercassetta
Date:     2012-11-15 03:16:54 +0000 (Thu, 15 Nov 2012)
Log Message:
-----------
Bugfix: Add-on was defaulting to Bundled library's materials

If a material was not cached, the add-on should have downloaded it.
Instead, if it was in the Bundled library, it would use that one.
This doesn't always cause obvious problems, but if a material in the Testing library is different from one in the Bundled library, the Bundled material would still be used instead of the updated Testing library one.

Modified Paths:
--------------
    contrib/py/scripts/addons/online_mat_lib/__init__.py

Modified: contrib/py/scripts/addons/online_mat_lib/__init__.py
===================================================================
--- contrib/py/scripts/addons/online_mat_lib/__init__.py	2012-11-15 02:47:15 UTC (rev 3969)
+++ contrib/py/scripts/addons/online_mat_lib/__init__.py	2012-11-15 03:16:54 UTC (rev 3970)
@@ -258,6 +258,7 @@
                     row.label(text="No cached files.")
                 elif mat_lib_cached_files == 1:
                     row.label(text=str(mat_lib_cached_files) + " cached file.")
+                    row.operator("material.libraryclearcache", text="Clear Cache", icon='CANCEL')
                 elif mat_lib_cached_files != -1:
                     row.label(text=str(mat_lib_cached_files) + " cached files.")
                     row.operator("material.libraryclearcache", text="Clear Cache", icon='CANCEL')
@@ -1414,7 +1415,7 @@
                     self.mat_name = ""
                     self.report({'ERROR'}, "Material file is either outdated or invalid.")
                     return {'CANCELLED'}
-            elif os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm"):
+            elif library == "bundled" and os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm"):
                 bcm_file = open(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm", mode="r", encoding="UTF-8")
                 material_file_contents = bcm_file.read()
                 bcm_file.close()
@@ -1597,7 +1598,7 @@
                     self.filename = ""
                     self.report({'ERROR'}, "Material file is either outdated or invalid.")
                     return {'CANCELLED'}
-            elif os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm"):
+            elif library == "bundled" and os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm"):
                 bcm_file = open(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm", mode="r", encoding="UTF-8")
                 material_file_contents = bcm_file.read()
                 bcm_file.close()
@@ -1612,6 +1613,13 @@
                 connection.request("GET", mat_lib_location + "cycles/" + category_filename + "/" + self.filename + ".bcm")
                 response = connection.getresponse().read()
                 
+                #Check file for validitity
+                if '<?xml version="1.0" encoding="UTF-8"?>' not in str(response)[2:40]:
+                    self.report({'ERROR'}, "Material file is either outdated or invalid.")
+                    self.mat_name = ""
+                    self.filename = ""
+                    return {'CANCELLED'}
+                
                 #Cache material
                 if library == "composite":
                     bcm_file = open(mat_lib_folder + os.sep + mat_lib_host + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm", mode="w+b")
@@ -1622,12 +1630,6 @@
                     bcm_file.write(response)
                     bcm_file.close()
                 
-                #Check file for validitity
-                if '<?xml version="1.0" encoding="UTF-8"?>' not in str(response)[2:40]:
-                    self.report({'ERROR'}, "Material file is either outdated or invalid.")
-                    self.mat_name = ""
-                    self.filename = ""
-                    return {'CANCELLED'}
                 material_file_contents = ""
                 material_file_contents = str(response)[str(response).index("<material"):str(response).index("/material>") + 10]
             else:
@@ -1818,7 +1820,7 @@
             bcm_file = open(mat_lib_folder + os.sep + mat_lib_host + os.sep + library + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm", mode="r+b")
             response = bcm_file.read()
             bcm_file.close()
-        elif os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + save_filename + ".bcm"):
+        elif library == "bundled" and os.path.exists(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + save_filename + ".bcm"):
             bcm_file = open(mat_lib_folder + os.sep + "bundled" + os.sep + "cycles" + os.sep + category_filename + os.sep + self.filename + ".bcm", mode="r+b")
             response = bcm_file.read()
             bcm_file.close()



More information about the Bf-extensions-cvs mailing list