diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-01-27 22:49:34 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-01-27 22:49:34 -0500 |
commit | 415f1cb1c7dd5fbfe21cca0c6eea2eb998bbd1a0 (patch) | |
tree | f38d9d7496e712ef36c0856bf4c0ddcb17219c18 | |
parent | 0f8f90cc2ade4135193f5399e5e6a12271668867 (diff) | |
download | cmd2-git-415f1cb1c7dd5fbfe21cca0c6eea2eb998bbd1a0.tar.gz |
Renamed locals_in_py to self_in_py
This more accurately reflects what it controls
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rwxr-xr-x | README.md | 7 | ||||
-rw-r--r-- | cmd2/cmd2.py | 8 | ||||
-rw-r--r-- | docs/features/embedded_python_shells.rst | 2 | ||||
-rw-r--r-- | docs/features/initialization.rst | 6 | ||||
-rwxr-xr-x | examples/basic.py | 2 | ||||
-rwxr-xr-x | examples/cmd_as_argument.py | 2 | ||||
-rwxr-xr-x | examples/hello_cmd2.py | 2 | ||||
-rwxr-xr-x | examples/initialization.py | 2 | ||||
-rwxr-xr-x | examples/override_parser.py | 2 | ||||
-rwxr-xr-x | examples/python_scripting.py | 2 | ||||
-rw-r--r-- | examples/scripts/conditional.py | 2 | ||||
-rw-r--r-- | examples/scripts/save_help_text.py | 2 | ||||
-rwxr-xr-x | tests/test_cmd2.py | 8 |
14 files changed, 24 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f6e71d6a..e8f07b93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ ## 0.9.26 (January 26, 2020) * Breaking changes + * Renamed `locals_in_py` attribute of `cmd2.Cmd` to `self_in_py` * The following public attributes of `cmd2.Cmd` are no longer settable at runtime by end users: * `continuation_prompt` - * `locals_in_py` + * `self_in_py` * `prompt` ## 0.9.25 (January 26, 2020) @@ -318,14 +318,11 @@ example/transcript_regex.txt: # regexes on prompts just make the trailing space obvious (Cmd) set allow_style: Terminal -continuation_prompt: >/ / debug: False echo: False editor: /.*?/ feedback_to_output: False -locals_in_py: True maxrepeats: 3 -prompt: (Cmd)/ / quiet: False timing: False ``` @@ -350,14 +347,14 @@ Open source projects using cmd2 Here are a few examples of open-source projects which use `cmd2`: +* [Jok3r](http://www.jok3r-framework.com) + * Network & Web Pentest Automation Framework * [CephFS Shell](http://docs.ceph.com/docs/master/cephfs/cephfs-shell/) * [Ceph](https://ceph.com/) is a distributed object, block, and file storage platform * [JSShell](https://github.com/Den1al/JSShell) * An interactive multi-user web JavaScript shell * [psiTurk](https://psiturk.org) * An open platform for science on Amazon Mechanical Turk -* [Jok3r](http://www.jok3r-framework.com) - * Network & Web Pentest Automation Framework * [Poseidon](https://github.com/CyberReboot/poseidon) * Leverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques * [Unipacker](https://github.com/unipacker/unipacker) diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 609f01ad..a36bcdb6 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -181,7 +181,7 @@ class Cmd(cmd.Cmd): super().__init__(completekey=completekey, stdin=stdin, stdout=stdout) # Attributes which should NOT be dynamically settable via the set command at runtime - # To prevent a user from altering these with the py/ipy commands, remove locals_in_py from the + # To prevent a user from altering these with the py/ipy commands, remove self_in_py from the # settable dictionary during your applications's __init__ method. self.default_to_shell = False # Attempt to run unrecognized commands as shell commands self.quit_on_sigint = False # Quit the loop on interrupt instead of just resetting prompt @@ -221,7 +221,7 @@ class Cmd(cmd.Cmd): self.continuation_prompt = '> ' # Allow access to your application in embedded Python shells and scripts py via self - self.locals_in_py = False + self.self_in_py = False # Commands to exclude from the help menu and tab completion self.hidden_commands = ['eof', '_relative_load', '_relative_run_script'] @@ -3118,7 +3118,7 @@ class Cmd(cmd.Cmd): self.py_locals['quit'] = py_quit self.py_locals['exit'] = py_quit - if self.locals_in_py: + if self.self_in_py: self.py_locals['self'] = self elif 'self' in self.py_locals: del self.py_locals['self'] @@ -3238,7 +3238,7 @@ class Cmd(cmd.Cmd): exec("{} = py_bridge".format(cmd2_app.py_bridge_name)) # Add self variable pointing to cmd2_app, if allowed - if cmd2_app.locals_in_py: + if cmd2_app.self_in_py: exec("self = cmd2_app") # Delete these names from the environment so IPython can't use them diff --git a/docs/features/embedded_python_shells.rst b/docs/features/embedded_python_shells.rst index 3386e8cd..0af2f737 100644 --- a/docs/features/embedded_python_shells.rst +++ b/docs/features/embedded_python_shells.rst @@ -8,7 +8,7 @@ arguments, it enters an interactive Python session. The session can call your cmd2 application while maintaining isolation. You may optionally enable full access to to your application by setting -``locals_in_py`` to ``True``. Enabling this flag adds ``self`` to the python +``self_in_py`` to ``True``. Enabling this flag adds ``self`` to the python session, which is a reference to your Cmd2 application. This can be useful for debugging your application. diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst index 864741cd..c5df5af8 100644 --- a/docs/features/initialization.rst +++ b/docs/features/initialization.rst @@ -39,7 +39,7 @@ capabilities which you may wish to utilize while initializing the app:: self.continuation_prompt = '... ' # Allow access to your application in py and ipy via self - self.locals_in_py = True + self.self_in_py = True # Set the default category name self.default_category = 'cmd2 Built-in Commands' @@ -125,7 +125,7 @@ override: of results in a Python script or interactive console. Built-in commands don't make use of this. It is purely there for user-defined commands and convenience. -- **locals_in_py**: if ``True`` allow access to your application in *py* +- **self_in_py**: if ``True`` allow access to your application in *py* command via ``self`` (Default: ``False``) - **macros**: dictionary of macro names and their values - **max_completion_items**: max number of CompletionItems to display during @@ -139,7 +139,7 @@ override: ``app``) - **py_locals**: dictionary that defines specific variables/functions available in Python shells and scripts (provides more fine-grained control than making - everything available with **locals_in_py**) + everything available with **self_in_py**) - **quiet**: if ``True`` then completely suppress nonessential output (Default: ``False``) - **quit_on_sigint**: if ``True`` quit the main loop on interrupt instead of diff --git a/examples/basic.py b/examples/basic.py index 75672a6b..37db6501 100755 --- a/examples/basic.py +++ b/examples/basic.py @@ -22,7 +22,7 @@ class BasicApp(cmd2.Cmd): self.intro = style('Welcome to PyOhio 2019 and cmd2!', fg='red', bg='white', bold=True) + ' 😀' # Allow access to your application in py and ipy via self - self.locals_in_py = True + self.self_in_py = True # Set the default category name self.default_category = 'cmd2 Built-in Commands' diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py index 49a50670..08643a50 100755 --- a/examples/cmd_as_argument.py +++ b/examples/cmd_as_argument.py @@ -33,7 +33,7 @@ class CmdLineApp(cmd2.Cmd): # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell super().__init__(allow_cli_args=False, use_ipython=True, multiline_commands=['orate'], shortcuts=shortcuts) - self.locals_in_py = True + self.self_in_py = True self.maxrepeats = 3 # Make maxrepeats settable at runtime self.settable['maxrepeats'] = 'max repetitions for speak command' diff --git a/examples/hello_cmd2.py b/examples/hello_cmd2.py index 84754623..94ec334f 100755 --- a/examples/hello_cmd2.py +++ b/examples/hello_cmd2.py @@ -12,6 +12,6 @@ if __name__ == '__main__': # Set "use_ipython" to True to include the ipy command if IPython is installed, which supports advanced interactive # debugging of your application via introspection on self. app = cmd2.Cmd(use_ipython=True, persistent_history_file='cmd2_history.dat') - app.locals_in_py = True # Enable access to "self" within the py command + app.self_in_py = True # Enable access to "self" within the py command app.debug = True # Show traceback if/when an exception occurs sys.exit(app.cmdloop()) diff --git a/examples/initialization.py b/examples/initialization.py index e26aac9f..32aa852f 100755 --- a/examples/initialization.py +++ b/examples/initialization.py @@ -33,7 +33,7 @@ class BasicApp(cmd2.Cmd): self.continuation_prompt = '... ' # Allow access to your application in py and ipy via self - self.locals_in_py = True + self.self_in_py = True # Set the default category name self.default_category = 'cmd2 Built-in Commands' diff --git a/examples/override_parser.py b/examples/override_parser.py index ddfa8323..eecb0e88 100755 --- a/examples/override_parser.py +++ b/examples/override_parser.py @@ -19,6 +19,6 @@ from cmd2 import cmd2 if __name__ == '__main__': import sys app = cmd2.Cmd(use_ipython=True, persistent_history_file='cmd2_history.dat') - app.locals_in_py = True # Enable access to "self" within the py command + app.self_in_py = True # Enable access to "self" within the py command app.debug = True # Show traceback if/when an exception occurs sys.exit(app.cmdloop()) diff --git a/examples/python_scripting.py b/examples/python_scripting.py index 8c680d33..fc23c562 100755 --- a/examples/python_scripting.py +++ b/examples/python_scripting.py @@ -29,7 +29,7 @@ class CmdLineApp(cmd2.Cmd): super().__init__(use_ipython=True) self._set_prompt() self.intro = 'Happy 𝛑 Day. Note the full Unicode support: 😇 💩' - self.locals_in_py = True + self.self_in_py = True def _set_prompt(self): """Set prompt so it displays the current working directory.""" diff --git a/examples/scripts/conditional.py b/examples/scripts/conditional.py index 2e307cb4..eb4c203e 100644 --- a/examples/scripts/conditional.py +++ b/examples/scripts/conditional.py @@ -8,7 +8,7 @@ To run it you should do the following: run_pyscript scripts/conditional.py directory_path Note: The "app" function is defined within the cmd2 embedded Python environment and in there "self" is your cmd2 -application instance. Note: self only exists in this environment if locals_in_py is True. +application instance. Note: self only exists in this environment if self_in_py is True. """ import os import sys diff --git a/examples/scripts/save_help_text.py b/examples/scripts/save_help_text.py index 2d1c2c41..cc4cfcc7 100644 --- a/examples/scripts/save_help_text.py +++ b/examples/scripts/save_help_text.py @@ -60,7 +60,7 @@ def main() -> None: # Make sure we have access to self if 'self' not in globals(): - print("Re-run this script from a cmd2 application where locals_in_py is True") + print("Re-run this script from a cmd2 application where self_in_py is True") return # Make sure the user passed in an output file diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 21cd941e..a3dbe1be 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -254,13 +254,13 @@ def test_base_py(base_app): out, err = run_cmd(base_app, 'py print("spaces" + " in this " + "command")') assert out[0].rstrip() == 'spaces in this command' - # Set locals_in_py to True and make sure we see self - base_app.locals_in_py = True + # Set self_in_py to True and make sure we see self + base_app.self_in_py = True out, err = run_cmd(base_app, 'py print(self)') assert 'cmd2.cmd2.Cmd object' in out[0] - # Set locals_in_py to False and make sure we can't see self - base_app.locals_in_py = False + # Set self_in_py to False and make sure we can't see self + base_app.self_in_py = False out, err = run_cmd(base_app, 'py print(self)') assert "NameError: name 'self' is not defined" in err |