Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two new commands: execfile and lexecfile to execute a remote/local python file #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions mp/mpfshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,48 @@ def do_cat(self, args):

complete_cat = complete_get

def do_execfile(self, args):
"""execfile <REMOTE FILE>
Execute the contents of a REMOTE file.
"""

if not len(args):
self.__error("Missing argument: <REMOTE FILE>")
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: <REMOTE FILE>")
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 <LOCAL FILE>
Execute the contents of a LOCAL file.
"""

if not len(args):
self.__error("Missing argument: <LOCAL FILE>")
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: <LOCAL FILE>")
return

try:
self.fe.execfile(s_args[0])
except IOError as e:
self.__error(str(e))

def do_exec(self, args):
"""exec <STATEMENT>
Execute a Python statement on remote.
Expand Down