Exemple #1
0
    def execute_script(
        self,
        script_path: str,
        args: List[str],
        working_directory: Optional[str] = None,
        command_name: str = "Run",
    ) -> None:

        if working_directory is not None and get_workbench().get_local_cwd() != working_directory:
            # create compound command
            # start with %cd
            cd_cmd_line = construct_cd_command(working_directory) + "\n"
            next_cwd = working_directory
        else:
            # create simple command
            cd_cmd_line = ""
            next_cwd = get_workbench().get_local_cwd()

        if not is_remote_path(script_path) and self._proxy.uses_local_filesystem():
            rel_filename = os.path.relpath(script_path, next_cwd)
            cmd_parts = ["%" + command_name, rel_filename] + args
        else:
            cmd_parts = ["%" + command_name, "-c", EDITOR_CONTENT_TOKEN] + args

        exe_cmd_line = construct_cmd_line(cmd_parts, [EDITOR_CONTENT_TOKEN]) + "\n"

        # submit to shell (shell will execute it)
        get_shell().submit_magic_command(cd_cmd_line + exe_cmd_line)
Exemple #2
0
    def restart_backend(self, clean: bool, first: bool = False, wait: float = 0) -> None:
        """Recreate (or replace) backend proxy / backend process."""

        if not first:
            get_shell().restart()
            get_shell().update_idletasks()

        self.destroy_backend()
        backend_name = get_workbench().get_option("run.backend_name")
        if backend_name not in get_workbench().get_backends():
            raise UserError(
                "Can't find backend '{}'. Please select another backend from options".format(
                    backend_name
                )
            )

        backend_class = get_workbench().get_backends()[backend_name].proxy_class
        self._set_state("running")
        self._proxy = None
        self._proxy = backend_class(clean)

        self._poll_backend_messages()

        if wait:
            start_time = time.time()
            while not self.is_waiting_toplevel_command() and time.time() - start_time <= wait:
                # self._pull_backend_messages()
                get_workbench().update()
                sleep(0.01)

        get_workbench().event_generate("BackendRestart", full=True)
Exemple #3
0
    def execute_script(
        self,
        script_path: str,
        args: List[str],
        working_directory: Optional[str] = None,
        command_name: str = "Run",
    ) -> None:
        if (working_directory is not None
                and get_workbench().get_cwd() != working_directory):
            # create compound command
            # start with %cd
            cd_cmd_line = construct_cmd_line(["%cd", working_directory]) + "\n"
            next_cwd = working_directory
        else:
            # create simple command
            cd_cmd_line = ""
            next_cwd = get_workbench().get_cwd()

        # append main command (Run, run, Debug or debug)
        rel_filename = os.path.relpath(script_path, next_cwd)
        exe_cmd_line = (
            construct_cmd_line(["%" + command_name, rel_filename] + args) +
            "\n")

        # submit to shell (shell will execute it)
        get_shell().submit_magic_command(cd_cmd_line + exe_cmd_line)
    def request_focus_into(self, path):
        if path == "":
            if running_on_windows():
                # list of drives, can't cd
                self.focus_into(path)
                return
            else:
                path = "/"

        if not os.path.isdir(path):
            return

        proxy = get_runner().get_backend_proxy()
        if (
            proxy
            and proxy.uses_local_filesystem()
            and proxy.get_cwd() != path
            and get_runner().is_waiting_toplevel_command()
        ):
            get_shell().submit_magic_command(construct_cd_command(normpath_with_actual_case(path)))
        else:
            # it's OK, if it's already focused into this directory
            # focus again to refresh
            self.focus_into(path)
            get_workbench().set_local_cwd(path)
Exemple #5
0
    def request_focus_into(self, path):
        if not path:
            if running_on_windows():
                # list of drives, can't cd
                return self.focus_into(path)
            else:
                path = "/"

        if not os.path.isdir(path):
            return

        proxy = get_runner().get_backend_proxy()
        if (proxy and proxy.uses_local_filesystem()
                and get_workbench().get_local_cwd() != path
                and get_runner().is_waiting_toplevel_command()):
            get_shell().submit_magic_command(construct_cd_command(path))
        else:
            # change directly without notifying (non-existing, busy or remote) back-end
            get_workbench().set_local_cwd(path)
