summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-29 17:36:46 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-29 17:36:46 -0400
commitda7020c26c6bbc871c94587ba10f751e53f7911b (patch)
tree6e2e2e8aaf7c18e344c4eb87c8acd661dc90d79e /cmd2/cmd2.py
parent31da70efe7160439eb6ab13f46739993f4d4cd7f (diff)
downloadcmd2-git-da7020c26c6bbc871c94587ba10f751e53f7911b.tar.gz
Remove load, _relative_load, pyscript aliases which
These commands were renamed in the last release, but aliases were created along with warnings to help aid the transition. The command aliases are now being removed in this release.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py93
1 files changed, 34 insertions, 59 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index eb2d4c15..d41a631d 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -3261,16 +3261,9 @@ class Cmd(cmd.Cmd):
finally:
# Restore command line arguments to original state
sys.argv = orig_args
- if args.__statement__.command == "pyscript":
- warning = ("pyscript has been renamed and will be removed in the next release, "
- "please use run_pyscript instead\n")
- self.perror(ansi.style_warning(warning))
return py_return
- # pyscript is deprecated
- do_pyscript = do_run_pyscript
-
# Only include the do_ipy() method if IPython is available on the system
if ipython_available: # pragma: no cover
@with_argparser(ACArgumentParser())
@@ -3644,59 +3637,49 @@ class Cmd(cmd.Cmd):
"""
expanded_path = os.path.abspath(os.path.expanduser(args.script_path))
- # Wrap everything in a try/finally just to make sure the warning prints at end if `load` was called
- try:
- # Make sure the path exists and we can access it
- if not os.path.exists(expanded_path):
- self.perror("'{}' does not exist or cannot be accessed".format(expanded_path))
- return
+ # Make sure the path exists and we can access it
+ if not os.path.exists(expanded_path):
+ self.perror("'{}' does not exist or cannot be accessed".format(expanded_path))
+ return
- # Make sure expanded_path points to a file
- if not os.path.isfile(expanded_path):
- self.perror("'{}' is not a file".format(expanded_path))
- return
+ # Make sure expanded_path points to a file
+ if not os.path.isfile(expanded_path):
+ self.perror("'{}' is not a file".format(expanded_path))
+ return
- # Make sure the file is not empty
- if os.path.getsize(expanded_path) == 0:
- self.perror("'{}' is empty".format(expanded_path))
- return
+ # Make sure the file is not empty
+ if os.path.getsize(expanded_path) == 0:
+ self.perror("'{}' is empty".format(expanded_path))
+ return
- # Make sure the file is ASCII or UTF-8 encoded text
- if not utils.is_text_file(expanded_path):
- self.perror("'{}' is not an ASCII or UTF-8 encoded text file".format(expanded_path))
- return
+ # Make sure the file is ASCII or UTF-8 encoded text
+ if not utils.is_text_file(expanded_path):
+ self.perror("'{}' is not an ASCII or UTF-8 encoded text file".format(expanded_path))
+ return
- try:
- # Read all lines of the script
- with open(expanded_path, encoding='utf-8') as target:
- script_commands = target.read().splitlines()
- except OSError as ex: # pragma: no cover
- self.pexcept("Problem accessing script from '{}': {}".format(expanded_path, ex))
- return
+ try:
+ # Read all lines of the script
+ with open(expanded_path, encoding='utf-8') as target:
+ script_commands = target.read().splitlines()
+ except OSError as ex: # pragma: no cover
+ self.pexcept("Problem accessing script from '{}': {}".format(expanded_path, ex))
+ return
- orig_script_dir_count = len(self._script_dir)
+ orig_script_dir_count = len(self._script_dir)
- try:
- self._script_dir.append(os.path.dirname(expanded_path))
+ try:
+ self._script_dir.append(os.path.dirname(expanded_path))
- if args.transcript:
- self._generate_transcript(script_commands, os.path.expanduser(args.transcript))
- else:
- return self.runcmds_plus_hooks(script_commands)
+ if args.transcript:
+ self._generate_transcript(script_commands, os.path.expanduser(args.transcript))
+ else:
+ return self.runcmds_plus_hooks(script_commands)
- finally:
- with self.sigint_protection:
- # Check if a script dir was added before an exception occurred
- if orig_script_dir_count != len(self._script_dir):
- self._script_dir.pop()
finally:
- if args.__statement__.command == "load":
- warning = ("load has been renamed and will be removed in the next release, "
- "please use run_script instead\n")
- self.perror(ansi.style_warning(warning))
-
- # load has been deprecated
- do_load = do_run_script
+ with self.sigint_protection:
+ # Check if a script dir was added before an exception occurred
+ if orig_script_dir_count != len(self._script_dir):
+ self._script_dir.pop()
relative_run_script_description = run_script_description
relative_run_script_description += (
@@ -3717,19 +3700,11 @@ class Cmd(cmd.Cmd):
Run commands in script file that is encoded as either ASCII or UTF-8 text
:return: True if running of commands should stop
"""
- if args.__statement__.command == "_relative_load":
- warning = ("_relative_load has been renamed and will be removed in the next release, "
- "please use _relative_run_script instead\n")
- self.perror(ansi.style_warning(warning))
-
file_path = args.file_path
# NOTE: Relative path is an absolute path, it is just relative to the current script directory
relative_path = os.path.join(self._current_script_dir or '', file_path)
return self.do_run_script(relative_path)
- # _relative_load has been deprecated
- do__relative_load = do__relative_run_script
-
def _run_transcript_tests(self, transcript_paths: List[str]) -> None:
"""Runs transcript tests for provided file(s).