forked from bartvdbraak/blender
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)
This commit is contained in:
parent
96dfaa215c
commit
77c17d332d
@ -23,8 +23,9 @@ This module contains utility functions specific to blender but
|
|||||||
not assosiated with blenders internal data.
|
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 script_paths as _bpy_script_paths
|
||||||
|
from _bpy import user_resource as _user_resource
|
||||||
|
|
||||||
import bpy as _bpy
|
import bpy as _bpy
|
||||||
import os as _os
|
import os as _os
|
||||||
@ -559,3 +560,36 @@ def keyconfig_set(filepath):
|
|||||||
keyconfigs.active = kc_new
|
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
|
||||||
|
|
||||||
|
@ -55,7 +55,11 @@ class AddPresetBase():
|
|||||||
|
|
||||||
filename = self.as_filename(self.name)
|
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"
|
filepath = os.path.join(target_path, filename) + ".py"
|
||||||
|
|
||||||
|
@ -1133,23 +1133,12 @@ class WM_OT_addon_install(bpy.types.Operator):
|
|||||||
pyfile = self.filepath
|
pyfile = self.filepath
|
||||||
|
|
||||||
# dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
|
# 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:
|
if not path_addons:
|
||||||
self.report({'WARNING'}, "Failed to get addons path\n")
|
self.report({'WARNING'}, "Failed to get addons path\n")
|
||||||
return {'CANCELLED'}
|
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))
|
contents = set(os.listdir(path_addons))
|
||||||
|
|
||||||
#check to see if the file is in compressed format (.zip)
|
#check to see if the file is in compressed format (.zip)
|
||||||
|
@ -121,17 +121,7 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char bpy_user_resource_doc[] =
|
// static char bpy_user_resource_doc[] = // now in bpy/utils.py
|
||||||
".. 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 PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
@ -165,7 +155,7 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
|||||||
|
|
||||||
static PyMethodDef meth_bpy_script_paths = {"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc};
|
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_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)
|
static void bpy_import_test(const char *modname)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user