Vijay
Vijay

Reputation: 1807

Need suggestions to get the git clone work from a ssh server using python script

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://[email protected]/somefile.git/

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

def getRepository():
    command =  'ssh://[email protected]/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?

Upvotes: 1

Views: 994

Answers (2)

VGO
VGO

Reputation: 2201

You can also use Paramiko module with a very nice API

Upvotes: 0

pyfunc
pyfunc

Reputation: 66709

Use pexpect module to provide interactive inputs

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

Upvotes: 1

Related Questions