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-07-29 03:24:17 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-07-29 03:24:17 +0400
commitfe77e6d91901e34d50b4f692593ad77ec6507ce7 (patch)
treea438847e53144a2b707e56b9f0206a4310adaa5e /release
parent3e387b8c42d9e3f7e6f9c946118b50099b9cb967 (diff)
minor changes to r30843
- the __main__ modules namespace was initialized cleanly but left dirty, now restore when finished executing a script incase a module uses this later. - made the interactive console use the __main__ modules namespace.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/op/console_python.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/release/scripts/op/console_python.py b/release/scripts/op/console_python.py
index cabc741c701..3c6e52e28cd 100644
--- a/release/scripts/op/console_python.py
+++ b/release/scripts/op/console_python.py
@@ -22,6 +22,9 @@ import bpy
language_id = 'python'
+# store our own __main__ module, not 100% needed
+# but python expects this in some places
+_BPY_MAIN_OWN = True
def add_scrollback(text, text_type):
for l in text.split('\n'):
@@ -63,12 +66,25 @@ def get_console(console_id):
# XXX, bug in python 3.1.2 ? (worked in 3.1.1)
# seems there is no way to clear StringIO objects for writing, have to make new ones each time.
- import io
- stdout = io.StringIO()
- stderr = io.StringIO()
+ # import io
+ # stdout = io.StringIO()
+ # stderr = io.StringIO()
else:
- namespace = {"__builtins__": __builtins__, "bpy": bpy, "C": bpy.context}
+ if _BPY_MAIN_OWN:
+ import types
+ bpy_main_mod = types.ModuleType("__main__")
+ namespace = bpy_main_mod.__dict__
+ else:
+ namespace = {}
+
+ namespace["__builtins__"] = sys.modules["builtins"]
+ namespace["bpy"] = bpy
+ namespace["C"] = bpy.context
+
console = InteractiveConsole(locals=namespace, filename="<blender_console>")
+
+ if _BPY_MAIN_OWN:
+ console._bpy_main_mod = bpy_main_mod
import io
stdout = io.StringIO()
@@ -105,6 +121,10 @@ def execute(context):
stdin_backup = sys.stdin
sys.stdin = None
+ if _BPY_MAIN_OWN:
+ main_mod_back = sys.modules["__main__"]
+ sys.modules["__main__"] = console._bpy_main_mod
+
# incase exception happens
line = "" # incase of encodingf error
is_multiline = False
@@ -121,6 +141,8 @@ def execute(context):
import traceback
stderr.write(traceback.format_exc())
+ if _BPY_MAIN_OWN:
+ sys.modules["__main__"] = main_mod_back
stdout.seek(0)
stderr.seek(0)