[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35017] trunk/blender/release/scripts/ui/ space_userpref.py: fix [#26093] Install Add-On Fails and deletes script

Campbell Barton ideasman42 at gmail.com
Mon Feb 21 08:34:00 CET 2011


Revision: 35017
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35017
Author:   campbellbarton
Date:     2011-02-21 07:33:59 +0000 (Mon, 21 Feb 2011)
Log Message:
-----------
fix [#26093] Install Add-On Fails and deletes script
problem was on installing a file which was already installed, when the source and target paths match python deleted the file.

now check if the selected file is inside any of the addon search paths and abort with an error.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_userpref.py

Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py	2011-02-21 07:25:24 UTC (rev 35016)
+++ trunk/blender/release/scripts/ui/space_userpref.py	2011-02-21 07:33:59 UTC (rev 35017)
@@ -22,7 +22,9 @@
 import shutil
 import addon_utils
 
+from bpy.props import StringProperty, BoolProperty, EnumProperty
 
+
 def ui_items_general(col, context):
     """ General UI Theme Settings (User Interface)
     """
@@ -878,8 +880,8 @@
         cats.discard("")
 
         if USERPREF_PT_addons._addons_cats != cats:
-            bpy.types.WindowManager.addon_filter = bpy.props.EnumProperty(items=[(cat, cat, "") for cat in ["All", "Enabled", "Disabled"] + sorted(cats)], name="Category", description="Filter add-ons by category")
-            bpy.types.WindowManager.addon_search = bpy.props.StringProperty(name="Search", description="Search within the selected filter")
+            bpy.types.WindowManager.addon_filter = EnumProperty(items=[(cat, cat, "") for cat in ["All", "Enabled", "Disabled"] + sorted(cats)], name="Category", description="Filter add-ons by category")
+            bpy.types.WindowManager.addon_search = StringProperty(name="Search", description="Search within the selected filter")
             USERPREF_PT_addons._addons_cats = cats
 
         sups_default = {'OFFICIAL', 'COMMUNITY'}
@@ -887,7 +889,7 @@
         sups.discard("")
 
         if USERPREF_PT_addons._addons_sups != sups:
-            bpy.types.WindowManager.addon_support = bpy.props.EnumProperty(items=[(sup, sup.title(), "") for  sup in reversed(sorted(sups))], name="Support", description="Display support level", default=sups_default, options={'ENUM_FLAG'})
+            bpy.types.WindowManager.addon_support = EnumProperty(items=[(sup, sup.title(), "") for  sup in reversed(sorted(sups))], name="Support", description="Display support level", default=sups_default, options={'ENUM_FLAG'})
             USERPREF_PT_addons._addons_sups = sups
 
         split = layout.split(percentage=0.2)
@@ -1010,8 +1012,6 @@
                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
 
 
-from bpy.props import *
-
 class WM_OT_addon_enable(bpy.types.Operator):
     "Enable an addon"
     bl_idname = "wm.addon_enable"
@@ -1079,9 +1079,22 @@
         path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
 
         if not path_addons:
-            self.report({'WARNING'}, "Failed to get addons path")
+            self.report({'ERROR'}, "Failed to get addons path")
             return {'CANCELLED'}
 
+        # Check if we are installing from a target path,
+        # doing so causes 2+ addons of same name or when the same from/to
+        # location is used, removal of the file!
+        addon_path = ""
+        pyfile_dir = os.path.dirname(pyfile)
+        for addon_path in addon_utils.paths():
+            if os.path.samefile(pyfile_dir, addon_path):
+                self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
+                return {'CANCELLED'}
+        del addon_path
+        del pyfile_dir
+        # done checking for exceptional case
+
         contents = set(os.listdir(path_addons))
 
         #check to see if the file is in compressed format (.zip)
@@ -1108,7 +1121,7 @@
                 traceback.print_exc()
                 return {'CANCELLED'}
 
-        else:            
+        else:
             path_dest = os.path.join(path_addons, os.path.basename(pyfile))
 
             if self.overwrite:




More information about the Bf-blender-cvs mailing list