Pexpect

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(catchg)
(catchg)
 
(2 intermediate revisions by 2 users not shown)
Line 10: Line 10:
 
# cd pexpect-2.1
 
# cd pexpect-2.1
 
# python setup.py install do this as root
 
# python setup.py install do this as root
 +
 +
Note that debian unstable already has pexpect 2.3 which you can get with
 +
apt-get install python-pexpect
  
 
===example===
 
===example===
Line 59: Line 62:
 
{{note| we may consider to use pexpect to do some auto tests for GSM functions  }}
 
{{note| we may consider to use pexpect to do some auto tests for GSM functions  }}
  
[[Category:Openmoko]]
+
[[Category:Middleware]]
[[Category:Application Developer]]
+

Latest revision as of 08:49, 19 July 2009

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

[edit] Download

Download the current version from sourceforge site.

[edit] 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

Note that debian unstable already has pexpect 2.3 which you can get with

apt-get install python-pexpect

[edit] 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.

[edit] 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.

[edit] How to use in neo

[edit] 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

[edit] 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'])
NOTE: we may consider to use pexpect to do some auto tests for GSM functions
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'])
NOTE: we may consider to use pexpect to do some auto tests for GSM functions