[Bf-extensions-cvs] [5b36ccb] master: fix for broken paths

Brendon Murphy noreply at git.blender.org
Thu May 28 02:32:37 CEST 2015


Commit: 5b36ccbe7d5f830b541540b7befad3b93af51ee8
Author: Brendon Murphy
Date:   Thu May 28 10:32:13 2015 +1000
Branches: master
https://developer.blender.org/rBAC5b36ccbe7d5f830b541540b7befad3b93af51ee8

fix for broken paths

===================================================================

M	online_mat_lib/__init__.py

===================================================================

diff --git a/online_mat_lib/__init__.py b/online_mat_lib/__init__.py
index a65cd13..75ca48c 100644
--- a/online_mat_lib/__init__.py
+++ b/online_mat_lib/__init__.py
@@ -30,8 +30,8 @@
 bl_info = {
     "name": "Online Material Library",
     "author": "Peter Cassetta",
-    "version": (0, 6),
-    "blender": (2, 71, 0),
+    "version": (0, 6, 1),
+    "blender": (2, 74, 5),
     "location": "Properties > Material > Online Material Library",
     "description": "Browse and download materials from online CC0 libraries.",
     "warning": "Beta version",
@@ -258,23 +258,15 @@ mat_lib_host = ""
 mat_lib_location = ""
 mat_lib_cached_files = -1
 
-mat_lib_folder = ""
+matlibpath = ""
 
 def findLibrary():
-    global mat_lib_folder
-    
-    if os.path.exists(os.path.join(str(bpy.utils.script_path_pref()), "addons", "online_mat_lib", "material-library")):
-        mat_lib_folder = os.path.join(str(bpy.utils.script_path_pref()), "addons", "online_mat_lib", "material-library")
-    elif os.path.exists(os.path.join(bpy.utils.script_path_user(), "addons", "online_mat_lib", "material-library")):
-        mat_lib_folder = os.path.join(bpy.utils.script_path_user(), "addons", "online_mat_lib", "material-library")
-    elif os.path.exists(os.path.join(bpy.utils.script_paths()[0], "addons", "online_mat_lib", "material-library")):
-        mat_lib_folder = os.path.join(bpy.utils.script_paths()[0], "addons", "online_mat_lib", "material-library")
-    elif os.path.exists(os.path.join(bpy.utils.script_paths()[0], "addons_contrib", "online_mat_lib", "material-library")):
-        mat_lib_folder = os.path.join(bpy.utils.script_paths()[0], "addons_contrib", "online_mat_lib", "material-library")
-    else:
-        print("ONLINE MATERIAL LIBRARY -- MAJOR PROBLEM:"\
-        "COULD NOT LOCATE ADD-ON INSTALLATION PATH.")
-        mat_lib_folder = "error"
+    global matlibpath
+    for p in bpy.utils.script_paths():
+        matlibpath = os.path.join(p, "addons_contrib", "online_mat_lib", "material-library")
+        if os.path.exists(matlibpath):
+            break
+    return matlibpath    
 
 findLibrary()
 
@@ -352,10 +344,10 @@ bpy.types.Scene.mat_lib_bcg_read = bpy.props.StringProperty(name = "Text Datablo
 bpy.types.Scene.mat_lib_bcm_name = bpy.props.StringProperty(name = "Material Name", description = "Specify a name for the new material", default="Untitled", options = {'SKIP_SAVE'})
 bpy.types.Scene.mat_lib_bcg_name = bpy.props.StringProperty(name = "Nodegroup Name", description = "Specify a name for the new nodegroup", default="Untitled", options = {'SKIP_SAVE'})
 
-bpy.types.Scene.mat_lib_bcm_save_location = bpy.props.StringProperty(name = "Save location", description = "Directory to save .bcm files in", default=mat_lib_folder + os.sep + "my-materials" + os.sep, options = {'SKIP_SAVE'}, subtype="DIR_PATH")
-bpy.types.Scene.mat_lib_bcg_save_location = bpy.props.StringProperty(name = "Save location", description = "Directory to save .bcg files in", default=mat_lib_folder + os.sep + "my-materials" + os.sep, options = {'SKIP_SAVE'}, subtype="DIR_PATH")
-bpy.types.Scene.mat_lib_bcm_open_location = bpy.props.StringProperty(name = "Open location", description = "Location of .bcm file to open", default=mat_lib_folder + os.sep + "my-materials" + os.sep + "untitled.bcm", options = {'SKIP_SAVE'})
-bpy.types.Scene.mat_lib_bcg_open_location = bpy.props.StringProperty(name = "Open location", description = "Location of .bcg file to open", default=mat_lib_folder + os.sep + "my-materials" + os.sep + "untitled.bcg", options = {'SKIP_SAVE'})
+bpy.types.Scene.mat_lib_bcm_save_location = bpy.props.StringProperty(name = "Save location", description = "Directory to save .bcm files in", default=matlibpath + os.sep + "my-materials" + os.sep, options = {'SKIP_SAVE'}, subtype="DIR_PATH")
+bpy.types.Scene.mat_lib_bcg_save_location = bpy.props.StringProperty(name = "Save location", description = "Directory to save .bcg files in", default=matlibpath + os.sep + "my-materials" + os.sep, options = {'SKIP_SAVE'}, subtype="DIR_PATH")
+bpy.types.Scene.mat_lib_bcm_open_location = bpy.props.StringProperty(name = "Open location", description = "Location of .bcm file to open", default=matlibpath + os.sep + "my-materials" + os.sep + "untitled.bcm", options = {'SKIP_SAVE'})
+bpy.types.Scene.mat_lib_bcg_open_location = bpy.props.StringProperty(name = "Open location", description = "Location of .bcg file to open", default=matlibpath + os.sep + "my-materials" + os.sep + "untitled.bcg", options = {'SKIP_SAVE'})
 
 #subcategory_enum_items = [("None0", "None", "No Subcategory Selected")]
 #bpy.types.Scene.mat_lib_material_subcategory = bpy.props.EnumProperty(name = "", items = subcategory_enum_items, description = "Choose a subcategory", options = {'SKIP_SAVE'})
@@ -386,7 +378,7 @@ class OnlineMaterialLibraryPanel(bpy.types.Panel):
             
             if category_type is not "info" and category_type is not "settings" and category_type is not "tools":
                 if mat_lib_contents == "" or mat_lib_contents == "Please refresh.":
-                    if mat_lib_folder == "error":
+                    if matlibpath == "error":
                         row.label(text="ERROR: Could not find installation path!", icon='ERROR')
                     else:
                         #Material Library Contents variable is empty -- show welcome message
@@ -818,7 +810,7 @@ class OnlineMaterialLibraryPanel(bpy.types.Panel):
                         
                         #Display material "Save" button
                         mat_button = functions.operator("material.librarysave", text="Save as...", icon='DISK_DRIVE')
-                        mat_button.filepath = os.path.join(mat_lib_folder, "my-materials", material_filenames[current_material_number] + ".bcm")
+                        mat_button.filepath = os.path.join(matlibpath, "my-materials", material_filenames[current_material_number] + ".bcm")
                         mat_button.filename = material_filenames[current_material_number]
                         save_filename = material_filenames[current_material_number]
                         
@@ -835,7 +827,7 @@ class OnlineMaterialLibraryPanel(bpy.types.Panel):
                         
                         #Display nodegroup "Save" button
                         mat_button = functions.operator("material.librarysavegroup", text="Save as...", icon='DISK_DRIVE')
-                        mat_button.filepath = os.path.join(mat_lib_folder, "my-materials", material_filenames[current_material_number] + ".bcg")
+                        mat_button.filepath = os.path.join(matlibpath, "my-materials", material_filenames[current_material_number] + ".bcg")
                         mat_button.filename = material_filenames[current_material_number]
                         save_filename = material_filenames[current_material_number]
                         
@@ -850,7 +842,7 @@ class OnlineMaterialLibraryPanel(bpy.types.Panel):
                         
                         #Display image "Save" button
                         mat_button = functions.operator("material.librarysaveimage", text="Save as...", icon='DISK_DRIVE')
-                        mat_button.filepath = os.path.join(mat_lib_folder, "my-materials", material_filenames[current_material_number])
+                        mat_button.filepath = os.path.join(matlibpath, "my-materials", material_filenames[current_material_number])
                         mat_button.filename = material_filenames[current_material_number]
                         mat_button.filename_ext = "." + material_filenames[current_material_number].split(".")[-1]
                         mat_button.filter_glob = "*." + material_filenames[current_material_number].split(".")[-1]
@@ -867,7 +859,7 @@ class OnlineMaterialLibraryPanel(bpy.types.Panel):
                         
                         #Display script "Save" button
                         mat_button = functions.operator("material.librarysavescript", text="Save as...", icon='DISK_DRIVE')
-                        mat_button.filepath = os.path.join(mat_lib_folder, "my-materials", material_filenames[current_material_number])
+                        mat_button.filepath = os.path.join(matlibpath, "my-materials", material_filenames[current_material_number])
                         mat_button.filename = material_filenames[current_material_number]
                         mat_button.filename_ext = "." + material_filenames[current_material_number].split(".")[-1]
                         mat_button.filter_glob = "*." + material_filenames[current_material_number].split(".")[-1]
@@ -953,18 +945,18 @@ def handleCategory(category, index):
                 return
     
     if library is not "bundled":
-        if not os.path.exists(os.path.join(mat_lib_folder, mat_lib_host, library, "cycles", category.attributes['folder'].value)):
+        if not os.path.exists(os.path.join(matlibpath, mat_lib_host, library, "cycles", category.attributes['folder'].value)):
             print("Folder \"/" + category.attributes['folder'].value + "/\" does not exist; creating now.")
             if library == "composite":
-                os.mkdir(os.path.join(mat_lib_folder, mat_lib_host, "cycles", category.attributes['folder'].value))
+                os.mkdir(os.path.join(matlibpath, mat_lib_host, "cycles", category.attributes['folder'].value))
             else:
-                os.mkdir(os.path.join(mat_lib_folder, mat_lib_host, library, "cycles", category.attributes['folder'].value))
+                os.mkdir(os.path.join(matlibpath, mat_lib_host, library, "cycles", category.attributes['folder'].value))
         
         if 'remove' in category.attributes:
             if library == "composite":
-                if os.path.exists(os.path.join(mat_lib_folder, mat_lib_host, "cycles", category.attributes['folder'].value)):
-                    for the_file in os.listdir(os.path.join(mat_lib_folder, mat_lib_host, "cycles", category.attributes['folder'].value)):
-                        file_path = os.path.join(mat_lib_folder, mat_lib_host, "cycles", category.attributes['folder'].value, the_file)
+                if os.path.exists(os.path.join(mat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list