[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39117] trunk/blender/release/scripts: fix [#28172] Cannot restore Add-ons tab in user preferences after a failed attempt to install an add-on .

Campbell Barton ideasman42 at gmail.com
Sun Aug 7 06:55:58 CEST 2011


Revision: 39117
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39117
Author:   campbellbarton
Date:     2011-08-07 04:55:58 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
fix [#28172] Cannot restore Add-ons tab in user preferences after a failed attempt to install an add-on.

non utf8 addons would make the addon UI vanish, now give a message in the console and UI.

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-08-07 04:22:33 UTC (rev 39116)
+++ trunk/blender/release/scripts/modules/addon_utils.py	2011-08-07 04:55:58 UTC (rev 39117)
@@ -32,6 +32,7 @@
 
 
 error_duplicates = False
+error_encoding = False
 
 
 def paths():
@@ -51,14 +52,18 @@
 
 def modules(module_cache):
     global error_duplicates
+    global error_encoding
     import os
 
     error_duplicates = False
+    error_encoding = False
 
     path_list = paths()
 
     # fake module importing
     def fake_module(mod_name, mod_path, speedy=True):
+        global error_encoding
+
         if _bpy.app.debug:
             print("fake_module", mod_path, mod_name)
         import ast
@@ -69,12 +74,28 @@
             line_iter = iter(file_mod)
             l = ""
             while not l.startswith("bl_info"):
-                l = line_iter.readline()
+                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
+
                 if len(l) == 0:
                     break
             while l.rstrip():
                 lines.append(l)
-                l = line_iter.readline()
+                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
+
             data = "".join(lines)
 
         else:

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-08-07 04:22:33 UTC (rev 39116)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-08-07 04:55:58 UTC (rev 39117)
@@ -949,6 +949,12 @@
                             "(see console for details)",
                             )
 
+        if addon_utils.error_encoding:
+            self.draw_error(col,
+                            "One or more addons do not have UTF-8 encoding\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