2019-04-24 14:32:02 +00:00
|
|
|
# **wexpect**
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
*Wexpect* is a Windows variant of [pexpect](https://pexpect.readthedocs.io/en/stable/).
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
*Pexpect* is a Python module for spawning child applications and controlling
|
|
|
|
them automatically.
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-05-05 15:54:10 +00:00
|
|
|
**!! UPDATE !!**
|
|
|
|
|
|
|
|
I'm glad to announce that python-3 is supported form version 2.3.3
|
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
## **Install**
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
pip install wexpect
|
|
|
|
|
|
|
|
## **Usage**
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
To interract with a child process use `spawn` method:
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-05-05 15:54:10 +00:00
|
|
|
```python
|
|
|
|
import wexpect
|
|
|
|
child = wexpect.spawn('cmd.exe')
|
|
|
|
child.expect('>')
|
|
|
|
child.sendline('ls')
|
|
|
|
child.expect('>')
|
|
|
|
print(child.before)
|
|
|
|
```
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
For more information see [examples](./examples) folder.
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
---
|
|
|
|
## What is it?
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
Wexpect is a Python module for spawning child applications and controlling
|
|
|
|
them automatically. Wexpect can be used for automating interactive applications
|
|
|
|
such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup
|
|
|
|
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.
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
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
|
|
|
|
tasks are easy.
|
2019-04-24 08:10:16 +00:00
|
|
|
|
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
### History
|
2019-04-24 10:09:19 +00:00
|
|
|
|
2019-04-24 14:32:02 +00:00
|
|
|
Wexpect is a one-file code developed at University of Washington. There are several
|
|
|
|
[copy](https://gist.github.com/anthonyeden/8488763) and
|
|
|
|
[reference](https://mediarealm.com.au/articles/python-pexpect-windows-wexpect/)
|
|
|
|
to this code with very few (almost none) documentation nor integration.
|
|
|
|
|
|
|
|
This repo tries to fix these limitations, with a few example code and pypi integration.
|
2019-04-24 10:09:19 +00:00
|
|
|
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 13:11:09 +00:00
|
|
|
---
|
2019-05-05 15:54:10 +00:00
|
|
|
## Installation of wexpect
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 13:11:09 +00:00
|
|
|
### Standard installation
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 13:11:09 +00:00
|
|
|
This version is uploaded to pypi server so you can easily install with pip:
|
|
|
|
|
|
|
|
pip install wexpect
|
2019-04-24 08:10:16 +00:00
|
|
|
|
2019-04-24 13:11:09 +00:00
|
|
|
### Manual installation
|
|
|
|
|
|
|
|
Because this is a tiny project dropping the wexpect.py file into your working directory is usually
|
|
|
|
good enough instead of installing. However in this case you need to install manually the one dependence.
|
|
|
|
|
|
|
|
One (non stanbdard) package, **pypiwin32** is needed by wexpect.
|
|
|
|
|
|
|
|
pip install pypiwin32
|
2019-05-05 15:54:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
## Dev
|
|
|
|
|
|
|
|
Thanks for any contributing!
|
|
|
|
|
2019-07-29 12:21:26 +00:00
|
|
|
### Test
|
|
|
|
|
2019-05-05 15:54:10 +00:00
|
|
|
To run test, enter into the folder of the wexpect's repo then:
|
|
|
|
|
2019-07-29 12:21:26 +00:00
|
|
|
`python -m unittest`
|
|
|
|
|
|
|
|
Note that `tests.test_constructor.TestCaseConstructor.test_constructor` test fails due to
|
|
|
|
[STDERR isn't handled properly #2](https://github.com/raczben/wexpect/issues/2).
|
|
|
|
|
|
|
|
### Release
|
|
|
|
|
|
|
|
The wexpect uses [pbr](https://docs.openstack.org/pbr/latest/) for managing releasing procedures.
|
|
|
|
*Pre-release tasks:*
|
|
|
|
|
|
|
|
- First of all be sure that your modification is good, by running the tests.
|
|
|
|
- Commit your modification.
|
|
|
|
- Create a test build `python -m setup sdist`
|
|
|
|
- Upload the test `twine upload -r testpypi dist\wexpect-<VERSION>.tar.gz` (You must install twine first.)
|
|
|
|
- create virtualenv `virtualenv wexpectPy`
|
|
|
|
- Activate the virtualenv `.\Scripts\activate.bat`
|
|
|
|
- Install the test build `python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple wexpect`
|
|
|
|
- run `python -c "import wexpect;print(wexpect.__version__)"`
|
|
|
|
|
|
|
|
*Release tasks:*
|
|
|
|
|
|
|
|
- Tag your commit (see the version tag format.)
|
|
|
|
- Run `python -m setup sdist`
|
|
|
|
- Upload the archive using: `twine upload dist/wexpect-<VERSION>.tar.gz`
|
|
|
|
- create virtualenv `virtualenv wexpectPy2`
|
|
|
|
- Activate the virtualenv `.\Scripts\activate.bat`
|
|
|
|
- Install the test build `python -m pip install wexpect`
|
|
|
|
- run `python -c "import wexpect;print(wexpect.__version__)"`
|
|
|
|
|
|
|
|
Test
|
|
|
|
This means that you should r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-05 15:54:10 +00:00
|
|
|
|