add support for installing addons to custom script path [#26751] installing addon to custom script directory doesn't work

This commit is contained in:
Campbell Barton 2011-04-05 09:33:28 +00:00
parent 1f45f5c15d
commit 165a40e742

@ -21,7 +21,7 @@ import bpy
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 @@ class WM_OT_addon_install(bpy.types.Operator):
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 @@ class WM_OT_addon_install(bpy.types.Operator):
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!