[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29159] trunk/blender/source/blender/ python: include the blendfile name when executing python scripts, so when using libraries you can tell where the script is stored which raises an error .
Campbell Barton
ideasman42 at gmail.com
Wed Jun 2 16:40:58 CEST 2010
Revision: 29159
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29159
Author: campbellbarton
Date: 2010-06-02 16:40:58 +0200 (Wed, 02 Jun 2010)
Log Message:
-----------
include the blendfile name when executing python scripts, so when using libraries you can tell where the script is stored which raises an error.
Modified Paths:
--------------
trunk/blender/source/blender/python/generic/bpy_internal_import.c
trunk/blender/source/blender/python/generic/bpy_internal_import.h
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.c 2010-06-02 13:41:05 UTC (rev 29158)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.c 2010-06-02 14:40:58 UTC (rev 29159)
@@ -32,6 +32,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h"
+#include "BKE_global.h" /* grr, only for G.sce */
#include "BLI_listbase.h"
#include <stddef.h>
@@ -55,6 +56,12 @@
bpy_import_main= maggie;
}
+/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
+void bpy_text_filename_get(char *fn, Text *text)
+{
+ sprintf(fn, "%s/%s", text->id.lib ? text->id.lib->filename : G.sce, text->id.name+2);
+}
+
PyObject *bpy_text_import( Text *text )
{
char *buf = NULL;
@@ -62,8 +69,11 @@
int len;
if( !text->compiled ) {
+ char fn_dummy[256];
+ bpy_text_filename_get(fn_dummy, text);
+
buf = txt_to_buf( text );
- text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
+ text->compiled = Py_CompileString( buf, fn_dummy, Py_file_input );
MEM_freeN( buf );
if( PyErr_Occurred( ) ) {
Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.h
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.h 2010-06-02 13:41:05 UTC (rev 29158)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.h 2010-06-02 14:40:58 UTC (rev 29159)
@@ -50,6 +50,9 @@
PyObject* bpy_text_import_name( char *name, int *found );
PyObject* bpy_text_reimport( PyObject *module, int *found );
/* void bpy_text_clear_modules( int clear_all );*/ /* Clear user modules */
+
+void bpy_text_filename_get(char *fn, struct Text *text);
+
extern PyMethodDef bpy_import_meth[];
extern PyMethodDef bpy_reload_meth[];
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2010-06-02 13:41:05 UTC (rev 29158)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2010-06-02 14:40:58 UTC (rev 29159)
@@ -327,16 +327,17 @@
}
bpy_context_set(C, &gilstate);
-
- py_dict = CreateGlobalDictionary(C, text?text->id.name+2:fn);
if (text) {
+ char fn_dummy[FILE_MAXDIR];
+ bpy_text_filename_get(fn_dummy, text);
+ py_dict = CreateGlobalDictionary(C, fn_dummy);
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
char *buf = txt_to_buf( text );
text->compiled =
- Py_CompileString( buf, text->id.name+2, Py_file_input );
+ Py_CompileString( buf, fn_dummy, Py_file_input );
MEM_freeN( buf );
@@ -347,7 +348,10 @@
if(text->compiled)
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
- } else {
+ }
+ else {
+ py_dict = CreateGlobalDictionary(C, fn);
+
FILE *fp= fopen(fn, "r");
if(fp) {
#ifdef _WIN32
More information about the Bf-blender-cvs
mailing list