1

I would need little help here. I'm trying to get the git respository from my corporate server via ssh.

the command to run is git clone ssh://username@someserver.com/somefile.git/

I'm a newbie to python programming and looking out for some assistance.

def getRepository():
    command =  'ssh://username@someserver.com/somefile.git'
    clone_process = subprocess.Popen(['git','clone',command],stdin = subprocess.PIPE, stdout = subprocess.PIPE,stderr=subprocess.PIPE)
    output,error = clone_process.communicate(input='password') 


if  __name__ == '__main__':
    getRepository()

During this process, it prompts for user password which I thought communicate(input='password') would take care but it does not.

Actually it takes some time to prompt for password and I have to read that line before I give the password as input. How do I achieve this?

I tried writing the stdout in a file and read the file till I get that line but that too did not work..

Also, when I enter the password manually I don't see the progress of downloading on the terminal. is there a way to get that too?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user596922
  • 1,501
  • 3
  • 18
  • 27
  • `pexpect` module can help you – avasal Jun 26 '12 at 07:18
  • You could take a look at the [`mr.developer` source code](https://github.com/fschulze/mr.developer/tree/master/src/mr/developer); that package manages git, hg, svn and bazaar checkouts from Python. At least the SVN plugin handles username and password prompting as well. – Martijn Pieters Jun 26 '12 at 08:37

2 Answers2

1

Use pexpect module to provide interactive inputs

See one of my previous example for the answer: Simplest way to run expect script from python

Community
  • 1
  • 1
pyfunc
  • 65,343
  • 15
  • 148
  • 136
  • Thanks Pyfunc.. I have used the pexpect module but stuck with an issue which i have put it on the following thread.. http://stackoverflow.com/questions/11208931/need-little-assistance-with-pexpect-module – user596922 Jun 26 '12 at 14:29
0

You can also use Paramiko module with a very nice API

Community
  • 1
  • 1
VGO
  • 2,161
  • 2
  • 17
  • 14