Exemple #6
0
    def request_focus_into(self, path):
        proxy = get_runner().get_backend_proxy()
        if proxy:
            assert proxy.has_own_filesystem()

            if not get_runner().is_waiting_toplevel_command():
                messagebox.showerror(
                    "Error",
                    "Can't change or refresh directories when device is busy.\n"
                    + "Wait until current command completes and try again.",
                )
            elif not proxy.supports_directories():
                assert path == ""
                self.focus_into(path)
            elif self.current_focus == path:
                # refreshes
                self.focus_into(path)
            else:
                get_shell().submit_magic_command(["%cd", path if path != "" else "/"])
Exemple #7
0
    def execute_script(
        self,
        script_path: str,
        args: List[str],
        working_directory: Optional[str] = None,
        command_name: str = "Run",
    ) -> None:

        if self._proxy.get_cwd() != working_directory:
            # create compound command
            # start with %cd
            cd_cmd_line = construct_cd_command(working_directory) + "\n"
        else:
            # create simple command
            cd_cmd_line = ""

        rel_filename = universal_relpath(script_path, working_directory)
        cmd_parts = ["%" + command_name, rel_filename] + args
        exe_cmd_line = construct_cmd_line(cmd_parts, [EDITOR_CONTENT_TOKEN]) + "\n"

        # submit to shell (shell will execute it)
        get_shell().submit_magic_command(cd_cmd_line + exe_cmd_line)
Exemple #8
0
    def request_focus_into(self, path):
        proxy = get_runner().get_backend_proxy()
        print("requesting", path)
        if proxy:
            assert proxy.has_own_filesystem()

            if not get_runner().is_waiting_toplevel_command():
                messagebox.showerror(
                    "Error",
                    "Can't change directories when device is busy.\n" +
                    "Wait until current command completes and try again.")
            elif not proxy.supports_directories():
                print("nodir")
                assert not path
                self.focus_into(path)
                get_workbench().set_remote_cwd(path)
            elif get_workbench().get_remote_cwd() == path:
                print("issame")
                self.focus_into(path)
                get_workbench().set_remote_cwd(path)
            else:
                print("notsame")
                get_shell().submit_magic_command(construct_cd_command(path))
Exemple #9
0
    def __init__(
        self,
        master,
        cmd: Union[InlineCommand, Callable],
        title,
        instructions=None,
        output_prelude=None,
        autostart=True,
    ):
        self.response = None
        self._title = title
        self._instructions = instructions
        self._output_prelude = output_prelude
        self._cmd = cmd
        self.returncode = None

        get_shell().set_ignore_program_output(True)

        get_workbench().bind("InlineResponse", self._on_response, True)
        get_workbench().bind("InlineProgress", self._on_progress, True)
        get_workbench().bind("ProgramOutput", self._on_output, True)

        super().__init__(master, autostart=autostart)
Exemple #10
0
    def ctrld(self):
        proxy = self.get_backend_proxy()
        if not proxy:
            return

        if get_shell().has_pending_input():
            messagebox.showerror(
                "Can't perform this action",
                "Ctrl+D only has effect on an empty line / prompt.\n"
                + "Submit current input (press ENTER) and try again",
            )
            return

        proxy.send_command(EOFCommand())
        self._set_state("running")
Exemple #11
0
 def _show_error(self, text):
     get_shell().print_error("\n" + text + "\n")
Exemple #12
0
    def send_command(self, cmd: CommandToBackend) -> Optional[str]:
        if isinstance(cmd, EOFCommand):
            get_shell().restart()  # Runner doesn't notice restart

        return super().send_command(cmd)
Exemple #13
0
 def execute_editor_content(self, command_name, args):
     get_shell().submit_magic_command(
         construct_cmd_line(
             ["%" + command_name, "-c", EDITOR_CONTENT_TOKEN] + args, [EDITOR_CONTENT_TOKEN]
         )
     )
Exemple #14
0
 def request_new_focus(self, path):
     get_shell().submit_magic_command(["%cd", path if path != "" else "/"])
Exemple #15
0
 def close(self):
     get_workbench().unbind("InlineResponse", self._on_response)
     get_workbench().unbind("InlineProgress", self._on_progress)
     super(InlineCommandDialog, self).close()
     get_shell().set_ignore_program_output(False)