Ejemplo n.º 1
0
    def __call__(self):
        from IPython.terminal.prompts import Prompts, Token
        from IPython.terminal.interactiveshell import TerminalInteractiveShell

        token = self._token

        class RFQuackShellPrompts(Prompts):
            def in_prompt_tokens(self, cli=None):
                return [(Token, token), (Token.Prompt, '> ')]

        TerminalInteractiveShell.prompts_class = RFQuackShellPrompts
        shell = TerminalInteractiveShell()
        shell.autocall = 0
        shell.show_banner(self._banner)

        q = RFQuack(self._transport, "rfquack", shell,
                    self._select_first_dongle)
        shell_objs = dict(q=q, pb=rfquack_pb2)

        # For each message field add a fake object with the same name,
        # this to achieve a **very basic** autocomp.
        for message_type in rfquack_pb2.DESCRIPTOR.message_types_by_name.values(
        ):
            for message_field in message_type.fields:
                shell_objs[
                    message_field.
                    name] = "This is a fake variable, used for autocompletion"

        shell.push(shell_objs)

        shell.mainloop()
Ejemplo n.º 2
0
    def __call__(self):
        from IPython.terminal.prompts import Prompts, Token
        from IPython.terminal.interactiveshell import TerminalInteractiveShell

        token = self._token

        class RFQuackShellPrompts(Prompts):
            def in_prompt_tokens(self, cli=None):
                return [(Token, token), (Token.Prompt, '> ')]

        TerminalInteractiveShell.prompts_class = RFQuackShellPrompts
        shell = TerminalInteractiveShell()
        shell.autocall = 2
        shell.show_banner(self._banner)

        q = RFQuack(self._transport, shell)
        q.idle()
        shell.push(dict(q=q, rfquack_pb2=rfquack_pb2))

        shell.mainloop()
Ejemplo n.º 3
0
def interactive(idx=0, DongleClass=RfCat, intro=''):
    global d
    import rflib.chipcon_nic as rfnic
    import atexit

    d = DongleClass(idx=idx)
    d.setModeRX()  # this puts the dongle into receive mode
    atexit.register(cleanupInteractiveAtExit)

    gbls = globals()
    lcls = locals()

    try:
        import IPython.Shell
        ipsh = IPython.Shell.IPShell(argv=[''],
                                     user_ns=lcls,
                                     user_global_ns=gbls)
        print intro
        ipsh.mainloop(intro)

    except ImportError, e:
        try:
            from IPython.terminal.interactiveshell import TerminalInteractiveShell
            ipsh = TerminalInteractiveShell()
            ipsh.user_global_ns.update(gbls)
            ipsh.user_global_ns.update(lcls)
            ipsh.autocall = 2  # don't require parenthesis around *everything*.  be smart!
            ipsh.show_banner(intro)
            ipsh.mainloop()
        except ImportError, e:
            try:
                from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
                ipsh = TerminalInteractiveShell()
                ipsh.user_global_ns.update(gbls)
                ipsh.user_global_ns.update(lcls)
                ipsh.autocall = 2  # don't require parenthesis around *everything*.  be smart!
                ipsh.mainloop(intro)
            except ImportError, e:
                print e
                shell = code.InteractiveConsole(gbls)
                shell.interact(intro)
Ejemplo n.º 4
0
def console(**kwargs):
    """
    An REPL fully configured for experimentation.

    usage:
        blueberrypy console [options]

    options:
        -e ENVIRONMENT, --environment=ENVIRONMENT  apply the given config environment
        -C ENV_VAR_NAME, --env-var ENV_VAR_NAME    add the given config from environment variable name
                                                   [default: BLUEBERRYPY_CONFIG]
        --ipython                                  use IPython shell instead of Python one
        -h, --help                                 show this help message and exit

    """

    banner = """
*****************************************************************************
* If the configuration file you specified contains a [sqlalchemy_engine*]   *
* section, a default SQLAlchemy engine and session should have been created *
* for you automatically already.                                            *
*****************************************************************************
"""
    environment = kwargs.get("environment")
    config_dir = kwargs.get("config_dir")
    environment and cherrypy.config.update({"environment": environment})
    configuration = BlueberryPyConfiguration(
        config_dir=config_dir,
        environment=environment,
        env_var_name=kwargs.get('env_var'),
    )
    use_ipython = kwargs.get("ipython", False)
    package_name = shell.get_package_name(configuration)

    if use_ipython:
        try:
            from IPython.terminal.interactiveshell import TerminalInteractiveShell
        except ImportError as e:
            print(e)
            print("""Cannot import iPython. Did you install it?""")
            return
        try:
            app_package = import_module(package_name)
        except ImportError as e:
            print(e)
            app_package = None
        repl = TerminalInteractiveShell(
            user_ns=shell.get_user_namespace(configuration),
            user_module=app_package,
            display_completions='multicolumn',  # oldstyle is 'readlinelike'
            mouse_support=True,
            space_for_menu=10,  # reserve N lines for the completion menu
        )
        repl.show_banner(banner)
        repl.mainloop()
    else:
        try:
            import readline
        except ImportError as e:
            print(e)
        else:
            import rlcompleter
        sys.ps1 = "[%s]>>> " % package_name
        sys.ps2 = "[%s]... " % package_name

        ns = shell.get_user_namespace(configuration, include_pkg=True)
        repl = InteractiveConsole(locals=ns)
        repl.prompt = package_name
        repl.interact(banner)