[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33760] trunk/blender: fix [#25262] Keyboard shortcut presets can't be made because of wrong folder
Campbell Barton
ideasman42 at gmail.com
Sat Dec 18 08:22:54 CET 2010
Revision: 33760
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33760
Author: campbellbarton
Date: 2010-12-18 08:22:52 +0100 (Sat, 18 Dec 2010)
Log Message:
-----------
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)
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/utils.py
trunk/blender/release/scripts/op/presets.py
trunk/blender/release/scripts/ui/space_userpref.py
trunk/blender/source/blender/python/intern/bpy.c
Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py 2010-12-17 22:25:47 UTC (rev 33759)
+++ trunk/blender/release/scripts/modules/bpy/utils.py 2010-12-18 07:22:52 UTC (rev 33760)
@@ -23,8 +23,9 @@
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 @@
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
+
Modified: trunk/blender/release/scripts/op/presets.py
===================================================================
--- trunk/blender/release/scripts/op/presets.py 2010-12-17 22:25:47 UTC (rev 33759)
+++ trunk/blender/release/scripts/op/presets.py 2010-12-18 07:22:52 UTC (rev 33760)
@@ -49,14 +49,18 @@
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"
if hasattr(self, "add"):
Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py 2010-12-17 22:25:47 UTC (rev 33759)
+++ trunk/blender/release/scripts/ui/space_userpref.py 2010-12-18 07:22:52 UTC (rev 33760)
@@ -1133,23 +1133,12 @@
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)
Modified: trunk/blender/source/blender/python/intern/bpy.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.c 2010-12-17 22:25:47 UTC (rev 33759)
+++ trunk/blender/source/blender/python/intern/bpy.c 2010-12-18 07:22:52 UTC (rev 33760)
@@ -121,17 +121,7 @@
}
-static char bpy_user_resource_doc[] =
-".. function:: user_resource(type, subdir)\n"
-"\n"
-" Returns a list of paths to external files referenced by the loaded .blend file.\n"
-"\n"
-" :arg type: Resource type in ['DATAFILES', 'CONFIG', 'SCRIPTS', 'AUTOSAVE'].\n"
-" :type type: string\n"
-" :arg subdir: Optional subdirectory.\n"
-" :type subdir: string\n"
-" :return: a path.\n"
-" :rtype: string\n";
+// static char bpy_user_resource_doc[] = // now in bpy/utils.py
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
char *type;
@@ -165,7 +155,7 @@
static PyMethodDef meth_bpy_script_paths = {"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc};
static PyMethodDef meth_bpy_blend_paths = {"blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc};
-static PyMethodDef meth_bpy_user_resource = {"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, bpy_user_resource_doc};
+static PyMethodDef meth_bpy_user_resource = {"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, NULL};
static void bpy_import_test(const char *modname)
{
More information about the Bf-blender-cvs
mailing list