Exemplo n.º 1
0
    def open_custom_system_shell(self):
        from thonny import terminal

        get_runner().send_command_and_wait(InlineCommand("prepare_disconnect"),
                                           "Disconnecting")

        self.disconnect()

        terminal.run_in_terminal(
            [
                running.get_interpreter_for_subprocess(sys.executable),
                "-m",
                # "serial.tools.miniterm",
                "thonny.plugins.micropython.miniterm_wrapper",
                "--exit-char",
                "20",
                "--menu-char",
                "29",
                "--filter",
                "direct",
                "--quiet",
                self._port,
                "115200",
            ],
            cwd=get_workbench().get_local_cwd(),
            keep_open=False,
            title=self._port,
        )
Exemplo n.º 2
0
    def run_script_in_terminal(self, script_path, args, interactive, keep_open):
        cmd = [self._executable]
        if interactive:
            cmd.append("-i")
        cmd.append(os.path.basename(script_path))
        cmd.extend(args)

        run_in_terminal(cmd, os.path.dirname(script_path), keep_open=keep_open)
Exemplo n.º 3
0
    def open_custom_system_shell(self):
        if not shutil.which("ssh"):
            messagebox.showerror(
                "Command not found", "Command 'ssh' not found", master=get_workbench()
            )
            return

        from thonny import terminal

        userhost = "%s@%s" % (self._user, self._host)
        terminal.run_in_terminal(
            ["ssh", userhost], cwd=get_workbench().get_local_cwd(), keep_open=False, title=userhost
        )
Exemplo n.º 4
0
def _open_system_shell():
    """Main task is to modify path and open terminal window.
    Bonus (and most difficult) part is executing a script in this window
    for recommending commands for running given python and related pip"""

    if inside_flatpak():
        show_command_not_available_in_flatpak_message()
        return

    cwd = get_workbench().get_local_cwd()

    proxy = get_runner().get_backend_proxy()
    if proxy and proxy.has_custom_system_shell():
        proxy.open_custom_system_shell()
        return
    if proxy and proxy.get_local_executable():
        target_executable = proxy.get_local_executable()
    else:
        target_executable = sys.executable

    exe_dirs = get_exe_dirs()
    if hasattr(proxy, "get_exe_dirs") and proxy.get_exe_dirs():
        # use both backend and frontend exe dirs
        exe_dirs = proxy.get_exe_dirs() + exe_dirs

    env_overrides = get_environment_overrides_for_python_subprocess(
        target_executable)
    env_overrides["PATH"] = get_augmented_system_path(exe_dirs)

    explainer = os.path.join(os.path.dirname(__file__),
                             "explain_environment.py")
    cmd = [target_executable, explainer]

    activate = os.path.join(
        os.path.dirname(target_executable),
        "activate.bat" if platform.system() == "Windows" else "activate",
    )

    if os.path.isfile(activate):
        del env_overrides["PATH"]
        if platform.system() == "Windows":
            cmd = [activate, "&"] + cmd
        else:
            cmd = ["source", activate, ";"] + cmd

    return terminal.run_in_terminal(cmd, cwd, env_overrides, True)