0

So we have our software product, which I'm currently working on a way to automate its installation. The way it will be done is:

  • I have a config.cfg file, which has all the information about Apache, Tomcat and MySQL's user and password, as well as port numbers.
  • I use ConfigParser to have that information available.

The installer script is iterative: you execute it like sudo foo.run and it prompts the command line so the person doing the installation can enter the inputs mentioned above. For example:

Apache user: **[foo]** 
Apache password: **[bar]**

and after that information is entered, the installer actually installs the product. However, I want to automate the full process, including inputting those informations using Python.

So far I came with this:

  1 from subprocess import Popen, call, PIPE, STDOUT
  2 import errno
  3 import os
  4 fname = "/home/ec2-user/foo.run"
  5 os.chmod(fname, 0777) # make it executable
  6 cmd = "sudo %s" % fname
  7 print cmd
  9 p = Popen(cmd, stdin=PIPE, stdout=PIPE,
 10           stderr=STDOUT, shell=True)
 11 # now is actually the missing part ... reading from the stdout and writing
 12 # to stdin ... how could I accomplish that? Is there a easier way of doing it?
 13 p.wait()

So I'm having a little trouble designing how that stdin / stdout part would work ... I need a while loop to read from it until stdout is empty, and then I would inject the data contained in ConfigParser. Could someone please give an example how that could be done? Is there any other easier way of doing it? I'm open to any suggestions ... A first step for me could be doing a manual installer from python, using Python's p.stdin.write() to give the informations to the installer.

cybertextron
  • 10,547
  • 28
  • 104
  • 208
  • 2
    Use [pexpect](http://www.noah.org/wiki/pexpect) instead of subprocess to run the program. Its job is to run interactive command line programs from python and the reference has examples you can use to make it go. – tdelaney Dec 28 '13 at 15:24
  • seems odd to have an installer that demands manual input and then to have to do various twisty stuff to automatically provide that manual input. The place I work has python based products too. They install automatically and use shell scripts to configure apache, mysql etc – Vorsprung Dec 28 '13 at 16:00
  • You should use pexpect, or even better just rethink your `foo.run` installer to get those parameters directly from your config file. – Alexandru Chirila Dec 28 '13 at 22:40

0 Answers0