def connect_info(self, arg_s):
     """Print information for connecting other clients to this kernel
     
     It will print the contents of this session's connection file, as well as
     shortcuts for local clients.
     
     In the simplest case, when called from the most recently launched kernel,
     secondary clients can be connected, simply with:
     
     $> ipython <app> --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 <app> --existing <file>\n"
         "or, if you are local, you can connect with just:\n"
         "    $> ipython <app> --existing {0} {1}\n"
         "or even just:\n"
         "    $> ipython <app> --existing {1}\n"
         "if this is the most recent IPython session you have started.".format(
         connection_file, profile_flag
         )
     )
Beispiel #2
0
 def connect_info(self, arg_s):
     """Print information for connecting other clients to this kernel
     
     It will print the contents of this session's connection file, as well as
     shortcuts for local clients.
     
     In the simplest case, when called from the most recently launched kernel,
     secondary clients can be connected, simply with:
     
     $> ipython <app> --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 <app> --existing <file>\n"
         "or, if you are local, you can connect with just:\n"
         "    $> ipython <app> --existing {0} {1}\n"
         "or even just:\n"
         "    $> ipython <app> --existing {1}\n"
         "if this is the most recent IPython session you have started.".format(
         connection_file, profile_flag
         )
     )
Beispiel #3
0
    def _handle_magics(self, magic_code, code):
        """
        Handle cell magics
        """
        _exec_status = False
        _content = None
        err_content = None
        if(magic_code == 'connect_info'):
            try:
                connection_file = get_connection_file()
                _content = get_connection_info(unpack=False)
            except Exception as e:
                error("Could not get connection info: %r" % e)
                return

        if(magic_code == 'history'):
            _args = re.search(r'^%(\S+)(?:\s*)(\d*)', code)
            self._shell.run_raw('history(' + _args.group(2) + ')')
            _content = self._shell.output[:-1]

        if(magic_code == 'help'):
            _args = re.search(r'^%(\S+)(?:\s*)(\S*)', code)
            _content = self._shell.get_info(_args.group(2))

        if(magic_code == 'image'):
            _args = re.search(r'^%(\S+)(?:\s*)(\S+)', code)
            if _args is not None:
                return self._show_image_inline(_args.group(2))

        if(magic_code == 'flush'):
            self._shell.flush()
            _content = ''

        if(_content is not None):
            execute_content = {'execution_count': self.execution_count,
                               'data': {'text/plain': _content},
                               'metadata': {}}
            self.send_response(self.iopub_socket, 'execute_result',
                               execute_content)
            _exec_status = True
        else:
            err_content = {'execution_count': self.execution_count,
                           'ename': str('CellMagicError'),
                           'evalue': str(1),
                           'traceback': ['Invalid cell magic']}
            self.send_response(self.iopub_socket, 'error', err_content)

        return _exec_status, err_content