[cli/enh] on 'shell' or migration command, use ipython if available
authorLaurent Peuch <cortex@worlddomination.be>
Thu, 21 Mar 2019 14:28:30 +0100
changeset 12520 c53f66bcc641
parent 12519 aff5d3498f68
child 12521 cb68c985ee01
[cli/enh] on 'shell' or migration command, use ipython if available
cubicweb/migration.py
--- a/cubicweb/migration.py	Tue Mar 19 13:17:47 2019 +0100
+++ b/cubicweb/migration.py	Thu Mar 21 14:28:30 2019 +0100
@@ -18,8 +18,6 @@
 """utilities for instances migration"""
 from __future__ import print_function
 
-
-
 import sys
 import os
 import logging
@@ -268,11 +266,20 @@
         banner = """entering the migration python shell
 just type migration commands or arbitrary python code and type ENTER to execute it
 type "exit" or Ctrl-D to quit the shell and resume operation"""
-        interact(banner, local=local_ctx)
+
+        # use ipython if available
         try:
-            readline.write_history_file(histfile)
-        except IOError:
-            pass
+            from IPython import start_ipython
+            print(banner)
+            start_ipython(argv=[], user_ns=local_ctx)
+        except ImportError:
+            interact(banner, local=local_ctx)
+
+            try:
+                readline.write_history_file(histfile)
+            except IOError:
+                pass
+
         # delete instance's confirm attribute to avoid questions
         del self.confirm
         self.need_wrap = True