Blender V2.61 - r43446
|
00001 # ##### BEGIN GPL LICENSE BLOCK ##### 00002 # 00003 # This program is free software; you can redistribute it and/or 00004 # modify it under the terms of the GNU General Public License 00005 # as published by the Free Software Foundation; either version 2 00006 # of the License, or (at your option) any later version. 00007 # 00008 # This program is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 # GNU General Public License for more details. 00012 # 00013 # You should have received a copy of the GNU General Public License 00014 # along with this program; if not, write to the Free Software Foundation, 00015 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00016 # 00017 # ##### END GPL LICENSE BLOCK ##### 00018 00019 # <pep8 compliant> 00020 00021 # simple script to enable all addons, and disable 00022 00023 import bpy 00024 import addon_utils 00025 00026 import sys 00027 import imp 00028 00029 00030 def reload_addons(do_reload=True, do_reverse=True): 00031 modules = addon_utils.modules({}) 00032 modules.sort(key=lambda mod: mod.__name__) 00033 addons = bpy.context.user_preferences.addons 00034 00035 # first disable all 00036 for mod_name in list(addons.keys()): 00037 addon_utils.disable(mod_name) 00038 00039 assert(bool(addons) == False) 00040 00041 # Run twice each time. 00042 for i in (0, 1): 00043 for mod in modules: 00044 mod_name = mod.__name__ 00045 print("\tenabling:", mod_name) 00046 addon_utils.enable(mod_name) 00047 assert(mod_name in addons) 00048 00049 for mod in addon_utils.modules({}): 00050 mod_name = mod.__name__ 00051 print("\tdisabling:", mod_name) 00052 addon_utils.disable(mod_name) 00053 assert(not (mod_name in addons)) 00054 00055 # now test reloading 00056 if do_reload: 00057 imp.reload(sys.modules[mod_name]) 00058 00059 if do_reverse: 00060 # incase order matters when it shouldnt 00061 modules.reverse() 00062 00063 00064 def main(): 00065 reload_addons(do_reload=False, do_reverse=False) 00066 reload_addons(do_reload=False, do_reverse=True) 00067 reload_addons(do_reload=True, do_reverse=True) 00068 00069 00070 if __name__ == "__main__": 00071 00072 # So a python error exits(1) 00073 try: 00074 main() 00075 except: 00076 import traceback 00077 traceback.print_exc() 00078 sys.exit(1)