[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49343] trunk/blender/release/scripts: fix for own regression with handling of script paths, however this didnt work quite right before either.

Campbell Barton ideasman42 at gmail.com
Sun Jul 29 03:02:29 CEST 2012


Revision: 49343
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49343
Author:   campbellbarton
Date:     2012-07-29 01:02:25 +0000 (Sun, 29 Jul 2012)
Log Message:
-----------
fix for own regression with handling of script paths, however this didnt work quite right before either.

Handle these 2 kinds of script paths
* user script path: ~/.blender/scripts OR $BLENDER_USER_SCRIPTS
* pref script path: always bpy.context.user_preferences.filepaths.script_directory

now both are returned by bpy.utils.script_paths()

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py
    trunk/blender/release/scripts/modules/sys_info.py
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2012-07-29 00:34:18 UTC (rev 49342)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2012-07-29 01:02:25 UTC (rev 49343)
@@ -34,13 +34,14 @@
     "register_class",
     "register_module",
     "resource_path",
+    "script_path_user",
+    "script_path_pref",
     "script_paths",
     "smpte_from_frame",
     "smpte_from_seconds",
     "unregister_class",
     "unregister_module",
     "user_resource",
-    "user_script_path",
     )
 
 from _bpy import register_class, unregister_class, blend_paths, resource_path
@@ -252,17 +253,18 @@
 _scripts = (_os.path.normpath(_scripts), )
 
 
-def user_script_path():
-    # returns the env var and falls back to userprefs
+def script_path_user():
+    """returns the env var and falls back to home dir or None"""
     path = _user_resource('SCRIPTS')
+    return _os.path.normpath(path) if path else None
 
-    if path:
-        path = _os.path.normpath(path)
-        return path
-    else:
-        return None
 
+def script_path_pref():
+    """returns the user preference or None"""
+    path = _bpy.context.user_preferences.filepaths.script_directory
+    return _os.path.normpath(path) if path else None
 
+
 def script_paths(subdir=None, user_pref=True, check_all=False):
     """
     Returns a list of valid script paths.
@@ -278,11 +280,7 @@
     :rtype: list
     """
     scripts = list(_scripts)
-    prefs = _bpy.context.user_preferences
 
-    # add user scripts dir
-    user_script = user_script_path()
-
     if check_all:
         # all possible paths
         base_paths = tuple(_os.path.join(resource_path(res), "scripts")
@@ -291,7 +289,7 @@
         # only paths blender uses
         base_paths = _bpy_script_paths()
 
-    for path in base_paths + (user_script, ):
+    for path in base_paths + (script_path_user(), script_path_pref()):
         if path:
             path = _os.path.normpath(path)
             if path not in scripts and _os.path.isdir(path):

Modified: trunk/blender/release/scripts/modules/sys_info.py
===================================================================
--- trunk/blender/release/scripts/modules/sys_info.py	2012-07-29 00:34:18 UTC (rev 49342)
+++ trunk/blender/release/scripts/modules/sys_info.py	2012-07-29 01:02:25 UTC (rev 49343)
@@ -87,7 +87,8 @@
     output.write("\nDirectories:\n")
     output.write(lilies)
     output.write("scripts: %r\n" % (bpy.utils.script_paths()))
-    output.write("user scripts: %r\n" % (bpy.utils.user_script_path()))
+    output.write("user scripts: %r\n" % (bpy.utils.script_path_user()))
+    output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref()))
     output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES')))
     output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG')))
     output.write("scripts : %r\n" % (bpy.utils.user_resource('SCRIPTS')))

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-07-29 00:34:18 UTC (rev 49342)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-07-29 01:02:25 UTC (rev 49343)
@@ -1004,10 +1004,10 @@
     @staticmethod
     def is_user_addon(mod, user_addon_paths):
         if not user_addon_paths:
-            user_script_path = bpy.utils.user_script_path()
-            if user_script_path is not None:
-                user_addon_paths.append(os.path.join(user_script_path, "addons"))
-            user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons"))
+            for path in (bpy.utils.script_path_user(),
+                         bpy.utils.script_path_pref()):
+                if path is not None:
+                    user_addon_paths.append(os.path.join(path, "addons"))
 
         for path in user_addon_paths:
             if bpy.path.is_subdir(mod.__file__, path):




More information about the Bf-blender-cvs mailing list