Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-06-02 18:40:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-06-02 18:40:58 +0400
commitb1a96f76dc391ae93a4bc9523d98072a1e119a2e (patch)
tree528092dea15dba81690554950b4d58a709936096
parentad25ac9e9b1414ec90a97aa5fe222e23ce6d33b7 (diff)
include the blendfile name when executing python scripts, so when using libraries you can tell where the script is stored which raises an error.
-rw-r--r--source/blender/python/generic/bpy_internal_import.c12
-rw-r--r--source/blender/python/generic/bpy_internal_import.h3
-rw-r--r--source/blender/python/intern/bpy_interface.c12
3 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index 6b79945ccd8..2f2415ee7aa 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -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 @@ void bpy_import_main_set(struct Main *maggie)
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 @@ PyObject *bpy_text_import( Text *text )
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( ) ) {
diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h
index 947e0dfc29d..37136d46c9e 100644
--- a/source/blender/python/generic/bpy_internal_import.h
+++ b/source/blender/python/generic/bpy_internal_import.h
@@ -50,6 +50,9 @@ PyObject* bpy_text_import( struct Text *text );
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[];
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 2a3f83a066b..b45d9689a0e 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -327,16 +327,17 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
}
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 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
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