| 
									
										
										
										
											2011-03-18 23:58:13 +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 ##### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # simple script to enable all addons, and disable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  | """
 | 
					
						
							|  |  |  | ./blender.bin --background -noaudio --factory-startup --python tests/python/bl_load_addons.py | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | import bpy | 
					
						
							|  |  |  | import addon_utils | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | import sys | 
					
						
							|  |  |  | import imp | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  | BLACKLIST_DIRS = ( | 
					
						
							|  |  |  |     os.path.join(bpy.utils.resource_path('USER'), "scripts"), | 
					
						
							|  |  |  |     ) + tuple(addon_utils.paths()[1:]) | 
					
						
							| 
									
										
										
										
											2015-04-10 11:38:30 +10:00
										 |  |  | BLACKLIST_ADDONS = set() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 16:26:00 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 11:38:30 +10:00
										 |  |  | def _init_addon_blacklist(): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # in case we built without cycles | 
					
						
							|  |  |  |     if not bpy.app.build_options.cycles: | 
					
						
							|  |  |  |         BLACKLIST_ADDONS.add("cycles") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # in case we built without freestyle | 
					
						
							|  |  |  |     if not bpy.app.build_options.freestyle: | 
					
						
							|  |  |  |         BLACKLIST_ADDONS.add("render_freestyle_svg") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # netrender has known problems re-registering | 
					
						
							|  |  |  |     BLACKLIST_ADDONS.add("netrender") | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def addon_modules_sorted(): | 
					
						
							|  |  |  |     modules = addon_utils.modules({}) | 
					
						
							| 
									
										
										
										
											2015-04-10 11:38:30 +10:00
										 |  |  |     modules[:] = [ | 
					
						
							|  |  |  |             mod for mod in modules | 
					
						
							|  |  |  |             if not (mod.__file__.startswith(BLACKLIST_DIRS)) | 
					
						
							|  |  |  |             if not (mod.__name__ in BLACKLIST_ADDONS)] | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  |     modules.sort(key=lambda mod: mod.__name__) | 
					
						
							|  |  |  |     return modules | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 23:17:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  | def disable_addons(): | 
					
						
							|  |  |  |     # first disable all | 
					
						
							|  |  |  |     addons = bpy.context.user_preferences.addons | 
					
						
							|  |  |  |     for mod_name in list(addons.keys()): | 
					
						
							| 
									
										
										
										
											2015-06-14 05:12:45 +10:00
										 |  |  |         addon_utils.disable(mod_name, default_set=True) | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     assert(bool(addons) is False) | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test_load_addons(): | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  |     modules = addon_modules_sorted() | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     disable_addons() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  |     addons = bpy.context.user_preferences.addons | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     addons_fail = [] | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     for mod in modules: | 
					
						
							|  |  |  |         mod_name = mod.__name__ | 
					
						
							|  |  |  |         print("\tenabling:", mod_name) | 
					
						
							| 
									
										
										
										
											2015-01-23 21:09:31 +11:00
										 |  |  |         addon_utils.enable(mod_name, default_set=True) | 
					
						
							| 
									
										
										
										
											2015-04-10 11:38:30 +10:00
										 |  |  |         if (mod_name not in addons) and (mod_name not in BLACKLIST_ADDONS): | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |             addons_fail.append(mod_name) | 
					
						
							| 
									
										
										
										
											2013-04-07 01:38:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     if addons_fail: | 
					
						
							|  |  |  |         print("addons failed to load (%d):" % len(addons_fail)) | 
					
						
							|  |  |  |         for mod_name in addons_fail: | 
					
						
							|  |  |  |             print("    %s" % mod_name) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         print("addons all loaded without errors!") | 
					
						
							|  |  |  |     print("") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def reload_addons(do_reload=True, do_reverse=True): | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  |     modules = addon_modules_sorted() | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     addons = bpy.context.user_preferences.addons | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     disable_addons() | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Run twice each time. | 
					
						
							|  |  |  |     for i in (0, 1): | 
					
						
							|  |  |  |         for mod in modules: | 
					
						
							|  |  |  |             mod_name = mod.__name__ | 
					
						
							|  |  |  |             print("\tenabling:", mod_name) | 
					
						
							| 
									
										
										
										
											2015-01-23 21:09:31 +11:00
										 |  |  |             addon_utils.enable(mod_name, default_set=True) | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  |             assert(mod_name in addons) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  |         for mod in modules: | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  |             mod_name = mod.__name__ | 
					
						
							|  |  |  |             print("\tdisabling:", mod_name) | 
					
						
							| 
									
										
										
										
											2015-06-14 05:12:45 +10:00
										 |  |  |             addon_utils.disable(mod_name, default_set=True) | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  |             assert(not (mod_name in addons)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # now test reloading | 
					
						
							|  |  |  |             if do_reload: | 
					
						
							|  |  |  |                 imp.reload(sys.modules[mod_name]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-21 12:56:30 +11:00
										 |  |  |         if do_reverse: | 
					
						
							|  |  |  |             # in case order matters when it shouldn't | 
					
						
							|  |  |  |             modules.reverse() | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2015-04-10 11:38:30 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _init_addon_blacklist() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 03:10:30 +00:00
										 |  |  |     # first load addons, print a list of all addons that fail | 
					
						
							|  |  |  |     test_load_addons() | 
					
						
							| 
									
										
										
										
											2013-04-07 01:38:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 23:58:13 +00:00
										 |  |  |     reload_addons(do_reload=False, do_reverse=False) | 
					
						
							|  |  |  |     reload_addons(do_reload=False, do_reverse=True) | 
					
						
							|  |  |  |     reload_addons(do_reload=True, do_reverse=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # So a python error exits(1) | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         main() | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         import traceback | 
					
						
							|  |  |  |         traceback.print_exc() | 
					
						
							|  |  |  |         sys.exit(1) |