diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-18 10:22:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-18 10:22:52 +0300 |
commit | 77c17d332d5afd0d5df5e31af2e7d2c8c31a8fe7 (patch) | |
tree | 5b42ed9d09f1ce800ed5e33a71ae7546dbeab52f /release | |
parent | 96dfaa215c87cbbb4676d19b1f278997a52d47a1 (diff) |
fix [#25262] Keyboard shortcut presets can't be made because of wrong folder
New create option when getting a user resource for creating paths.
bpy.utils.user_resource(type, path, create=False)
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 36 | ||||
-rw-r--r-- | release/scripts/op/presets.py | 8 | ||||
-rw-r--r-- | release/scripts/ui/space_userpref.py | 13 |
3 files changed, 42 insertions, 15 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 1643b2036fd..624f111d85f 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -23,8 +23,9 @@ This module contains utility functions specific to blender but not assosiated with blenders internal data. """ -from _bpy import blend_paths, user_resource +from _bpy import blend_paths from _bpy import script_paths as _bpy_script_paths +from _bpy import user_resource as _user_resource import bpy as _bpy import os as _os @@ -559,3 +560,36 @@ def keyconfig_set(filepath): keyconfigs.active = kc_new +def user_resource(type, path, create=False): + """ + Return a user resource path (normally from the users home directory). + + :arg type: Resource type in ['DATAFILES', 'CONFIG', 'SCRIPTS', 'AUTOSAVE']. + :type type: string + :arg subdir: Optional subdirectory. + :type subdir: string + :arg create: Treat the path as a directory and create it if its not existing. + :type create: boolean + :return: a path. + :rtype: string + """ + + target_path = _user_resource(type, path) + + if create: + # should always be true. + if target_path: + # create path if not existing. + if not _os.path.exists(target_path): + try: + _os.makedirs(target_path) + except: + import traceback + traceback.print_exc() + target_path = "" + elif not _os.path.isdir(target_path): + print("Path %r found but isn't a directory!" % path) + target_path = "" + + return target_path + diff --git a/release/scripts/op/presets.py b/release/scripts/op/presets.py index 3a78f15d770..0ee20966fad 100644 --- a/release/scripts/op/presets.py +++ b/release/scripts/op/presets.py @@ -49,13 +49,17 @@ class AddPresetBase(): preset_menu_class = getattr(bpy.types, self.preset_menu) if not self.remove_active: - + if not self.name: return {'FINISHED'} filename = self.as_filename(self.name) - target_path = bpy.utils.preset_paths(self.preset_subdir)[0] # we need some way to tell the user and system preset path + target_path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", self.preset_subdir), create=True) + + if not target_path: + self.report({'WARNING'}, "Failed to create presets path") + return {'CANCELLED'} filepath = os.path.join(target_path, filename) + ".py" diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 3f9e0cd83bb..39700016526 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -1133,23 +1133,12 @@ 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') + path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True) - # should never happen. if not path_addons: self.report({'WARNING'}, "Failed to get addons path\n") return {'CANCELLED'} - # create path if not existing. - if not os.path.exists(path_addons): - try: - os.makedirs(path_addons) - except: - self.report({'WARNING'}, "Failed to create %r\n" % path_addons) - - traceback.print_exc() - return {'CANCELLED'} - contents = set(os.listdir(path_addons)) #check to see if the file is in compressed format (.zip) |