0

I know, I want always more!

I am wondering how I can do something like this in fabric:

def deploy():
   local('git pull origin dev')
   gitusername = "test"
   gitpwd = "testpassword"
   # here render credentials to stdin so that no need to type in in console

   local('python manage.py collectstatic')       
   confirm_type = "yes"
   # here render 'confirm_type' to stdin so that I dont have to type in console

   local('python manage.py migrate')
   local('/etc/init.d/nginx restart')

I thought of fabric.operations.prompt but I dont need prompt. I want that fabric reads the credentials from variables and goes on further without asking me anything..

any ideas?

doniyor
  • 36,596
  • 57
  • 175
  • 260

1 Answers1

2

As stated in fabric's documentation, use subprocess to send data via stdin (used code from "how do i write to a python subprocess' stdin"):

from subprocess import Popen, PIPE, STDOUT
p = Popen(['python', 'manage.py', 'collectstatic'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
stdout_data = p.communicate(input='yes')[0]

Remove the stdout, stderr parameters if you want to see the output.

Also, in case of collectstatic you can just specify a --noinput parameter without playing with pipes.

Community
  • 1
  • 1
Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31