Logging into CVS using Python

Albert Hofkamp hat at se-46.wpa.wtb.tue.nl
Tue Apr 8 11:16:03 EDT 2003


On Tue, 8 Apr 2003 10:47:13 -0400, Mike <uptonothing at yahoo.com> wrote:
> How do I use Python to login into CVS? Here's what I have tried, but it has
> failed. I'm not even sure that I'm using the correct methods.

Doing 'cvs -d :pserver:mike at server.com:1000/path/to/CVS login' on the
command-line should work. If it does, the method is correct :-)

> import popen2
> 
> pipe_in, pipe_out = popen2.popen2("cvs -d
>:pserver:mike at server.com:1000/path/to/CVS login")

If mike and PASSWORD are a correct combination at server.com, it may be
easier to convince rsh or ssh to log you in without entering a password.
That also has the advantage of not having your password in a Python file.

> 
> s = pipe_in.readline()
> 
> print s
> 
> pipe_out.write("PASSWORD")
> 
> pipe_out.flush()
> 
> pipe_in.close()
> pipe_out.close()
> 
> The code just results in "cvs login: authorization failed." Any help would
> be appreciated.

Two things may be wrong (or maybe even both are wrong):
- cvs asks for the password using /dev/tty, which is directly to your
  terminal, instead of through your pipe.
- After the flush(), you close the pipe. This means that cvs at the other
  end has no stdin or stdout any more.
  On unix, this usually means that the process is killed. This may even be
  happening before PASSWORD is received at the other end.

You may want to have a look at the pexpect package, which is built to do
what you are trying to do (i.e. running an interactive session through a
pipe). I have very good experiences with it.



Albert
-- 
Unlike popular belief, the .doc format is not an open publically available format.




More information about the Python-list mailing list