[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26803] trunk/blender: bpy.utils. home_paths, use this to get script paths for the user/local/ system blender paths.
Campbell Barton
ideasman42 at gmail.com
Thu Feb 11 15:08:23 CET 2010
Revision: 26803
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26803
Author: campbellbarton
Date: 2010-02-11 15:08:22 +0100 (Thu, 11 Feb 2010)
Log Message:
-----------
bpy.utils.home_paths, use this to get script paths for the user/local/system blender paths.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/utils.py
trunk/blender/source/blender/python/generic/IDProp.h
trunk/blender/source/blender/python/intern/bpy_interface.c
Added Paths:
-----------
trunk/blender/source/blender/python/intern/bpy.c
trunk/blender/source/blender/python/intern/bpy.h
Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py 2010-02-11 10:41:11 UTC (rev 26802)
+++ trunk/blender/release/scripts/modules/bpy/utils.py 2010-02-11 14:08:22 UTC (rev 26803)
@@ -27,6 +27,7 @@
import os as _os
import sys as _sys
+from _bpy import home_paths
def load_scripts(reload_scripts=False, refresh_scripts=False):
import traceback
@@ -171,17 +172,15 @@
# add user scripts dir
user_script_path = _bpy.context.user_preferences.filepaths.python_scripts_directory
+
+ for path in home_paths("scripts") + (user_script_path, ):
+ if path:
+ path = _os.path.normpath(path)
+ if path not in scripts and _os.path.isdir(path):
+ scripts.append(path)
- if not user_script_path:
- # XXX - WIN32 needs checking, perhaps better call a blender internal function.
- user_script_path = _os.path.join(_os.path.expanduser("~"), ".blender", "scripts")
-
- user_script_path = _os.path.normpath(user_script_path)
-
- if user_script_path not in scripts and _os.path.isdir(user_script_path):
- scripts.append(user_script_path)
-
if not args:
+ print(scripts)
return scripts
subdir = _os.path.join(*args)
@@ -190,7 +189,7 @@
path_subdir = _os.path.join(path, subdir)
if _os.path.isdir(path_subdir):
script_paths.append(path_subdir)
-
+ print(script_paths)
return script_paths
Modified: trunk/blender/source/blender/python/generic/IDProp.h
===================================================================
--- trunk/blender/source/blender/python/generic/IDProp.h 2010-02-11 10:41:11 UTC (rev 26802)
+++ trunk/blender/source/blender/python/generic/IDProp.h 2010-02-11 14:08:22 UTC (rev 26803)
@@ -49,14 +49,14 @@
} BPy_IDGroup_Iter;
PyObject *BPy_Wrap_IDProperty(struct ID *id, struct IDProperty *prop, struct IDProperty *parent);
-PyObject *BPy_Wrap_GetKeys(IDProperty *prop);
-PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop);
-PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop);
-int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val);
+PyObject *BPy_Wrap_GetKeys(struct IDProperty *prop);
+PyObject *BPy_Wrap_GetValues(struct ID *id, struct IDProperty *prop);
+PyObject *BPy_Wrap_GetItems(struct ID *id, struct IDProperty *prop);
+int BPy_Wrap_SetMapItem(struct IDProperty *prop, PyObject *key, PyObject *val);
-PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop );
-char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob);
+PyObject *BPy_IDGroup_WrapData(struct ID *id, struct IDProperty *prop );
+char *BPy_IDProperty_Map_ValidateAndCreate(char *name, struct IDProperty *group, PyObject *ob);
void IDProp_Init_Types(void);
Added: trunk/blender/source/blender/python/intern/bpy.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.c (rev 0)
+++ trunk/blender/source/blender/python/intern/bpy.c 2010-02-11 14:08:22 UTC (rev 26803)
@@ -0,0 +1,133 @@
+/**
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* This file defines the '_bpy' module which is used by python's 'bpy' package.
+ * a script writer should never directly access this module */
+
+#include <Python.h>
+
+#include "bpy_rna.h"
+#include "bpy_app.h"
+#include "bpy_props.h"
+#include "bpy_operator.h"
+
+#include "BLI_path_util.h"
+
+ /* external util modules */
+#include "../generic/Mathutils.h"
+#include "../generic/Geometry.h"
+#include "../generic/BGL.h"
+#include "../generic/IDProp.h"
+
+/* todo, make nice syntax for sphinx */
+static char bpy_home_paths_doc[] = "home_paths(subfolder), return 3 paths to blender home directories (system, local, user), strings will be empty when not found.";
+
+PyObject *bpy_home_paths(PyObject *self, PyObject *args)
+{
+ PyObject *ret= PyTuple_New(3);
+ char *path;
+ char *subfolder= "";
+
+ if (!PyArg_ParseTuple(args, "|s:blender_homes", &subfolder))
+ return NULL;
+
+ path= BLI_gethome_folder(subfolder, BLI_GETHOME_SYSTEM);
+ PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
+
+ path= BLI_gethome_folder(subfolder, BLI_GETHOME_LOCAL);
+ PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
+
+ path= BLI_gethome_folder(subfolder, BLI_GETHOME_USER);
+ PyTuple_SET_ITEM(ret, 2, PyUnicode_FromString(path?path:""));
+
+ return ret;
+}
+
+static PyMethodDef meth_bpy_home_paths[] = {{ "home_paths", (PyCFunction)bpy_home_paths, METH_VARARGS, bpy_home_paths_doc}};
+
+static void bpy_import_test(char *modname)
+{
+ PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
+ if(mod) {
+ Py_DECREF(mod);
+ }
+ else {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+}
+
+/*****************************************************************************
+* Description: Creates the bpy module and adds it to sys.modules for importing
+*****************************************************************************/
+void BPy_init_modules( void )
+{
+ extern BPy_StructRNA *bpy_context_module;
+ PyObject *mod;
+
+ /* Needs to be first since this dir is needed for future modules */
+ char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
+ if(modpath) {
+ PyObject *sys_path= PySys_GetObject("path"); /* borrow */
+ PyObject *py_modpath= PyUnicode_FromString(modpath);
+ PyList_Insert(sys_path, 0, py_modpath); /* add first */
+ Py_DECREF(py_modpath);
+ }
+
+ /* stand alone utility modules not related to blender directly */
+ Geometry_Init();
+ Mathutils_Init();
+ BGL_Init();
+ IDProp_Init_Types();
+
+
+ mod = PyModule_New("_bpy");
+
+ /* add the module so we can import it */
+ PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
+ Py_DECREF(mod);
+
+ /* run first, initializes rna types */
+ BPY_rna_init();
+
+ PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
+ bpy_import_test("bpy_types");
+ PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
+ bpy_import_test("bpy_types");
+ PyModule_AddObject( mod, "props", BPY_rna_props() );
+ PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
+ PyModule_AddObject( mod, "app", BPY_app_struct() );
+
+ /* bpy context */
+ bpy_context_module= ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
+ RNA_pointer_create(NULL, &RNA_Context, NULL, &bpy_context_module->ptr);
+ bpy_context_module->freeptr= 0;
+ PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
+
+ /* utility func's that have nowhere else to go */
+ PyModule_AddObject(mod, meth_bpy_home_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_home_paths, NULL));
+
+ /* add our own modules dir, this is a python package */
+ bpy_import_test("bpy");
+}
Added: trunk/blender/source/blender/python/intern/bpy.h
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.h (rev 0)
+++ trunk/blender/source/blender/python/intern/bpy.h 2010-02-11 14:08:22 UTC (rev 26803)
@@ -0,0 +1,25 @@
+/**
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK ***** */
+
+void BPy_init_modules( void );
+
\ No newline at end of file
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2010-02-11 10:41:11 UTC (rev 26802)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2010-02-11 14:08:22 UTC (rev 26803)
@@ -38,10 +38,8 @@
#include "compile.h" /* for the PyCodeObject */
#include "eval.h" /* for PyEval_EvalCode */
-#include "bpy_app.h"
+#include "bpy.h"
#include "bpy_rna.h"
-#include "bpy_props.h"
-#include "bpy_operator.h"
#include "bpy_util.h"
#ifndef WIN32
@@ -55,10 +53,10 @@
#include "MEM_guardedalloc.h"
-#include "BLI_path_util.h"
#include "BLI_storage.h"
#include "BLI_fileops.h"
#include "BLI_string.h"
+#include "BLI_path_util.h"
#include "BKE_context.h"
#include "BKE_text.h"
@@ -68,19 +66,13 @@
#include "BPY_extern.h"
#include "../generic/bpy_internal_import.h" // our own imports
-/* external util modules */
-#include "../generic/Mathutils.h"
-#include "../generic/Geometry.h"
-#include "../generic/BGL.h"
-#include "../generic/IDProp.h"
-
/* for internal use, when starting and ending python scripts */
/* incase a python script triggers another python call, stop bpy_context_clear from invalidating */
static int py_call_level= 0;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list