From 899213ecbc7182217f6796debc1eb07d109bab72 2011-10-24 04:51:17 From: MinRK Date: 2011-10-24 04:51:17 Subject: [PATCH] update %connect_info magic to cover non-default cases print profile flag for non-default profile, and fullpath for JSON files outside the security dir. --- diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index 5c7d1c9..942ea43 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -518,22 +518,42 @@ class ZMQInteractiveShell(InteractiveShell): $> ipython --existing """ + + from IPython.core.application import BaseIPythonApplication as BaseIPApp + + if BaseIPApp.initialized(): + app = BaseIPApp.instance() + security_dir = app.profile_dir.security_dir + profile = app.profile + else: + profile = 'default' + security_dir = '' + try: connection_file = get_connection_file() info = get_connection_info(unpack=False) except Exception as e: error("Could not get connection info: %r" % e) return - + + # add profile flag for non-default profile + profile_flag = "--profile %s" % profile if profile != 'default' else "" + + # if it's in the security dir, truncate to basename + if security_dir == os.path.dirname(connection_file): + connection_file = os.path.basename(connection_file) + + print (info + '\n') print ("Paste the above JSON into a file, and connect with:\n" " $> ipython --existing \n" "or, if you are local, you can connect with just:\n" - " $> ipython --existing %s\n" + " $> ipython --existing {0} {1}\n" "or even just:\n" - " $> ipython --existing\n" - "if this is the most recent IPython session you have started." - % os.path.basename(connection_file) + " $> ipython --existing {1}\n" + "if this is the most recent IPython session you have started.".format( + connection_file, profile_flag + ) ) def magic_qtconsole(self, arg_s):