Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/addon_utils.py
| Show All 32 Lines | |||||
| _user_preferences = _bpy.context.user_preferences | _user_preferences = _bpy.context.user_preferences | ||||
| error_encoding = False | error_encoding = False | ||||
| # (name, file, path) | # (name, file, path) | ||||
| error_duplicates = [] | error_duplicates = [] | ||||
| addons_fake_modules = {} | addons_fake_modules = {} | ||||
| class _BL_Origin: | |||||
| __slots__ = ( | |||||
| "bl_origin_prev", | |||||
| "bl_origin_curr", | |||||
| ) | |||||
| def __enter__(self): | |||||
| from _bpy import _bl_origin_get, _bl_origin_set | |||||
| self.bl_origin_prev = _bl_origin_get() | |||||
| _bl_origin_set(self.bl_origin_curr) | |||||
| def __exit__(self, type, value, traceback): | |||||
| from _bpy import _bl_origin_set | |||||
| _bl_origin_set(self.bl_origin_prev) | |||||
| def __init__(self, bl_origin): | |||||
| self.bl_origin_curr = bl_origin | |||||
| # called only once at startup, avoids calling 'reset_all', correct but slower. | # called only once at startup, avoids calling 'reset_all', correct but slower. | ||||
| def _initialize(): | def _initialize(): | ||||
| path_list = paths() | path_list = paths() | ||||
| for path in path_list: | for path in path_list: | ||||
| _bpy.utils._sys_path_ensure(path) | _bpy.utils._sys_path_ensure(path) | ||||
| for addon in _user_preferences.addons: | for addon in _user_preferences.addons: | ||||
| enable(addon.module) | enable(addon.module) | ||||
| ▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | with RestrictBlend(): | ||||
| if default_set: | if default_set: | ||||
| _addon_remove(module_name) | _addon_remove(module_name) | ||||
| return None | return None | ||||
| # 2) try register collected modules | # 2) try register collected modules | ||||
| # removed, addons need to handle own registration now. | # removed, addons need to handle own registration now. | ||||
| # 3) try run the modules register function | # 3) try run the modules register function | ||||
| try: | try: | ||||
| with _BL_Origin(module_name): | |||||
| mod.register() | mod.register() | ||||
| except Exception as ex: | except Exception as ex: | ||||
| print("Exception in module register(): %r" % | print("Exception in module register(): %r" % | ||||
| getattr(mod, "__file__", module_name)) | getattr(mod, "__file__", module_name)) | ||||
| handle_error(ex) | handle_error(ex) | ||||
| del sys.modules[module_name] | del sys.modules[module_name] | ||||
| if default_set: | if default_set: | ||||
| _addon_remove(module_name) | _addon_remove(module_name) | ||||
| return None | return None | ||||
| ▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines | |||||