Fix T52442: bl_app_templates_system not working
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Sep 2017 19:46:43 +0000 (05:46 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Sep 2017 19:57:37 +0000 (05:57 +1000)
Portable builds LOCAL files need to be
treated as system instead of using as a fallback to USER templates.

release/scripts/modules/bpy/utils/__init__.py
source/blender/blenkernel/intern/appdir.c

index 185a0e732791f2f34e29ba64809688c5004421da..c3175f93f4e1b3356529c24808355b440eaa2996 100644 (file)
@@ -400,27 +400,26 @@ def app_template_paths(subdir=None):
     :return: app template paths.
     :rtype: generator
     """
+    # Note: keep in sync with: Blender's BKE_appdir_app_template_any
 
-    # note: LOCAL, USER, SYSTEM order matches script resolution order.
     subdir_tuple = (subdir,) if subdir is not None else ()
 
-    path = _os.path.join(*(
-        resource_path('LOCAL'), "scripts", "startup",
-        "bl_app_templates_user", *subdir_tuple))
-    if _os.path.isdir(path):
-        yield path
-    else:
-        path = _os.path.join(*(
-            resource_path('USER'), "scripts", "startup",
-            "bl_app_templates_user", *subdir_tuple))
-        if _os.path.isdir(path):
-            yield path
-
-    path = _os.path.join(*(
-        resource_path('SYSTEM'), "scripts", "startup",
-        "bl_app_templates_system", *subdir_tuple))
-    if _os.path.isdir(path):
-        yield path
+    # Avoid adding 'bl_app_templates_system' twice.
+    # Either we have a portable build or an installed system build.
+    for resource_type, module_name in (
+            ('USER', "bl_app_templates_user"),
+            ('LOCAL', "bl_app_templates_system"),
+            ('SYSTEM', "bl_app_templates_system"),
+    ):
+        path = resource_path(resource_type)
+        if path:
+            path = _os.path.join(
+                *(path, "scripts", "startup", module_name, *subdir_tuple))
+            if _os.path.isdir(path):
+                yield path
+                # Only load LOCAL or SYSTEM (never both).
+                if resource_type == 'LOCAL':
+                    break
 
 
 def preset_paths(subdir):
index d059310a0f8c12b254e92c2bf538cb8324cf99dc..6dd852c78758f15a5f463ea64b5d726ae76e0ebc 100644 (file)
@@ -691,13 +691,16 @@ bool BKE_appdir_program_python_search(
        return is_found;
 }
 
+/** Keep in sync with `bpy.utils.app_template_paths()` */
 static const char *app_template_directory_search[2] = {
        "startup" SEP_STR "bl_app_templates_user",
        "startup" SEP_STR "bl_app_templates_system",
 };
 
 static const int app_template_directory_id[2] = {
+       /* Only 'USER' */
        BLENDER_USER_SCRIPTS,
+       /* Covers 'LOCAL' & 'SYSTEM'. */
        BLENDER_SYSTEM_SCRIPTS,
 };