]> khamidou — GitHub mirrors - imapclient.git/commitdiff
interact.py now works with both ipython 0.10 and 0.11 shell embedding
authorMenno Smits <menno@freshfoo.com>
Tue, 8 Nov 2011 21:01:53 +0000 (21:01 +0000)
committerMenno Smits <menno@freshfoo.com>
Tue, 8 Nov 2011 21:01:53 +0000 (21:01 +0000)
interact.py

index faa151bf2c27ba7251bcc114f71714b073621b18..900e5d81461b845affed7f1468a8c93811aa3556 100755 (executable)
@@ -5,7 +5,6 @@
 # Please see http://en.wikipedia.org/wiki/BSD_licenses
 
 
-import code
 from getpass import getpass
 from optparse import OptionParser
 
@@ -48,11 +47,27 @@ def command_line():
 
 if __name__ == '__main__':
     opts = command_line()
+    print 'Connecting...'
     client = create_client_from_config(opts)
+    print 'Connected.'
     banner = '\nIMAPClient instance is "c"'
-    try:
+
+    def ipython_011(c):
+        from IPython.frontend.terminal.embed import InteractiveShellEmbed
+        ipshell = InteractiveShellEmbed(banner1=banner)
+        ipshell('')
+
+    def ipython_010(c):
         from IPython.Shell import IPShellEmbed
-        c = client
         IPShellEmbed('', banner=banner)()
-    except ImportError:
-        code.interact(banner, local=dict(c=client))
+
+    def builtin(c):
+        import code
+        code.interact(banner, local=dict(c=c))
+    
+    for shell_attempt in (ipython_011, ipython_010, builtin):
+        try:
+            shell_attempt(client)
+            break
+        except ImportError:
+            pass