summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2013-02-10 13:23:58 +0100
committerAndreas Sandberg <andreas@sandberg.pp.se>2013-02-10 13:23:58 +0100
commitd4eca0591d28cd34448148302cb26872bfc1f919 (patch)
tree80daa3a8779097cc6d652b8a3c0cfc60d0f6e75f /src
parent7c6bc52bf53f3c424a1a3a12157750c2ca9a17ca (diff)
downloadgem5-d4eca0591d28cd34448148302cb26872bfc1f919.tar.xz
base: Add support for newer versions of IPython
IPython is used for the interactive gem5 shell if it exists. IPython made API changes in version 0.11. This patch adds support for IPython version 0.11 and above. --HG-- extra : rebase_source : 5388d0919adb58d97f49a1a637db48cba61283a3
Diffstat (limited to 'src')
-rw-r--r--src/python/m5/main.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/python/m5/main.py b/src/python/m5/main.py
index 03fab9901..a02d43335 100644
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -129,11 +129,40 @@ def parse_options():
def interact(scope):
banner = "gem5 Interactive Console"
+
+ ipshell = None
+ prompt_in1 = "gem5 \\#> "
+ prompt_out = "gem5 \\#: "
+
+ # Is IPython version 0.10 or earlier available?
try:
from IPython.Shell import IPShellEmbed
- ipshell = IPShellEmbed(argv=[], banner=banner, user_ns=scope)
- ipshell()
+ ipshell = IPShellEmbed(argv=["-prompt_in1", prompt_in1,
+ "-prompt_out", prompt_out],
+ banner=banner, user_ns=scope)
except ImportError:
+ pass
+
+ # Is IPython version 0.11 or later available?
+ if not ipshell:
+ try:
+ import IPython
+ from IPython.config.loader import Config
+ from IPython.frontend.terminal.embed import InteractiveShellEmbed
+
+ cfg = Config()
+ cfg.PromptManager.in_template = prompt_in1
+ cfg.PromptManager.out_template = prompt_out
+ ipshell = InteractiveShellEmbed(config=cfg, user_ns=scope,
+ banner1=banner)
+ except ImportError:
+ pass
+
+ if ipshell:
+ ipshell()
+ else:
+ # Use the Python shell in the standard library if IPython
+ # isn't available.
code.InteractiveConsole(scope).interact(banner)
def main(*args):