diff options
author | Todd Leonhardt <tleonhardt@gmail.com> | 2017-02-07 18:54:18 -0500 |
---|---|---|
committer | Todd Leonhardt <tleonhardt@gmail.com> | 2017-02-07 18:54:18 -0500 |
commit | 432fd66a6fb19c06e7a048aea1957dc7302166c1 (patch) | |
tree | 1bb4cedf22d921d05d0065f6173e52051f1ec412 /cmd2.py | |
parent | 1dc956e8b3a2b7bd8f152dcbcb60caa8dd57ddb6 (diff) | |
download | cmd2-git-432fd66a6fb19c06e7a048aea1957dc7302166c1.tar.gz |
Moved preloop() and postloop() calls from _cmdloop() to cmdloop().
In order to fix a problem with do_load() trying to do more than it should, refactored to move the preloop() and postloop() calls so they are not called when loading a script.
This is so a script is simply a way to automate running several commands in a row and makes it safe for preloop() to create threads, connect to servers, and do other stateful things.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -1055,11 +1055,8 @@ class Cmd(cmd.Cmd): off the received input, and dispatch to action methods, passing them the remainder of the line as argument. """ - # An almost perfect copy from Cmd; however, the pseudo_raw_input portion # has been split out so that it can be called separately - - self.preloop() if self.use_rawinput and self.completekey: try: import readline @@ -1071,8 +1068,6 @@ class Cmd(cmd.Cmd): stop = None try: if intro is not None: - self.intro = intro - if self.intro: self.stdout.write(str(self.intro) + "\n") while not stop: if self.cmdqueue: @@ -1082,7 +1077,6 @@ class Cmd(cmd.Cmd): if self.echo and isinstance(self.stdin, file): self.stdout.write(line + '\n') stop = self.onecmd_plus_hooks(line) - self.postloop() finally: if self.use_rawinput and self.completekey: try: @@ -1414,7 +1408,7 @@ class Cmd(cmd.Cmd): self.use_rawinput = False self.prompt = self.continuation_prompt = '' self.current_script_dir = os.path.split(targetname)[0] - stop = self._cmdloop() + stop = self._cmdloop(None) self.stdin.close() keepstate.restore() self.lastcmd = '' @@ -1460,7 +1454,9 @@ class Cmd(cmd.Cmd): self.runTranscriptTests(callargs) else: if not self.run_commands_at_invocation(callargs): - self._cmdloop() + self.preloop() + self._cmdloop(self.intro) + self.postloop() class HistoryItem(str): |