diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-28 14:48:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-28 14:48:06 +0300 |
commit | 18ea9b6443a4029c729fc29c55d53f3a9e849ca8 (patch) | |
tree | 71dd0273e0b994870b48e2156d9c1ea9edb58ae0 /release/scripts/modules | |
parent | 72cb4548a76dba3fc39c0d8bb36e65f115d0ab22 (diff) |
move bpy.load_scripts --> bpy.utils.load_scripts
added sequencer strip length display in seconds
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/bpy/__init__.py | 72 | ||||
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 74 |
2 files changed, 76 insertions, 70 deletions
diff --git a/release/scripts/modules/bpy/__init__.py b/release/scripts/modules/bpy/__init__.py index 1b248658afd..8d654fb3978 100644 --- a/release/scripts/modules/bpy/__init__.py +++ b/release/scripts/modules/bpy/__init__.py @@ -36,74 +36,6 @@ ops = _ops_module.ops_fake_module import sys as _sys -def load_scripts(reload_scripts=False): - import os - import traceback - import time - - - t_main = time.time() - - loaded_modules = set() - - def test_import(module_name): - if module_name in loaded_modules: - return None - if "." in module_name: - print("Ignoring '%s', can't import files containing multiple periods." % module_name) - return None - - try: - t = time.time() - ret = __import__(module_name) - if app.debug: - print("time %s %.4f" % (module_name, time.time() - t)) - return ret - except: - traceback.print_exc() - return None - - def test_reload(module): - try: - reload(module) - except: - traceback.print_exc() - - if reload_scripts: - # reload modules that may not be directly included - for type_class_name in dir(types): - type_class = getattr(types, type_class_name) - module_name = getattr(type_class, "__module__", "") - - if module_name and module_name != "bpy.types": # hard coded for C types - loaded_modules.add(module_name) - - for module_name in loaded_modules: - print("Reloading:", module_name) - test_reload(_sys.modules[module_name]) - - for base_path in utils.script_paths(): - for path_subdir in ("ui", "op", "io"): - path = os.path.join(base_path, path_subdir) - if os.path.isdir(path): - if path not in _sys.path: # reloading would add twice - _sys.path.insert(0, path) - for f in sorted(os.listdir(path)): - if f.endswith(".py"): - # python module - mod = test_import(f[0:-3]) - elif "." not in f: - # python package - mod = test_import(f) - else: - mod = None - - if reload_scripts and mod: - print("Reloading:", mod) - test_reload(mod) - - if app.debug: - print("Time %.4f" % (time.time() - t_main)) def _main(): @@ -119,14 +51,14 @@ def _main(): # if "-d" in sys.argv: # Enable this to measure startup speed if 0: import cProfile - cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof') + cProfile.run('import bpy; bpy.utils.load_scripts()', 'blender.prof') import pstats p = pstats.Stats('blender.prof') p.sort_stats('cumulative').print_stats(100) else: - load_scripts() + utils.load_scripts() _main() diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 855751a0743..55116281d0a 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -25,6 +25,80 @@ not assosiated with blenders internal data. import bpy as _bpy import os as _os +import sys as _sys + +def load_scripts(reload_scripts=False, refresh_scripts=False): + import traceback + import time + + t_main = time.time() + + loaded_modules = set() + + def test_import(module_name): + if module_name in loaded_modules: + return None + if "." in module_name: + print("Ignoring '%s', can't import files containing multiple periods." % module_name) + return None + + try: + t = time.time() + ret = __import__(module_name) + if _bpy.app.debug: + print("time %s %.4f" % (module_name, time.time() - t)) + return ret + except: + traceback.print_exc() + return None + + def test_reload(module): + try: + reload(module) + except: + traceback.print_exc() + + if reload_scripts: + # reload modules that may not be directly included + for type_class_name in dir(types): + type_class = getattr(types, type_class_name) + module_name = getattr(type_class, "__module__", "") + + if module_name and module_name != "bpy.types": # hard coded for C types + loaded_modules.add(module_name) + + for module_name in loaded_modules: + print("Reloading:", module_name) + test_reload(_sys.modules[module_name]) + + for base_path in script_paths(): + for path_subdir in ("ui", "op", "io"): + path = _os.path.join(base_path, path_subdir) + if _os.path.isdir(path): + + # needed to load scripts after the users script path changes + # we should also support a full reload but since this is now unstable it can be postponed. + if refresh_scripts and path in _sys.path: + continue + + if path not in _sys.path: # reloading would add twice + _sys.path.insert(0, path) + for f in sorted(_os.listdir(path)): + if f.endswith(".py"): + # python module + mod = test_import(f[0:-3]) + elif "." not in f: + # python package + mod = test_import(f) + else: + mod = None + + if reload_scripts and mod: + print("Reloading:", mod) + test_reload(mod) + + if _bpy.app.debug: + print("Time %.4f" % (time.time() - t_main)) def expandpath(path): |