Pexpect

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(build package)
(installing)
Line 46: Line 46:
 
  ipkg files python-pexpect
 
  ipkg files python-pexpect
 
  ipkg files python-io
 
  ipkg files python-io
  export PYTHONPATH="/media/card/ipkg/usr/lib/python2.5/site-packages/:/media/card/ipkg/usr/lib/python2.5/lib-dynload/:/media/card/ipkg/usr/lib/python2.5/"
+
  export PYTHONPATH="/media/card/ipkg/usr/lib/python2.5/site-packages/: \
 +
/media/card/ipkg/usr/lib/python2.5/lib-dynload/:/media/card/ipkg/usr/lib/python2.5/"
  
 
* verify the pexpect module
 
* verify the pexpect module

Revision as of 09:25, 26 November 2007

Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect allows your script to spawn a child application and control it as if a human were typing commands. Pexpect 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. The Pexpect interface was designed to be easy to use.


Contents

Download

Download the current version from sourceforge site.

installing pexpect

  1. download pexpect-2.1.tar.gz
  2. tar zxf pexpect-2.1.tar.gz
  3. cd pexpect-2.1
  4. python setup.py install do this as root

example

Under the pexpect-2.1 directory you should find the examples directory. This is the best way to learn to use Pexpect. See the descriptions of Pexpect Examples.

API document

  • pexpect This is the main module that you want.
  • pxssh Pexpect SSH is an extension of 'pexpect.spawn' that specializes in SSH.

the following are experimental extensions to Pexpect

  • fdpexpect fdpexpect extension of 'pexpect.spawn' that uses an open file descriptor.
  • SCREEN This represents a virtual 'screen'.
  • ANSI This parses ANSI/VT-100 terminal escape codes.
  • FSM This is a finite state machine used by ANSI.

How to use in neo

build package

Download BitBake recipe from here. Using MokoMakefile tool train:

  • copy this bitbake recipe to python package folder
cp python-pexpect_2.1.bb $OMDIR/openembedded/packages/python
  • use bitbake to build pexpect
bitbake python-pexpect
  • it generates the package files to this folder
$OMDIR/build/tmp/deploy/glibc/ipk/armv4tpython-pexpect_2.1-r0_armv4t.ipk

installing

Using SCP to upload the ipk file to neo

  • install pexpect to card memory, reference from here
ipkg install -d card armv4tpython-pexpect_2.1-r0_armv4t.ipk
  • solve the PYTHON path problem
ipkg files python-pexpect
ipkg files python-io
export PYTHONPATH="/media/card/ipkg/usr/lib/python2.5/site-packages/: \
/media/card/ipkg/usr/lib/python2.5/lib-dynload/:/media/card/ipkg/usr/lib/python2.5/"
  • verify the pexpect module
python -c "import pexpect"
  • some examples:
child = pexpect.spawn('libgsmd-tool -m shell')
child.sendline('O')
child.expect(['Power-On','ERROR','OK'])
Personal tools

Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect allows your script to spawn a child application and control it as if a human were typing commands. Pexpect 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. The Pexpect interface was designed to be easy to use.


Download

Download the current version from sourceforge site.

installing pexpect

  1. download pexpect-2.1.tar.gz
  2. tar zxf pexpect-2.1.tar.gz
  3. cd pexpect-2.1
  4. python setup.py install do this as root

example

Under the pexpect-2.1 directory you should find the examples directory. This is the best way to learn to use Pexpect. See the descriptions of Pexpect Examples.

API document

  • pexpect This is the main module that you want.
  • pxssh Pexpect SSH is an extension of 'pexpect.spawn' that specializes in SSH.

the following are experimental extensions to Pexpect

  • fdpexpect fdpexpect extension of 'pexpect.spawn' that uses an open file descriptor.
  • SCREEN This represents a virtual 'screen'.
  • ANSI This parses ANSI/VT-100 terminal escape codes.
  • FSM This is a finite state machine used by ANSI.

How to use in neo

build package

Download BitBake recipe from here. Using MokoMakefile tool train:

  • copy this bitbake recipe to python package folder
cp python-pexpect_2.1.bb $OMDIR/openembedded/packages/python
  • use bitbake to build pexpect
bitbake python-pexpect
  • it generates the package files to this folder
$OMDIR/build/tmp/deploy/glibc/ipk/armv4tpython-pexpect_2.1-r0_armv4t.ipk

installing

Using SCP to upload the ipk file to neo

  • install pexpect to card memory, reference from here
ipkg install -d card armv4tpython-pexpect_2.1-r0_armv4t.ipk
  • solve the PYTHON path problem
ipkg files python-pexpect
ipkg files python-io
export PYTHONPATH="/media/card/ipkg/usr/lib/python2.5/site-packages/:/media/card/ipkg/usr/lib/python2.5/lib-dynload/:/media/card/ipkg/usr/lib/python2.5/"
  • verify the pexpect module
python -c "import pexpect"
  • some examples:
child = pexpect.spawn('libgsmd-tool -m shell')
child.sendline('O')
child.expect(['Power-On','ERROR','OK'])