[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15312] branches/apricot: * fix path problems when running .py scripts through menus

Nathan Letwory jesterking at letwory.net
Sun Jun 22 21:49:49 CEST 2008


Revision: 15312
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15312
Author:   jesterking
Date:     2008-06-22 21:49:48 +0200 (Sun, 22 Jun 2008)

Log Message:
-----------
* fix path problems when running .py scripts through menus
  - \'s were not escaped, confusing execfile()
* small indentation fix in btools.py

Modified Paths:
--------------
    branches/apricot/source/blender/python/BPY_interface.c
    branches/apricot/tools/btools.py

Modified: branches/apricot/source/blender/python/BPY_interface.c
===================================================================
--- branches/apricot/source/blender/python/BPY_interface.c	2008-06-22 19:43:52 UTC (rev 15311)
+++ branches/apricot/source/blender/python/BPY_interface.c	2008-06-22 19:49:48 UTC (rev 15312)
@@ -782,14 +782,45 @@
 	}
 }
 
+#ifdef WIN32
+static char *escape_slashes(const char *s) {
+	int l= 0;
+	int i= 0;
+	int k= 0;
+	char *news= NULL;
+	char *tmp= (char *)s;
+	int slashcount= 0;
+	if(s==0) return 0;
+	l= strlen(s);
+	for(i= 0; i < l; i++) {
+		if(tmp[i]=='\\')
+			slashcount++;
+	}
+
+	if(slashcount>0) {
+		news= MEM_mallocN(slashcount+l+1, "escslashes");
+		tmp= (char *)s;
+		for(i= 0; i < l; i++) {
+			if(tmp[i]=='\\') {
+				news[i+k]='\\';
+				k++;
+			}
+			news[i+k]= tmp[i];
+		}
+		news[slashcount+l] = '\0';
+	} else {
+			news= (char *)s;
+	}
+
+	return news;
+}
+#endif
+
 int BPY_run_script(Script *script)
 {
 	PyObject *py_dict, *py_res, *pyarg;
 	Text *text = NULL;
 	BPy_constant *info;
-
-
-
 	
 	PyGILState_STATE gilstate = PyGILState_Ensure();
 	
@@ -880,10 +911,21 @@
 	if (text) {
 		py_res = RunPython( text, py_dict );
 	} else {
+#ifdef WIN32
+		/* backward slashes need to be escaped on windows, otherwise execfile() doesn't work right */
+		char *scriptname= escape_slashes(script->scriptname);
+		char pystring[sizeof(scriptname) + 14];
+		pystring[0] = '\0';
+		sprintf(pystring, "execfile('%s')", scriptname);
+#else
 		char pystring[sizeof(script->scriptname) + 14];
 		pystring[0] = '\0';
 		sprintf(pystring, "execfile('%s')", script->scriptname);
+#endif
 		py_res = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
+#ifdef WIN32
+		MEM_freeN(scriptname);
+#endif
 	}
 
 	if( !py_res ) {		/* Failed execution of the script */

Modified: branches/apricot/tools/btools.py
===================================================================
--- branches/apricot/tools/btools.py	2008-06-22 19:43:52 UTC (rev 15311)
+++ branches/apricot/tools/btools.py	2008-06-22 19:49:48 UTC (rev 15312)
@@ -51,7 +51,7 @@
             'WITH_BF_STATICOPENGL', 'BF_OPENGL', 'BF_OPENGL_INC', 'BF_OPENGL_LIB', 'BF_OPENGL_LIBPATH', 'BF_OPENGL_LIB_STATIC', 'BF_OPENGL_LINKFLAGS',
             'WITH_BF_FTGL', 'BF_FTGL', 'BF_FTGL_INC', 'BF_FTGL_LIB',
             'WITH_BF_PLAYER',
-	    'WITH_BF_GLEXT',
+            'WITH_BF_GLEXT',
             'WITH_BF_BINRELOC',	
             'CFLAGS', 'CCFLAGS', 'CPPFLAGS', 
             'REL_CFLAGS', 'REL_CCFLAGS',





More information about the Bf-blender-cvs mailing list