[Bf-blender-cvs] [5bd6561266] app-templates: Don't attempt template loading when they're not present
Campbell Barton
noreply at git.blender.org
Thu Mar 23 10:46:12 CET 2017
Commit: 5bd65612661dcb181540242e774fdc7548cdb738
Author: Campbell Barton
Date: Thu Mar 23 20:32:23 2017 +1100
Branches: app-templates
https://developer.blender.org/rB5bd65612661dcb181540242e774fdc7548cdb738
Don't attempt template loading when they're not present
===================================================================
M release/scripts/modules/bpy/utils/__init__.py
M source/blender/blenkernel/BKE_appdir.h
M source/blender/blenkernel/intern/appdir.c
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 5e21ef1905..f760f52615 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -68,7 +68,6 @@ import os as _os
import sys as _sys
import addon_utils as _addon_utils
-import bl_app_template_utils as _bl_app_template_utils
_user_preferences = _bpy.context.user_preferences
_script_module_dirs = "startup", "modules"
@@ -248,7 +247,10 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
test_register(mod)
# load template (if set)
- _bl_app_template_utils.reset(reload_scripts=reload_scripts)
+ if any(_bpy.utils.app_template_paths()):
+ import bl_app_template_utils
+ bl_app_template_utils.reset(reload_scripts=reload_scripts)
+ del bl_app_template_utils
# deal with addons separately
_initialize = getattr(_addon_utils, "_initialize", None)
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index 52a6cfad43..84621a8463 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -32,7 +32,8 @@ const char *BKE_appdir_folder_id_create(const int folder_id, const char *subfold
const char *BKE_appdir_folder_id_user_notest(const int folder_id, const char *subfolder);
const char *BKE_appdir_folder_id_version(const int folder_id, const int ver, const bool do_check);
-const char *BKE_appdir_template_id_search(const char *app_template);
+bool BKE_appdir_app_template_any(void);
+const char *BKE_appdir_app_template_id_search(const char *app_template);
/* Initialize path to program executable */
void BKE_appdir_program_path_init(const char *argv0);
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 758eb77cfb..a86ef11254 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -655,28 +655,44 @@ bool BKE_appdir_program_python_search(
return is_found;
}
-const char *BKE_appdir_template_id_search(const char *app_template)
-{
#ifdef WIN32
# define SEP_STR "\\"
#else
# define SEP_STR "/"
#endif
+
+static const char *app_template_directory_search[2] = {
+ "startup" SEP_STR "bl_app_templates_system",
+ "startup" SEP_STR "bl_app_templates_user",
+};
+#undef SEP_STR
+
+static const int app_template_directory_id[2] = {
+ BLENDER_SYSTEM_SCRIPTS,
+ BLENDER_USER_SCRIPTS,
+};
+
+bool BKE_appdir_app_template_any(void)
+{
+ for (int i = 0; i < 2; i++) {
+ if (BKE_appdir_folder_id(app_template_directory_id[i], app_template_directory_search[i])) {
+ return true;
+ }
+ }
+ return false;
+}
+
+const char *BKE_appdir_app_template_id_search(const char *app_template)
+{
static char path[FILE_MAX] = "";
- int folder_id[2] = {BLENDER_SYSTEM_SCRIPTS, BLENDER_USER_SCRIPTS};
- const char *folder_name[2] = {
- "startup" SEP_STR "bl_app_templates_system",
- "startup" SEP_STR "bl_app_templates_user",
- };
for (int i = 0; i < 2; i++) {
- BLI_join_dirfile(path, sizeof(path), folder_name[i], app_template);
- const char *filepath_startup_template = BKE_appdir_folder_id(folder_id[i], path);
+ BLI_join_dirfile(path, sizeof(path), app_template_directory_search[i], app_template);
+ const char *filepath_startup_template = BKE_appdir_folder_id(app_template_directory_id[i], path);
if (filepath_startup_template) {
BLI_strncpy(path, filepath_startup_template, sizeof(path));
return path;
}
}
-#undef SEP_STR
return NULL;
}
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 44b5b75763..d4abbb4bc0 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -470,8 +470,9 @@ static void wm_file_read_post(bContext *C, bool is_startup_file)
if (is_startup_file) {
/* possible python hasn't been initialized */
if (CTX_py_init_get(C)) {
- BPY_execute_string(C, "__import__('bl_app_template_utils').reset()");
-
+ if (BKE_appdir_app_template_any()) {
+ BPY_execute_string(C, "__import__('bl_app_template_utils').reset()");
+ }
/* sync addons, these may have changed from the defaults */
BPY_execute_string(C, "__import__('addon_utils').reset_all()");
@@ -724,7 +725,7 @@ int wm_homefile_read(
}
if (app_template != NULL) {
- const char *path = BKE_appdir_template_id_search(app_template);
+ const char *path = BKE_appdir_app_template_id_search(app_template);
if (path) {
BLI_strncpy(template_directory, path, sizeof(template_directory));
}
More information about the Bf-blender-cvs
mailing list