Skip to content

Commit

Permalink
[DOC] Add all API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
raczben committed Apr 7, 2020
1 parent 2e96ee1 commit 9cdc9a2
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 89 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ them automatically.
To interract with a child process use `spawn` method:

```python
import wexpect
import wexpect
child = wexpect.spawn('cmd.exe')
child.expect('>')
child.sendline('ls')
Expand All @@ -49,11 +49,11 @@ structured spawn class.
But what is the difference between the old and new and what was the problem with the old?

Generally, wexpect (both old and new) has three processes:
- *host* is our original pyton script/program, which want to launch the child.

- *host* is our original python script/program, which want to launch the child.
- *console* is a process which started by the host, and launches the child. (This is a python script)
- *child* is the process which want to be launced.

The child and the console has a common Windows console, distict from the host.

The `legacy_wexpect`'s console is a thin script, almost do nothing. It initializes the Windows's
Expand Down Expand Up @@ -81,7 +81,7 @@ scripts for duplicating software package installations on different servers. It
can be used for automated software testing. Wexpect is in the spirit of Don
Libes' Expect, but Wexpect is pure Python. Other Expect-like modules for Python
require TCL and Expect or require C extensions to be compiled. Wexpect does not
use C, Expect, or TCL extensions.
use C, Expect, or TCL extensions.

Original Pexpect should work on any platform that supports the standard Python pty module. While
Wexpect works on Windows platforms. The Wexpect interface focuses on ease of use so that simple
Expand Down Expand Up @@ -117,13 +117,13 @@ See `after_test` section in [appveyor.yml](appveyor.yml) for more details.
The wexpect uses [pbr](https://docs.openstack.org/pbr/latest/) for managing releasing procedures.
The versioning is handled by the pbr. The *"master-version"* is the git tag. Pbr derives the package
version from the git tags.

## Basic behaviour

Let's go through the example code:

```python
import wexpect
import wexpect
child = wexpect.spawn('cmd.exe')
child.expect('>')
child.sendline('ls')
Expand All @@ -139,28 +139,28 @@ child.sendline('exit')
Call trace:

- ::spawn
- spawn_windows::__init__()
- spawn_windows::__init__()
- spawn_windows::_spawn()
- Wtty::spawn()
- Wtty::startChild()
- win32process.CreateProcess()


### expect()

`child.expect('>')`

Call trace:

- spawn_windows::expect()
- spawn_windows::expect_list()
- spawn_windows::expect_list()
- spawn_windows::expect_loop()
- spawn_windows::read_nonblocking()
- Wtty::read_nonblocking()
- Wtty::readConsoleToCursor()
- Wtty::readConsole()
- __consout.ReadConsoleOutputCharacter()


### sendline()

Expand Down
62 changes: 62 additions & 0 deletions doc/source/api/console_reader.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Console reader
==============

.. automodule:: wexpect.console_reader


ConsoleReaderPipe
-----------------

.. autoclass:: ConsoleReaderPipe

.. automethod:: __init__
.. automethod:: read_loop
.. automethod:: suspend_child
.. automethod:: resume_child
.. automethod:: refresh_console
.. automethod:: terminate_child
.. automethod:: isalive
.. automethod:: write
.. automethod:: createKeyEvent
.. automethod:: initConsole
.. automethod:: parseData
.. automethod:: getConsoleOut
.. automethod:: getCoord
.. automethod:: getOffset
.. automethod:: readConsole
.. automethod:: readConsoleToCursor
.. automethod:: interact
.. automethod:: sendeof
.. automethod:: create_connection
.. automethod:: close_connection
.. automethod:: send_to_host
.. automethod:: get_from_host


ConsoleReaderSocket
-------------------

.. autoclass:: ConsoleReaderSocket

.. automethod:: __init__
.. automethod:: read_loop
.. automethod:: suspend_child
.. automethod:: resume_child
.. automethod:: refresh_console
.. automethod:: terminate_child
.. automethod:: isalive
.. automethod:: write
.. automethod:: createKeyEvent
.. automethod:: initConsole
.. automethod:: parseData
.. automethod:: getConsoleOut
.. automethod:: getCoord
.. automethod:: getOffset
.. automethod:: readConsole
.. automethod:: readConsoleToCursor
.. automethod:: interact
.. automethod:: sendeof
.. automethod:: create_connection
.. automethod:: close_connection
.. automethod:: send_to_host
.. automethod:: get_from_host
48 changes: 48 additions & 0 deletions doc/source/api/host.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Host
=============

