From 9b36a3a410468674b542d3a6d0193700c61846fe Mon Sep 17 00:00:00 2001 From: GHPS Date: Fri, 19 Jan 2018 18:43:08 +0100 Subject: [PATCH] Added two new commands: execfile and lexecfile to execute a remote/local python file --- mp/mpfshell.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mp/mpfshell.py b/mp/mpfshell.py index e5a7ebb..e72abf0 100644 --- a/mp/mpfshell.py +++ b/mp/mpfshell.py @@ -524,6 +524,48 @@ def do_cat(self, args): complete_cat = complete_get + def do_execfile(self, args): + """execfile + Execute the contents of a REMOTE file. + """ + + if not len(args): + self.__error("Missing argument: ") + elif self.__is_open(): + + s_args = self.__parse_file_names(args) + if not s_args: + return + elif len(s_args) > 1: + self.__error("Only one argument allowed: ") + return + + try: + self.fe.exec_(self.fe.gets(s_args[0])) + except IOError as e: + self.__error(str(e)) + + def do_lexecfile(self, args): + """lexecfile + Execute the contents of a LOCAL file. + """ + + if not len(args): + self.__error("Missing argument: ") + elif self.__is_open(): + + s_args = self.__parse_file_names(args) + if not s_args: + return + elif len(s_args) > 1: + self.__error("Only one argument allowed: ") + return + + try: + self.fe.execfile(s_args[0]) + except IOError as e: + self.__error(str(e)) + def do_exec(self, args): """exec Execute a Python statement on remote.