| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | # ##### BEGIN GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | #  modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | #  as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | #  of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | #  GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | #  along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  | #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # ##### END GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  | # <pep8-80 compliant> | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | __all__ = ( | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     "paths", | 
					
						
							|  |  |  |     "modules", | 
					
						
							|  |  |  |     "check", | 
					
						
							|  |  |  |     "enable", | 
					
						
							|  |  |  |     "disable", | 
					
						
							|  |  |  |     "reset_all", | 
					
						
							|  |  |  |     "module_bl_info", | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  | import bpy as _bpy | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-18 05:41:46 +00:00
										 |  |  | error_duplicates = False | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  | error_encoding = False | 
					
						
							| 
									
										
										
										
											2011-09-23 13:47:29 +00:00
										 |  |  | addons_fake_modules = {} | 
					
						
							| 
									
										
										
										
											2011-09-23 13:29:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-29 01:24:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | def paths(): | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     # RELEASE SCRIPTS: official scripts distributed in Blender releases | 
					
						
							|  |  |  |     paths = _bpy.utils.script_paths("addons") | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     # CONTRIB SCRIPTS: good for testing but not official scripts yet | 
					
						
							|  |  |  |     # if folder addons_contrib/ exists, scripts in there will be loaded too | 
					
						
							|  |  |  |     paths += _bpy.utils.script_paths("addons_contrib") | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     # EXTERN SCRIPTS: external projects scripts | 
					
						
							|  |  |  |     # if folder addons_extern/ exists, scripts in there will be loaded too | 
					
						
							|  |  |  |     paths += _bpy.utils.script_paths("addons_extern") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return paths | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def modules(module_cache): | 
					
						
							| 
									
										
										
										
											2011-07-18 05:41:46 +00:00
										 |  |  |     global error_duplicates | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  |     global error_encoding | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     import os | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-18 05:41:46 +00:00
										 |  |  |     error_duplicates = False | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  |     error_encoding = False | 
					
						
							| 
									
										
										
										
											2011-07-18 05:41:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     path_list = paths() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # fake module importing | 
					
						
							| 
									
										
										
										
											2011-11-17 20:11:20 +00:00
										 |  |  |     def fake_module(mod_name, mod_path, speedy=True, force_support=None): | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  |         global error_encoding | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |         if _bpy.app.debug: | 
					
						
							|  |  |  |             print("fake_module", mod_path, mod_name) | 
					
						
							|  |  |  |         import ast | 
					
						
							|  |  |  |         ModuleType = type(ast) | 
					
						
							|  |  |  |         file_mod = open(mod_path, "r", encoding='UTF-8') | 
					
						
							|  |  |  |         if speedy: | 
					
						
							|  |  |  |             lines = [] | 
					
						
							|  |  |  |             line_iter = iter(file_mod) | 
					
						
							|  |  |  |             l = "" | 
					
						
							|  |  |  |             while not l.startswith("bl_info"): | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  |                 try: | 
					
						
							|  |  |  |                     l = line_iter.readline() | 
					
						
							|  |  |  |                 except UnicodeDecodeError as e: | 
					
						
							|  |  |  |                     if not error_encoding: | 
					
						
							|  |  |  |                         error_encoding = True | 
					
						
							|  |  |  |                         print("Error reading file as UTF-8:", mod_path, e) | 
					
						
							|  |  |  |                     file_mod.close() | 
					
						
							|  |  |  |                     return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |                 if len(l) == 0: | 
					
						
							|  |  |  |                     break | 
					
						
							|  |  |  |             while l.rstrip(): | 
					
						
							|  |  |  |                 lines.append(l) | 
					
						
							| 
									
										
										
										
											2011-08-07 04:55:58 +00:00
										 |  |  |                 try: | 
					
						
							|  |  |  |                     l = line_iter.readline() | 
					
						
							|  |  |  |                 except UnicodeDecodeError as e: | 
					
						
							|  |  |  |                     if not error_encoding: | 
					
						
							|  |  |  |                         error_encoding = True | 
					
						
							|  |  |  |                         print("Error reading file as UTF-8:", mod_path, e) | 
					
						
							|  |  |  |                     file_mod.close() | 
					
						
							|  |  |  |                     return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |             data = "".join(lines) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             data = file_mod.read() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         file_mod.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             ast_data = ast.parse(data, filename=mod_path) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             print("Syntax error 'ast.parse' can't read %r" % mod_path) | 
					
						
							|  |  |  |             import traceback | 
					
						
							|  |  |  |             traceback.print_exc() | 
					
						
							|  |  |  |             ast_data = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         body_info = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ast_data: | 
					
						
							|  |  |  |             for body in ast_data.body: | 
					
						
							|  |  |  |                 if body.__class__ == ast.Assign: | 
					
						
							|  |  |  |                     if len(body.targets) == 1: | 
					
						
							|  |  |  |                         if getattr(body.targets[0], "id", "") == "bl_info": | 
					
						
							|  |  |  |                             body_info = body | 
					
						
							|  |  |  |                             break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if body_info: | 
					
						
							| 
									
										
										
										
											2011-03-27 20:52:50 +00:00
										 |  |  |             try: | 
					
						
							|  |  |  |                 mod = ModuleType(mod_name) | 
					
						
							|  |  |  |                 mod.bl_info = ast.literal_eval(body.value) | 
					
						
							|  |  |  |                 mod.__file__ = mod_path | 
					
						
							|  |  |  |                 mod.__time__ = os.path.getmtime(mod_path) | 
					
						
							|  |  |  |             except: | 
					
						
							|  |  |  |                 print("AST error in module %s" % mod_name) | 
					
						
							|  |  |  |                 import traceback | 
					
						
							|  |  |  |                 traceback.print_exc() | 
					
						
							|  |  |  |                 raise | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 20:11:20 +00:00
										 |  |  |             if force_support is not None: | 
					
						
							|  |  |  |                 mod.bl_info["support"] = force_support | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |             return mod | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     modules_stale = set(module_cache.keys()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for path in path_list: | 
					
						
							| 
									
										
										
										
											2011-11-17 20:11:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # force all contrib addons to be 'TESTING' | 
					
						
							| 
									
										
										
										
											2011-11-21 14:19:34 +00:00
										 |  |  |         if path.endswith("addons_contrib") or path.endswith("addons_extern"): | 
					
						
							|  |  |  |             force_support = 'TESTING' | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             force_support = None | 
					
						
							| 
									
										
										
										
											2011-11-17 20:11:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |         for mod_name, mod_path in _bpy.path.module_names(path): | 
					
						
							|  |  |  |             modules_stale -= {mod_name} | 
					
						
							|  |  |  |             mod = module_cache.get(mod_name) | 
					
						
							|  |  |  |             if mod: | 
					
						
							| 
									
										
										
										
											2011-07-18 05:41:46 +00:00
										 |  |  |                 if mod.__file__ != mod_path: | 
					
						
							|  |  |  |                     print("multiple addons with the same name:\n  %r\n  %r" % | 
					
						
							|  |  |  |                           (mod.__file__, mod_path)) | 
					
						
							|  |  |  |                     error_duplicates = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 elif mod.__time__ != os.path.getmtime(mod_path): | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |                     print("reloading addon:", | 
					
						
							|  |  |  |                           mod_name, | 
					
						
							|  |  |  |                           mod.__time__, | 
					
						
							|  |  |  |                           os.path.getmtime(mod_path), | 
					
						
							|  |  |  |                           mod_path, | 
					
						
							|  |  |  |                           ) | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |                     del module_cache[mod_name] | 
					
						
							|  |  |  |                     mod = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if mod is None: | 
					
						
							| 
									
										
										
										
											2011-11-24 19:36:12 +00:00
										 |  |  |                 mod = fake_module(mod_name, | 
					
						
							|  |  |  |                                   mod_path, | 
					
						
							|  |  |  |                                   force_support=force_support) | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |                 if mod: | 
					
						
							|  |  |  |                     module_cache[mod_name] = mod | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-17 06:58:07 +00:00
										 |  |  |     # just in case we get stale modules, not likely | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     for mod_stale in modules_stale: | 
					
						
							|  |  |  |         del module_cache[mod_stale] | 
					
						
							|  |  |  |     del modules_stale | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mod_list = list(module_cache.values()) | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |     mod_list.sort(key=lambda mod: (mod.bl_info['category'], | 
					
						
							|  |  |  |                                    mod.bl_info['name'], | 
					
						
							|  |  |  |                                    )) | 
					
						
							| 
									
										
										
										
											2011-02-25 16:06:14 +00:00
										 |  |  |     return mod_list | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def check(module_name): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Returns the loaded state of the addon. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     :arg module_name: The name of the addon and module. | 
					
						
							|  |  |  |     :type module_name: string | 
					
						
							|  |  |  |     :return: (loaded_default, loaded_state) | 
					
						
							|  |  |  |     :rtype: tuple of booleans | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     import sys | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |     loaded_default = module_name in _bpy.context.user_preferences.addons | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     mod = sys.modules.get(module_name) | 
					
						
							|  |  |  |     loaded_state = mod and getattr(mod, "__addon_enabled__", Ellipsis) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if loaded_state is Ellipsis: | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |         print("Warning: addon-module %r found module " | 
					
						
							|  |  |  |                "but without __addon_enabled__ field, " | 
					
						
							|  |  |  |                "possible name collision from file: %r" % | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |                (module_name, getattr(mod, "__file__", "<unknown>"))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         loaded_state = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return loaded_default, loaded_state | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def enable(module_name, default_set=True): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Enables an addon by name. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     :arg module_name: The name of the addon and module. | 
					
						
							|  |  |  |     :type module_name: string | 
					
						
							| 
									
										
										
										
											2011-10-17 06:58:07 +00:00
										 |  |  |     :return: the loaded module or None on failure. | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |     :rtype: module | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     import os | 
					
						
							|  |  |  |     import sys | 
					
						
							|  |  |  |     import imp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def handle_error(): | 
					
						
							|  |  |  |         import traceback | 
					
						
							|  |  |  |         traceback.print_exc() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # reload if the mtime changes | 
					
						
							|  |  |  |     mod = sys.modules.get(module_name) | 
					
						
							| 
									
										
										
										
											2011-11-26 17:41:56 +00:00
										 |  |  |     # chances of the file _not_ existing are low, but it could be removed | 
					
						
							|  |  |  |     if mod and os.path.exists(mod.__file__): | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |         mod.__addon_enabled__ = False | 
					
						
							|  |  |  |         mtime_orig = getattr(mod, "__time__", 0) | 
					
						
							|  |  |  |         mtime_new = os.path.getmtime(mod.__file__) | 
					
						
							|  |  |  |         if mtime_orig != mtime_new: | 
					
						
							|  |  |  |             print("module changed on disk:", mod.__file__, "reloading...") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 imp.reload(mod) | 
					
						
							|  |  |  |             except: | 
					
						
							|  |  |  |                 handle_error() | 
					
						
							|  |  |  |                 del sys.modules[module_name] | 
					
						
							|  |  |  |                 return None | 
					
						
							|  |  |  |             mod.__addon_enabled__ = False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |     # Split registering up into 3 steps so we can undo | 
					
						
							|  |  |  |     # if it fails par way through. | 
					
						
							| 
									
										
										
										
											2011-11-26 17:41:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |     # 1) try import | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         mod = __import__(module_name) | 
					
						
							|  |  |  |         mod.__time__ = os.path.getmtime(mod.__file__) | 
					
						
							|  |  |  |         mod.__addon_enabled__ = False | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         handle_error() | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # 2) try register collected modules | 
					
						
							|  |  |  |     # removed, addons need to handle own registration now. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # 3) try run the modules register function | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         mod.register() | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         handle_error() | 
					
						
							|  |  |  |         del sys.modules[module_name] | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # * OK loaded successfully! * | 
					
						
							|  |  |  |     if default_set: | 
					
						
							| 
									
										
										
										
											2011-10-17 06:58:07 +00:00
										 |  |  |         # just in case its enabled already | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |         ext = _bpy.context.user_preferences.addons.get(module_name) | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |         if not ext: | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |             ext = _bpy.context.user_preferences.addons.new() | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |             ext.module = module_name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mod.__addon_enabled__ = True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |     if _bpy.app.debug: | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |         print("\taddon_utils.enable", mod.__name__) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return mod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def disable(module_name, default_set=True): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Disables an addon by name. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     :arg module_name: The name of the addon and module. | 
					
						
							|  |  |  |     :type module_name: string | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     import sys | 
					
						
							|  |  |  |     mod = sys.modules.get(module_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-17 06:58:07 +00:00
										 |  |  |     # possible this addon is from a previous session and didn't load a | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  |     # module this time. So even if the module is not found, still disable | 
					
						
							|  |  |  |     # the addon in the user prefs. | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |     if mod: | 
					
						
							|  |  |  |         mod.__addon_enabled__ = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             mod.unregister() | 
					
						
							|  |  |  |         except: | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |             import traceback | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |             traceback.print_exc() | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         print("addon_utils.disable", module_name, "not loaded") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-17 06:58:07 +00:00
										 |  |  |     # could be in more then once, unlikely but better do this just in case. | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |     addons = _bpy.context.user_preferences.addons | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if default_set: | 
					
						
							|  |  |  |         while module_name in addons: | 
					
						
							|  |  |  |             addon = addons.get(module_name) | 
					
						
							|  |  |  |             if addon: | 
					
						
							|  |  |  |                 addons.remove(addon) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |     if _bpy.app.debug: | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |         print("\taddon_utils.disable", module_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def reset_all(reload_scripts=False): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Sets the addon state based on the user preferences. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     import sys | 
					
						
							|  |  |  |     import imp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # RELEASE SCRIPTS: official scripts distributed in Blender releases | 
					
						
							|  |  |  |     paths_list = paths() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for path in paths_list: | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |         _bpy.utils._sys_path_ensure(path) | 
					
						
							|  |  |  |         for mod_name, mod_path in _bpy.path.module_names(path): | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |             is_enabled, is_loaded = check(mod_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # first check if reload is needed before changing state. | 
					
						
							|  |  |  |             if reload_scripts: | 
					
						
							|  |  |  |                 mod = sys.modules.get(mod_name) | 
					
						
							|  |  |  |                 if mod: | 
					
						
							|  |  |  |                     imp.reload(mod) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if is_enabled == is_loaded: | 
					
						
							|  |  |  |                 pass | 
					
						
							|  |  |  |             elif is_enabled: | 
					
						
							|  |  |  |                 enable(mod_name) | 
					
						
							|  |  |  |             elif is_loaded: | 
					
						
							|  |  |  |                 print("\taddon_utils.reset_all unloading", mod_name) | 
					
						
							| 
									
										
										
										
											2011-02-22 22:24:50 +00:00
										 |  |  |                 disable(mod_name) | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-31 03:15:37 +00:00
										 |  |  | def module_bl_info(mod, info_basis={"name": "", | 
					
						
							|  |  |  |                                     "author": "", | 
					
						
							|  |  |  |                                     "version": (), | 
					
						
							|  |  |  |                                     "blender": (), | 
					
						
							|  |  |  |                                     "api": 0, | 
					
						
							|  |  |  |                                     "location": "", | 
					
						
							|  |  |  |                                     "description": "", | 
					
						
							|  |  |  |                                     "wiki_url": "", | 
					
						
							|  |  |  |                                     "tracker_url": "", | 
					
						
							|  |  |  |                                     "support": 'COMMUNITY', | 
					
						
							|  |  |  |                                     "category": "", | 
					
						
							|  |  |  |                                     "warning": "", | 
					
						
							|  |  |  |                                     "show_expanded": False, | 
					
						
							|  |  |  |                                     } | 
					
						
							|  |  |  |                    ): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-21 07:07:44 +00:00
										 |  |  |     addon_info = getattr(mod, "bl_info", {}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # avoid re-initializing | 
					
						
							|  |  |  |     if "_init" in addon_info: | 
					
						
							|  |  |  |         return addon_info | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not addon_info: | 
					
						
							|  |  |  |         mod.bl_info = addon_info | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for key, value in info_basis.items(): | 
					
						
							|  |  |  |         addon_info.setdefault(key, value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not addon_info["name"]: | 
					
						
							|  |  |  |         addon_info["name"] = mod.__name__ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     addon_info["_init"] = None | 
					
						
							|  |  |  |     return addon_info |