.. automodule:: wexpect.host

Functions
---------

.. automethod:: wexpect.host.run

SpawnPipe
---------

.. autoclass:: SpawnPipe

.. automethod:: __init__
.. automethod:: expect
.. automethod:: expect_exact
.. automethod:: expect_list
.. automethod:: compile_pattern_list
.. automethod:: send
.. automethod:: sendline
.. automethod:: write
.. automethod:: writelines
.. automethod:: sendeof
.. automethod:: read
.. automethod:: readline
.. automethod:: read_nonblocking


SpawnSocket
-----------

.. autoclass:: SpawnSocket

.. automethod:: __init__
.. automethod:: expect
.. automethod:: expect_exact
.. automethod:: expect_list
.. automethod:: compile_pattern_list
.. automethod:: send
.. automethod:: sendline
.. automethod:: write
.. automethod:: writelines
.. automethod:: sendeof
.. automethod:: read
.. automethod:: readline
.. automethod:: read_nonblocking
83 changes: 82 additions & 1 deletion doc/source/api/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
API documentation
=================

Wexpect symbols
---------------

Wexpect package has the following symbols. (Exported by :code:`__all__` in code:`__init__.py`)

.. _wexpect.spawn:

**spawn**

This is the main class interface for Wexpect. Use this class to start and control child applications.
There are two implementation: :class:`wexpect.host.SpawnPipe` uses Windows-Pipe for communicate child.
:class:`wexpect.SpawnSocket` uses TCP socket. Choose the default implementation with
:code:`WEXPECT_SPAWN_CLASS` environment variable, or the :class:`wexpect.host.SpawnPipe` will be
chosen by default.

.. _wexpect.SpawnPipe:

**SpawnPipe**

:class:`wexpect.host.SpawnPipe` is the default spawn class, but you can access it directly with its
exact name.

.. _wexpect.SpawnSocket:

**SpawnSocket**

:class:`wexpect.host.SpawnSocket` is the secondary spawn class, you can access it directly with its
exact name or by setting the :code:`WEXPECT_SPAWN_CLASS` environment variable to :code:`SpawnSocket`

.. _wexpect.run:

**run**

:meth:`wexpect.host.run` runs the given command; waits for it to finish; then returns all output as a string.
This function is similar to :code:`os.system()`.

.. _wexpect.EOF:

**EOF**

:class:`wexpect.wexpect_util.EOF` is an exception. This usually means the child has exited.

.. _wexpect.TIMEOUT:

**TIMEOUT**

:class:`wexpect.wexpect_util.TIMEOUT` raised when a read time exceeds the timeout.

.. _wexpect.__version__:

**__version__**

This gives back the version of the wexpect release. Versioning is handled by the
`pbr <https://pypi.org/project/pbr/>`_ package, which derives it from Git tags.

.. _wexpect.spawn_class_name:

**spawn_class_name**

Contains the default spawn class' name even if the user has not specified it. The value can be
:code:`SpawnPipe` or :code:`SpawnSocket`

.. _wexpect.ConsoleReaderSocket:

**ConsoleReaderSocket**

For advanced users only!
:class:`wexpect.console_reader.ConsoleReaderSocket`

.. _wexpect.ConsoleReaderPipe:

**ConsoleReaderPipe**

For advanced users only!
:class:`wexpect.console_reader.ConsoleReaderPipe`

Wexpect modules
---------------

.. toctree::
:maxdepth: 2

spawn_classes
host
wexpect_util
console_reader
23 changes: 0 additions & 23 deletions doc/source/api/spawn_classes.rst

This file was deleted.

28 changes: 28 additions & 0 deletions doc/source/api/wexpect_util.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Wexpect util
============

.. automodule:: wexpect.wexpect_util

Functions
---------

.. automethod:: wexpect.wexpect_util.str2bool
.. automethod:: wexpect.wexpect_util.spam
.. automethod:: wexpect.wexpect_util.init_logger
.. automethod:: wexpect.wexpect_util.split_command_line
.. automethod:: wexpect.wexpect_util.join_args

ExceptionPexpect
----------------

.. autoclass:: ExceptionPexpect

EOF
---

.. autoclass:: EOF

TIMEOUT
-------

.. autoclass:: TIMEOUT
6 changes: 4 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [ 'sphinx.ext.autodoc'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx'
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -71,7 +73,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = 'default'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down

0 comments on commit 9cdc9a2

Please sign in to comment.