diff options
| -rw-r--r-- | pexpect/Makefile | 17 | ||||
| -rw-r--r-- | pexpect/doc/index.template.html | 146 | ||||
| -rw-r--r-- | pexpect/pexpect.py | 43 |
3 files changed, 50 insertions, 156 deletions
diff --git a/pexpect/Makefile b/pexpect/Makefile index 9ed54f0..39e685b 100644 --- a/pexpect/Makefile +++ b/pexpect/Makefile @@ -1,8 +1,9 @@ +# TODO This stupid Makefile is getty crappier and crappier. Is 'crappier' a word? SHELL = /bin/sh VERSION=2.1 #DOCGENERATOR= happydoc -DOCGENERATOR= pydoc -w +DOCGENERATOR=pydoc -w # This is for GNU Make. This does not work on BSD Make. #MANIFEST_LINES := $(shell cat MANIFEST) # This is for BSD Make. This does not work on GNU Make. @@ -13,9 +14,10 @@ all: merge_templates docs dist merge_templates: python tools/merge_templates.py -docs: doc/* -# rm -f pexpect-doc-$(VERSION).tar.gz - -rm -f `ls doc/*.html | sed -e 's/doc\/index\.template\.html//' | sed -e 's/doc\/index\.html//'` +docs: doc/index.template.html doc/examples.html doc/clean.css doc/email.png + make clean_docs + make merge_templates + #-rm -f `ls doc/*.html | sed -e 's/doc\/index\.template\.html//' | sed -e 's/doc\/index\.html//'` #$(DOCGENERATOR) `echo "$(MANIFEST_LINES)" | sed -e "s/\.py//g" -e "s/setup *//" -e "s/README *//"` #mv *.html doc/ cd doc;\ @@ -33,7 +35,7 @@ dist/pexpect-$(VERSION).tar.gz: rm -f dist/pexpect-$(VERSION).tar.gz python setup.py sdist -clean: +clean: clean_docs -rm -f MANIFEST -rm -f *.pyc -rm -f tests/*.pyc @@ -47,9 +49,10 @@ clean: -rm -f pexpect-$(VERSION).tar.gz -rm -f pexpect-$(VERSION)-examples.tar.gz -rm -f pexpect-$(VERSION)-doc.tar.gz - -rm -f `ls doc/*.html | sed -e 's/doc\/index\.template\.html//'` -rm -f python.core -rm -f core -rm -f setup.py -rm -f doc/index.html - + +clean_docs: + -rm -f `ls doc/*.html | sed -e 's/doc\/index\.template\.html//' | sed -e 's/doc\/examples\.html//'` diff --git a/pexpect/doc/index.template.html b/pexpect/doc/index.template.html index 325e758..884f209 100644 --- a/pexpect/doc/index.template.html +++ b/pexpect/doc/index.template.html @@ -76,138 +76,42 @@ http://pexpect.sourceforge.net/ <p>Download the <a href="http://sourceforge.net/project/showfiles.php?group_id=59762"> current version here</a> from the SourceForge site. Grab the current Pexpect tarball. -You should also grab the Pexpect examples tarball as this is the best -way to learn to use Pexpect.</p> +</p> <h2>Installing Pexpect</h2> <p>The Pexpect tarball is a standard Python Distutil distribution.</p> <ol> - <li>download <span class="code">pexpect-VERSION.tgz</span></li> - <li><span class="code">tar zxf pexpect-VERSION.tgz</span></li> + <li>download <span class="code">pexpect-VERSION.tar.gz</span></li> + <li><span class="code">tar zxf pexpect-VERSION.tar.gz</span></li> <li><span class="code">cd pexpect-VERSION</span></li> - <li><span class="code">python setup.py install</span></li> + <li><span class="code">python setup.py install</span> <i>do this as root</i></li> </ol> -<hr noshade="noshade" size="1"> -<h1><a name="doc"></a>Documentation</h1> -<a href="pexpect.html">pexpect.spawn</a> This is the main class that you want.<br> -<a href="pxssh.html">pxssh.ssh</a> Pexpect SSH is an extension of 'pexpect.spawn' that specializes in SSH.<br> -<a href="screen.html">SCREEN</a> This represents a virtual 'screen'.<br> -<a href="ANSI.html">ANSI</a> This parses ANSI/VT-100 terminal escape codes.<br> -<a href="FSM.html">FSM</a> This is a finite state machine used by ANSI.<br> -</p> <h2>Examples</h2> -<p>The Pexpect examples tarball contains -the following scripts that give examples of how Pexpect can be used.<br> +<p> +Under the <span class="code">pexpect-VERSION</span> directory you should find +the <span class="code">examples</span> directory. +This is the best way to learn to use Pexpect. +See the descriptions of <a href="examples.html">Pexpect Examples</a>. </p> +<h2><a name="doc"></a>API Documentation</h2> +<p> <blockquote> -<p><span class="code">script.py</span></p> -<p><blockquote> - This implements a command similar to the classic BSD -"script" command. - This will start a subshell and log all input and -output to a file. - This demonstrates the interact() method of Pexpect. -</p></blockquote> - -<p><span class="code">fix_cvs_files.py</span></p> -<p><blockquote> - This is for cleaning up binary files improperly -added to CVS. - This script scans the given path to find binary -files; - checks with CVS to see if the sticky options are set -to -kb; - finally if sticky options are not -kb then uses 'cvs -admin' to - set the -kb option. -</p></blockquote> - -<p><span class="code">ftp.py</span></p> -<p><blockquote> - This demonstrates an FTP "bookmark". - This connects to an ftp site; does a few ftp stuff; -and then gives the user - interactive control over the session. In this case -the "bookmark" is to a - directory on the OpenBSD ftp server. It puts you in -the i386 packages - directory. You can easily modify this for other -sites. - This demonstrates the interact() method of Pexpect. -</p></blockquote> - -<p><span class="code">monitor.py</span></p> -<p><blockquote> - This runs a sequence of commands on a remote host -using SSH. - It runs a simple system checks such as uptime and -free to monitor - the state of the remote host. -</p></blockquote> - -<p><span class="code">passmass.py</span></p> -<p><blockquote> - This will login to each given server and change the -password of the - given user. This demonstrates scripting logins and -passwords. -</p></blockquote> - -<p><span class="code">python.py</span></p> -<p><blockquote> - This starts the python interpreter and prints the -greeting message backwards. - It then gives the user iteractive control of Python. -It's pretty useless! -</p></blockquote> - -<p><span class="code">rippy.py</span></p> -<p><blockquote> - This is a wizard for mencoder. It greatly simplifies -the process of - ripping a DVD to Divx (mpeg4) format. It can -transcode from any - video file to another. It has options for resampling -the audio stream; - removing interlace artifacts, fitting to a target -file size, etc. - There are lots of options, but the process is simple -and easy to use. -</p></blockquote> - -<p><span class="code">sshls.py</span></p> -<p><blockquote> - This lists a directory on a remote machine. -</p></blockquote> -<p><span class="code">ssh_tunnel.py</span></p> -<p><blockquote> - This starts an SSH tunnel to a remote machine. It -monitors the connection - and restarts the tunnel if it goes down. -</p></blockquote> -<p><span class="code">uptime.py</span></p> -<p><blockquote> - This will run the uptime command and parse the -output into variables. - This demonstrates using a single regular expression -to match the output - of a command and capturing different variable in -match groups. - The regular expression takes into account a wide -variety of different - </blockquote> +<a href="pexpect.html">pexpect</a> This is the main module that you want.<br> +<a href="pxssh.html">pxssh</a> Pexpect SSH is an extension of 'pexpect.spawn' that specializes in SSH.<br> </blockquote> -<p></p> +the following are experimental extensions to Pexpect<br> +<blockquote> +<a href="fdpexpect.html">fdpexpect</a> fdpexpect extension of 'pexpect.spawn' that uses an open file descriptor.<br> +<a href="screen.html">SCREEN</a> This represents a virtual 'screen'.<br> +<a href="ANSI.html">ANSI</a> This parses ANSI/VT-100 terminal escape codes.<br> +<a href="FSM.html">FSM</a> This is a finite state machine used by ANSI.<br> +</blockquote> +</p> <hr noshade="noshade" size="1"> <h1><a name="status"></a>Project Status</h1> -<p>This is mature code. Automated pyunit tests reach over 80% +<p>Automated pyunit tests reach over 80% code coverage on pexpect.py. I regularly test on Linux and BSD -platforms. I occaisonally test on Solaris and Irix. Generally -everything works pretty well. The <a href="#download">examples</a> -tarball has several sample scripts.<br> +platforms. I try to test on Solaris and Irix. </p> -<p>I also built a prototype screen scraper. I have a working ANSI -terminal emulator (VT100 compatible), it is not extensively tested with -real-world applications.</p> <hr noshade="noshade" size="1"> <h1><a name="requirements"></a>Requirements for use of Pexpect</h1> <h2>Python</h2> @@ -274,9 +178,11 @@ the human user.</p> <pre class="code">import pexpect<br>child = pexpect.spawn ('ftp ftp.openbsd.org')<br>child.expect ('Name .*: ')<br>child.sendline ('anonymous')<br>child.expect ('Password:')<br>child.sendline ('noah@example.com')<br>child.expect ('ftp> ')<br>child.sendline ('ls /pub/OpenBSD/')<br>child.expect ('ftp> ')<br>print child.before # Print the result of the ls command.<br>child.interact() # Give control of the child to the user.<br></pre> </blockquote> <h2>Special EOF and TIMEOUT patterns</h2> +<p> There are two special patterns to match the End Of File or a Timeout condition. You you can pass these patterns to <span class="code">expect()</span>. These patterns are not regular expressions. Use them like predefined constants. +</p> <p>If the child has died and you have read all the child's output then ordinarily <span class="code">expect()</span> will raise an <span class="code">EOF</span> exception. You can read everything up to the EOF without generating an @@ -364,7 +270,7 @@ do a NON greedy match (minimal) at the end of a input {### already said this}.</font> </p> <p>Pexpect compiles all regular expressions with the DOTALL flag. With the DOTALL flag a "." will match a newline. See the Python <a - href="http://www.python.org/doc/current/lib/node99.html#l2h-733">documentation</a></p> + href="http://www.python.org/doc/current/lib/node115.html#l2h-733">documentation</a></p> <h2>Beware of + and * at the end of input.</h2> <p>Remember that any time you try to match a pattern that needs look-ahead that you will always get a minimal match (non greedy). For diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py index 2f7ef98..e1f680b 100644 --- a/pexpect/pexpect.py +++ b/pexpect/pexpect.py @@ -29,27 +29,11 @@ This works even for commands that ask for passwords or other input outside of the normal stdio streams. Credits: - Noah Spurrier - Richard Holden - Marco Molteni - Kimberley Burchett - Robert Stone - Mike Snitzer - Marti Raudsepp - Matt (<matt (*) corvil.com>) - Hartmut Goebel - Chad Schroeder - Erick Tryzelaar - Dave Kirby - Ids vander Molen - George Todd - Noel Taylor - Nicolas D. Cesar - Alexander Gattin - Geoffrey Marshall - Francisco Lourenco - Glen Mabey - Karthik Gurusamy +Noah Spurrier, Richard Holden, Marco Molteni, Kimberley Burchett, Robert Stone, +Hartmut Goebel, Chad Schroeder, Erick Tryzelaar, Dave Kirby, Ids vander Molen, +George Todd, Noel Taylor, Nicolas D. Cesar, Alexander Gattin, +Geoffrey Marshall, Francisco Lourenco, Glen Mabey, Karthik Gurusamy, +Fernando Perez (Let me know if I forgot anyone.) Free, open source, and all that good stuff. @@ -1021,15 +1005,15 @@ class spawn (object): return compiled_pattern_list def expect(self, pattern, timeout = -1, searchwindowsize=None): + """This seeks through the stream until a pattern is matched. The pattern is overloaded and may take several types including a list. - The pattern can be a StringType, EOF, a compiled re, or - a list of those types. Strings will be compiled to re types. - This returns the index into the pattern list. If the pattern was - not a list this returns index 0 on a successful match. - This may raise exceptions for EOF or TIMEOUT. - To avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to - the pattern list. + The pattern can be a StringType, EOF, a compiled re, or a list of + those types. Strings will be compiled to re types. This returns the + index into the pattern list. If the pattern was not a list this + returns index 0 on a successful match. This may raise exceptions for + EOF or TIMEOUT. To avoid the EOF or TIMEOUT exceptions add + EOF or TIMEOUT to the pattern list. After a match is found the instance attributes 'before', 'after' and 'match' will be set. @@ -1081,7 +1065,7 @@ class spawn (object): def expect_list(self, pattern_list, timeout = -1, searchwindowsize = -1): """This takes a list of compiled regular expressions and returns - the index into the pattern_list that matched the child's output. + the index into the pattern_list that matched the child output. The list may also contain EOF or TIMEOUT (which are not compiled regular expressions). This method is similar to the expect() method except that expect_list() does not @@ -1091,6 +1075,7 @@ class spawn (object): If timeout==-1 then the self.timeout value is used. If searchwindowsize==-1 then the self.searchwindowsize value is used. """ + self.patterns = pattern_list if timeout == -1: |
