setup_pg.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import subprocess
  3. import sys
  4. import time
  5. bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
  6. python = os.path.expanduser(os.path.join(bin_dir, 'python'))
  7. pip = os.path.expanduser(os.path.join(bin_dir, 'pip'))
  8. cwd = os.path.expanduser('~/FrameworkBenchmarks/tornado')
  9. def start(args, logfile, errfile):
  10. subprocess.call(pip + ' install -r requirements.txt', cwd=cwd, shell=True, stderr=errfile, stdout=logfile)
  11. subprocess.Popen(
  12. python + ' server.py --port=8080 --postgres=%s --logging=error' % (args.database_host,),
  13. shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
  14. return 0
  15. def stop(logfile, errfile):
  16. for line in subprocess.check_output(['ps', 'aux']).splitlines():
  17. if 'server.py --port=8080' in line:
  18. pid = int(line.split(None, 2)[1])
  19. os.kill(pid, 9)
  20. return 0
  21. if __name__ == '__main__':
  22. class DummyArg:
  23. database_host = 'localhost'
  24. start(DummyArg(), sys.stderr, sys.stderr)
  25. time.sleep(1)
  26. stop(sys.stderr, sys.stderr)