diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:41:51 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:41:51 -0400 |
commit | a266446746c49f55c3447c467f053f88c2059c66 (patch) | |
tree | 6a8b19f452cd90ceffab4184cf34defd4e1f9be1 | |
parent | 13936653ec86ba405f29f6a680e91a7f21353aaa (diff) | |
download | cmd2-git-a266446746c49f55c3447c467f053f88c2059c66.tar.gz |
Print warning if a user tries to run something other than a *.py file with run_pyscript and ask them if they want to continue
-rw-r--r-- | cmd2/cmd2.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 4553e2cd..d1dc87ff 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3246,6 +3246,12 @@ class Cmd(cmd.Cmd): """ expanded_filename = os.path.expanduser(filename) + if not expanded_filename.endswith('.py'): + self.pwarning("'{}' does not appear to be a Python file".format(expanded_filename)) + selection = self.select('Yes No', 'Continue to try to run it as a Python script? ') + if selection != 'Yes': + return + # cmd_echo defaults to False for scripts. The user can always toggle this value in their script. py_bridge.cmd_echo = False @@ -3756,9 +3762,9 @@ class Cmd(cmd.Cmd): self.perror("'{}' is not an ASCII or UTF-8 encoded text file".format(expanded_path)) return - if expanded_path.endswith('.py') or expanded_path.endswith('.pyc'): + if expanded_path.endswith('.py'): self.pwarning("'{}' appears to be a Python file".format(expanded_path)) - selection = self.select('Yes No', 'Continue to try to run it as a text file script? ') + selection = self.select('Yes No', 'Continue to try to run it as a text script? ') if selection != 'Yes': return |