diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-21 06:54:58 -0400 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-21 06:54:58 -0400 |
| commit | 98b57f380d4bedbbe9a0eea174075f8c62aea6bd (patch) | |
| tree | 2b1a212898dfdc14be9f952585fd3c5abed42102 /examples/script_conditional.py | |
| parent | 1b829f13cfa9460ddb6304d507ea30bfbb31c6e7 (diff) | |
| download | cmd2-git-98b57f380d4bedbbe9a0eea174075f8c62aea6bd.tar.gz | |
Moved example scripts from examples to examples/scripts directly
Cleaned up the examples directory by adding a scripts subdirectory.
This makes it a bit clearer which Python files are example cmd2 applications and which are example Python scripts for use with the pyscript command.
Diffstat (limited to 'examples/script_conditional.py')
| -rw-r--r-- | examples/script_conditional.py | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/examples/script_conditional.py b/examples/script_conditional.py deleted file mode 100644 index c26bd5fe..00000000 --- a/examples/script_conditional.py +++ /dev/null @@ -1,39 +0,0 @@ -# coding=utf-8 -""" -This is a Python script intended to be used with the "python_scripting.py" cmd2 example application. - -To run it you should do the following: - ./python_scripting.py - pyscript script_conditional.py directory_path - -Note: The "cmd" function is defined within the cmd2 embedded Python environment and in there "self" is your cmd2 -application instance. -""" -import os -import sys - - -if len(sys.argv) > 1: - directory = sys.argv[1] - print('Using specified directory: {!r}'.format(directory)) -else: - directory = 'foobar' - print('Using default directory: {!r}'.format(directory)) - -# Keep track of where we stared -original_dir = os.getcwd() - -# Try to change to the specified directory -cmd('cd {}'.format(directory)) - -# Conditionally do something based on the results of the last command -if self._last_result: - print('\nContents of directory {!r}:'.format(directory)) - cmd('dir -l') - - # Change back to where we were - print('Changing back to original directory: {!r}'.format(original_dir)) - cmd('cd {}'.format(original_dir)) -else: - # cd command failed, print a warning - print('Failed to change directory to {!r}'.format(directory)) |
