make cvs pserver/ssh(2) connection with python

Chris Liechti cliechti at gmx.net
Sun Jul 7 18:25:24 EDT 2002


"Marc" <m.bohlen at tu-bs.de> wrote in
news:20020708.000822.654887343.4043 at tu-bs.de: 
> Im Artikel <Xns9244E88E74599cliechtigmxnet at 62.2.16.82> schrieb "Chris
> Liechti" <cliechti at gmx.net>:
>> "Marc" <m.bohlen at tu-bs.de> wrote in
>> news:20020707.223646.680466996.4043 at tu-bs.de:
>>> I am searching a way to make a cvs pserver or/and a ssh(protocol
>>> Version 2) connection with python under Linux/Unix. I've tried to
>>> control the cvs pserver
>>> connection by a python frontend which uses the normal cvs binary,
>>> but it won't work without using the 'normal console interaction' for
>>> input (maintainly the cvs login).
>>> I can get the inputstream, but I can't write correctly to the
>>> outputstream. I get the password query, but the answer fails.
>>> Perhaps someone have experience in writing a frontend for
>>> interactive programms under Linux/Unix and can help me.
>> 
>> do you use popen? something like that:
>>>>> i,o = os.popen2("cat - >tmp")
>>>>> i.write("hello")
>>>>> i.close()
>>>>> o.close()
> At this time I use this:
> os.popen(command)
> 
> The Problem isn't the reading and writing input-/outputstream, it's
> the timing(I think).

well it is when you're using only popen. it supports either reading or 
writing but not both at the same time.

> I make a 'cvs login' then I'll be asked for the
> cvs password and the answer of this question fails. Perhaps I've to
> use the tty or ptty module of python, but I don't know how. I'm
> searching a way to handle his problem. I hope someone had similar
> problem (i.e. by writing a frontend for ftp,telnet,ssh,... (for
> interactive applications)). 
> 
> the Python version is 1.5.2 (I think! It is a pool with 20(?)
> workstations, different OS (Linux and Solaris, different versions)).
> I think popen2 is available python-version>2 and if it exists another
> way (as upgrade Pyhon) to solve the problem I'll use that way.

i think the popen2 module is available in 1.5.2 and it provides popen2 (it 
should, given the module name ;-) however the semantics are slightly 
different.

> Insteat, if you know a way to solve my problem by useing popen2 please
> give me a short example.

basicaly you need to read until you find the prompt on the o stream and 
then write the passwd on the i stream.
(untested:)

i,o = os.popen2('cvs -d%s login' % CVSROOT)
while 1:
  if o.readline().strip().endswith('password:'):
    	i.write("secret\n")
    	break
print o.read()    	#read the reset of the output
i.close()
o.close()

in the telnetlib you'll find more andvanced functions like read_until() 
etc. which you could probably adapt for your problem if readline isn't good 
enough.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list