[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29078] trunk/blender: - Python console argument '--python-console', option so you can start blender and drop into a python console, ( useful for debugging some problems on a renderfarm over ssh)
Campbell Barton
ideasman42 at gmail.com
Sun May 30 16:05:58 CEST 2010
Revision: 29078
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29078
Author: campbellbarton
Date: 2010-05-30 16:05:58 +0200 (Sun, 30 May 2010)
Log Message:
-----------
- Python console argument '--python-console', option so you can start blender and drop into a python console, (useful for debugging some problems on a renderfarm over ssh)
- Also made it so sys.stdin isnt overwritten anymore, instead the interactive consoel overwrites while it executes and restores after.
- removed hope folder from sphinx patch path
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/__init__.py
trunk/blender/release/scripts/op/console_python.py
trunk/blender/source/blender/blenkernel/intern/fcurve.c
trunk/blender/source/blender/blenkernel/intern/fmodifier.c
trunk/blender/source/blender/editors/interface/interface.c
trunk/blender/source/blender/python/BPY_extern.h
trunk/blender/source/blender/python/doc/sphinx_html_compact.diff
trunk/blender/source/blender/python/intern/bpy_driver.c
trunk/blender/source/blender/python/intern/bpy_interface.c
trunk/blender/source/creator/creator.c
Modified: trunk/blender/release/scripts/modules/bpy/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/__init__.py 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/release/scripts/modules/bpy/__init__.py 2010-05-30 14:05:58 UTC (rev 29078)
@@ -43,17 +43,11 @@
## people need to explain how this is even a fix.
# _sys.path[:] = filter(None, _sys.path)
- # a bit nasty but this prevents help() and input() from locking blender
- # Ideally we could have some way for the console to replace sys.stdin but
- # python would lock blender while waiting for a return value, not easy :|
-
- if not app.debug:
- _sys.stdin = None
-
# because of how the console works. we need our own help() pager func.
# replace the bold function because it adds crazy chars
import pydoc
pydoc.getpager = lambda: pydoc.plainpager
+ pydoc.Helper.getline = lambda self, prompt: None
pydoc.TextDoc.bold = lambda self, text: text
Modified: trunk/blender/release/scripts/op/console_python.py
===================================================================
--- trunk/blender/release/scripts/op/console_python.py 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/release/scripts/op/console_python.py 2010-05-30 14:05:58 UTC (rev 29078)
@@ -102,6 +102,10 @@
sys.stdout = stdout
sys.stderr = stderr
+ # dont allow the stdin to be used, can lock blender.
+ stdin_backup = sys.stdin
+ sys.stdin = None
+
# run the console
if not line.strip():
line_exec = '\n' # executes a multiline statement
@@ -144,6 +148,9 @@
if output_err:
add_scrollback(output_err, 'ERROR')
+ # restore the stdin
+ sys.stdin = stdin_backup
+
return {'FINISHED'}
@@ -163,6 +170,11 @@
if sc.console_type != 'PYTHON':
return {'CANCELLED'}
+ # dont allow the stdin to be used, can lock blender.
+ # note: unlikely stdin would be used for autocomp. but its possible.
+ stdin_backup = sys.stdin
+ sys.stdin = None
+
# This function isnt aware of the text editor or being an operator
# just does the autocomp then copy its results back
current_line.line, current_line.current_character, scrollback = \
@@ -182,6 +194,9 @@
if scrollback:
add_scrollback(scrollback, 'INFO')
+ # restore the stdin
+ sys.stdin = stdin_backup
+
context.area.tag_redraw()
return {'FINISHED'}
Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -1418,7 +1418,7 @@
/* this evaluates the expression using Python,and returns its result:
* - on errors it reports, then returns 0.0f
*/
- driver->curval= BPY_pydriver_eval(driver);
+ driver->curval= BPY_eval_driver(driver);
}
#endif /* DISABLE_PYTHON*/
}
Modified: trunk/blender/source/blender/blenkernel/intern/fmodifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fmodifier.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/blenkernel/intern/fmodifier.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -44,7 +44,7 @@
#include "BKE_utildefines.h"
#ifndef DISABLE_PYTHON
-#include "BPY_extern.h" /* for BPY_pydriver_eval() */
+#include "BPY_extern.h" /* for BPY_eval_driver() */
#endif
#define SMALL -1.0e-10
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/editors/interface/interface.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -1633,7 +1633,7 @@
bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type);
}
- if(BPY_button_eval(C, str_unit_convert, &value)) {
+ if(BPY_eval_button(C, str_unit_convert, &value)) {
value = ui_get_but_val(but); /* use its original value */
if(str[0])
Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/python/BPY_extern.h 2010-05-30 14:05:58 UTC (rev 29078)
@@ -119,10 +119,12 @@
// short eventValue, unsigned short space_event);
//
// void BPY_pydriver_update(void);
- float BPY_pydriver_eval(struct ChannelDriver *driver);
+ float BPY_eval_driver(struct ChannelDriver *driver);
//
- int BPY_button_eval(struct bContext *C, char *expr, double *value);
+ int BPY_eval_button(struct bContext *C, const char *expr, double *value);
+ int BPY_eval_string(struct bContext *C, const char *expr);
+
/* format importer hook */
int BPY_call_importloader( char *name );
//
Modified: trunk/blender/source/blender/python/doc/sphinx_html_compact.diff
===================================================================
--- trunk/blender/source/blender/python/doc/sphinx_html_compact.diff 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/python/doc/sphinx_html_compact.diff 2010-05-30 14:05:58 UTC (rev 29078)
@@ -1,5 +1,5 @@
---- /home/sashka/Sphinx-0.6.5-py2.6.egg_FILES/sphinx/writers/html.py 2010-01-02 00:43:38.000000000 +0200
-+++ /home/sashka/egg/lib/python2.6/site-packages/Sphinx-0.6.5-py2.6.egg/sphinx/writers/html.py 2010-05-27 02:24:33.203418028 +0300
+--- Sphinx-0.6.5-py2.6.egg_FILES/sphinx/writers/html.py 2010-01-02 00:43:38.000000000 +0200
++++ Sphinx-0.6.5-py2.6.egg_FILES/sphinx/writers/html.py 2010-05-27 02:24:33.203418028 +0300
@@ -16,6 +16,7 @@
from docutils import nodes
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
Modified: trunk/blender/source/blender/python/intern/bpy_driver.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_driver.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/python/intern/bpy_driver.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -103,7 +103,7 @@
}
/* Update function, it gets rid of pydrivers global dictionary, forcing
- * BPY_pydriver_eval to recreate it. This function is used to force
+ * BPY_eval_driver to recreate it. This function is used to force
* reloading the Blender text module "pydrivers.py", if available, so
* updates in it reach pydriver evaluation.
*/
@@ -153,7 +153,7 @@
* bake operator which intern starts a thread which calls scene update which
* does a driver update. to avoid a deadlock check PyThreadState_Get() if PyGILState_Ensure() is needed.
*/
-float BPY_pydriver_eval (ChannelDriver *driver)
+float BPY_eval_driver (ChannelDriver *driver)
{
PyObject *driver_vars=NULL;
PyObject *retval= NULL;
@@ -246,11 +246,11 @@
/* this target failed - bad name */
if (targets_ok) {
/* first one - print some extra info for easier identification */
- fprintf(stderr, "\nBPY_pydriver_eval() - Error while evaluating PyDriver:\n");
+ fprintf(stderr, "\nBPY_eval_driver() - Error while evaluating PyDriver:\n");
targets_ok= 0;
}
- fprintf(stderr, "\tBPY_pydriver_eval() - couldn't add variable '%s' to namespace\n", dvar->name);
+ fprintf(stderr, "\tBPY_eval_driver() - couldn't add variable '%s' to namespace\n", dvar->name);
// BPy_errors_to_report(NULL); // TODO - reports
PyErr_Print();
PyErr_Clear();
@@ -290,7 +290,7 @@
return (float)result;
}
else {
- fprintf(stderr, "\tBPY_pydriver_eval() - driver '%s' evaluates to '%f'\n", dvar->name, result);
+ fprintf(stderr, "\tBPY_eval_driver() - driver '%s' evaluates to '%f'\n", dvar->name, result);
return 0.0f;
}
}
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -528,7 +528,7 @@
#endif
-int BPY_button_eval(bContext *C, char *expr, double *value)
+int BPY_eval_button(bContext *C, const char *expr, double *value)
{
PyGILState_STATE gilstate;
PyObject *dict, *mod, *retval;
@@ -599,6 +599,40 @@
return error_ret;
}
+int BPY_eval_string(bContext *C, const char *expr)
+{
+ PyGILState_STATE gilstate;
+ PyObject *dict, *retval;
+ int error_ret = 0;
+
+ if (!expr) return -1;
+
+ if(expr[0]=='\0') {
+ return error_ret;
+ }
+
+ bpy_context_set(C, &gilstate);
+
+ dict= CreateGlobalDictionary(C, NULL);
+
+ retval = PyRun_String(expr, Py_eval_input, dict, dict);
+
+ if (retval == NULL) {
+ error_ret= -1;
+
+ BPy_errors_to_report(CTX_wm_reports(C));
+ }
+ else {
+ Py_DECREF(retval);
+ }
+
+ Py_DECREF(dict);
+ bpy_context_clear(C, &gilstate);
+
+ return error_ret;
+}
+
+
void BPY_load_user_modules(bContext *C)
{
PyGILState_STATE gilstate;
Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c 2010-05-30 14:05:24 UTC (rev 29077)
+++ trunk/blender/source/creator/creator.c 2010-05-30 14:05:58 UTC (rev 29078)
@@ -261,6 +261,7 @@
printf("\n");
BLI_argsPrintArgDoc(ba, "--python");
+ BLI_argsPrintArgDoc(ba, "--python-console");
#ifdef WIN32
BLI_argsPrintArgDoc(ba, "-R");
@@ -789,37 +790,41 @@
}
}
+/* macro for ugly context setup/reset */
+#ifndef DISABLE_PYTHON
+#define BPY_CTX_SETUP(_cmd) \
+{ \
+ wmWindowManager *wm= CTX_wm_manager(C); \
+ wmWindow *prevwin= CTX_wm_window(C); \
+ Scene *prevscene= CTX_data_scene(C); \
+ if(wm->windows.first) { \
+ CTX_wm_window_set(C, wm->windows.first); \
+ _cmd; \
+ CTX_wm_window_set(C, prevwin); \
+ } \
+ else { \
+ fprintf(stderr, "Python script \"%s\" running with missing context data.\n", argv[1]); \
+ _cmd; \
+ } \
+ CTX_data_scene_set(C, prevscene); \
+} \
+
+#endif /* DISABLE_PYTHON */
+
static int run_python(int argc, char **argv, void *data)
{
#ifndef DISABLE_PYTHON
bContext *C = data;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list