[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38468] trunk/blender/release/scripts: fix [#28005] Python Add-Ons are constantly reloaded if twice in the path

Campbell Barton ideasman42 at gmail.com
Mon Jul 18 07:41:46 CEST 2011


Revision: 38468
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38468
Author:   campbellbarton
Date:     2011-07-18 05:41:46 +0000 (Mon, 18 Jul 2011)
Log Message:
-----------
fix [#28005] Python Add-Ons are constantly reloaded if twice in the path
Addons are checked for their timestamps and reloaded when it changes but this failed when, 2 addons had the same name since different times caused 2 reloads on every redraw.

Now when duplicate addons are in the path now give a error message in the UI and print path conflict in the console and don't thrash reloading.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/addon_utils.py
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py

Modified: trunk/blender/release/scripts/modules/addon_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/addon_utils.py	2011-07-18 05:12:50 UTC (rev 38467)
+++ trunk/blender/release/scripts/modules/addon_utils.py	2011-07-18 05:41:46 UTC (rev 38468)
@@ -31,6 +31,8 @@
 import bpy as _bpy
 
 
+error_duplicates = False
+
 def paths():
     # RELEASE SCRIPTS: official scripts distributed in Blender releases
     paths = _bpy.utils.script_paths("addons")
@@ -47,8 +49,11 @@
 
 
 def modules(module_cache):
+    global error_duplicates
     import os
 
+    error_duplicates = False
+
     path_list = paths()
 
     # fake module importing
@@ -117,7 +122,12 @@
             modules_stale -= {mod_name}
             mod = module_cache.get(mod_name)
             if mod:
-                if mod.__time__ != os.path.getmtime(mod_path):
+                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):
                     print("reloading addon:", mod_name, mod.__time__, os.path.getmtime(mod_path), mod_path)
                     del module_cache[mod_name]
                     mod = None

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-07-18 05:12:50 UTC (rev 38467)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-07-18 05:41:46 UTC (rev 38468)
@@ -889,6 +889,16 @@
                 return True
         return False
 
+    @staticmethod
+    def draw_error(layout, message):
+        lines = message.split("\n")
+        box = layout.box()
+        rowsub = box.row()
+        rowsub.label(lines[0])
+        rowsub.label(icon='ERROR')
+        for l in lines[1:]:
+            box.label(l)
+
     def draw(self, context):
         layout = self.layout
 
@@ -909,6 +919,14 @@
 
         col = split.column()
 
+        # set in addon_utils.modules(...)
+        if addon_utils.error_duplicates:
+            self.draw_error(col,
+                            "Multiple addons using the same name found!\n"
+                            "likely a problem with the script search path.\n"
+                            "(see console for details)",
+                            )
+
         filter = context.window_manager.addon_filter
         search = context.window_manager.addon_search.lower()
         support = context.window_manager.addon_support




More information about the Bf-blender-cvs mailing list