py api: add restrict state context manager (thats python's context not blenders context),

which restricts bpy.context and bpy.data.

enable this for loading scripts in 'startup' too.
This commit is contained in:
2012-12-20 03:56:22 +00:00
parent e4728bf910
commit 423994bf39
3 changed files with 92 additions and 45 deletions

View File

@@ -217,18 +217,21 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
del _global_loaded_modules[:]
for base_path in script_paths():
for path_subdir in _script_module_dirs:
path = _os.path.join(base_path, path_subdir)
if _os.path.isdir(path):
_sys_path_ensure(path)
from bpy_restrict_state import RestrictBlend
# only add this to sys.modules, don't run
if path_subdir == "modules":
continue
with RestrictBlend():
for base_path in script_paths():
for path_subdir in _script_module_dirs:
path = _os.path.join(base_path, path_subdir)
if _os.path.isdir(path):
_sys_path_ensure(path)
for mod in modules_from_path(path, loaded_modules):
test_register(mod)
# only add this to sys.modules, don't run
if path_subdir == "modules":
continue
for mod in modules_from_path(path, loaded_modules):
test_register(mod)
# deal with addons separately
_addon_utils.reset_all(reload_scripts)