[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36019] trunk/blender/release/scripts/ startup/bl_ui/space_userpref.py: add support for installing addons to custom script path [#26751] installing addon to custom script directory doesn't work

Campbell Barton ideasman42 at gmail.com
Tue Apr 5 11:33:29 CEST 2011


Revision: 36019
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36019
Author:   campbellbarton
Date:     2011-04-05 09:33:28 +0000 (Tue, 05 Apr 2011)
Log Message:
-----------
add support for installing addons to custom script path [#26751] installing addon to custom script directory doesn't work

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

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-04-05 08:54:13 UTC (rev 36018)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-04-05 09:33:28 UTC (rev 36019)
@@ -21,7 +21,7 @@
 import os
 import addon_utils
 
-from bpy.props import StringProperty, BoolProperty
+from bpy.props import StringProperty, BoolProperty, EnumProperty
 
 
 def ui_items_general(col, context):
@@ -1044,6 +1044,10 @@
     bl_label = "Install Add-On..."
 
     overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True)
+    target = EnumProperty(
+            name="Target Path",
+            items=(('DEFAULT', "Default", ""),
+                   ('PREFS', "User Prefs", "")))
 
     filepath = StringProperty(name="File Path", description="File path to write file to")
     filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
@@ -1070,13 +1074,22 @@
 
         pyfile = self.filepath
 
-        # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
-        path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
+        if self.target == 'DEFAULT':
+            # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
+            path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
+        else:
+            path_addons = bpy.context.user_preferences.filepaths.script_directory
+            if path_addons:
+                path_addons = os.path.join(path_addons, "addons")
 
         if not path_addons:
             self.report({'ERROR'}, "Failed to get addons path")
             return {'CANCELLED'}
 
+        # create dir is if missing.
+        if not os.path.exists(path_addons):
+            os.makedirs(path_addons)
+
         # 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!




More information about the Bf-blender-cvs mailing list