from os.path import expanduser
from os import kill
import subprocess
import sys
import time


python = expanduser('~/FrameworkBenchmarks/installs/py2/bin/python')
cwd = expanduser('~/FrameworkBenchmarks/tornado')


def start(args, logfile, errfile):
    subprocess.Popen(
        python + " server.py --port=8080 --postgres=%s --logging=error" % (args.database_host,),
        shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
    return 0

def stop(logfile, errfile):
    for line in subprocess.check_output(["ps", "aux"]).splitlines():
        if 'server.py --port=8080' in line:
            pid = int(line.split(None,2)[1])
            kill(pid, 9)
    return 0

if __name__ == '__main__':
    class DummyArg:
        database_host = 'localhost'
    start(DummyArg(), sys.stderr, sys.stderr)
    time.sleep(1)
    stop(sys.stderr, sys.stderr)

import os
import subprocess
import sys
import time


bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
python = os.path.expanduser(os.path.join(bin_dir, 'python'))
pip = os.path.expanduser(os.path.join(bin_dir, 'pip'))
cwd = os.path.expanduser('~/FrameworkBenchmarks/tornado')


def start(args, logfile, errfile):
    subprocess.call(pip + ' install -r requirements.txt', cwd=cwd, shell=True, stderr=errfile, stdout=logfile)

    subprocess.Popen(
        python + ' server.py --port=8080 --postgres=%s --logging=error' % (args.database_host,),
        shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
    return 0


def stop(logfile, errfile):
    for line in subprocess.check_output(['ps', 'aux']).splitlines():
        if 'server.py --port=8080' in line:
            pid = int(line.split(None, 2)[1])
            os.kill(pid, 9)
    return 0

if __name__ == '__main__':
    class DummyArg:
        database_host = 'localhost'
    start(DummyArg(), sys.stderr, sys.stderr)
    time.sleep(1)
    stop(sys.stderr, sys.stderr)

Call pip install before running server.
Call pip install before running server.

+ import os
- from os.path import expanduser
- from os import kill
  import subprocess
  import sys
  import time
  
  
- python = expanduser('~/FrameworkBenchmarks/installs/py2/bin/python')
+ bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
+ python = os.path.expanduser(os.path.join(bin_dir, 'python'))
+ pip = os.path.expanduser(os.path.join(bin_dir, 'pip'))
- cwd = expanduser('~/FrameworkBenchmarks/tornado')
+ cwd = os.path.expanduser('~/FrameworkBenchmarks/tornado')
  
  
  def start(args, logfile, errfile):
+     subprocess.call(pip + ' install -r requirements.txt', cwd=cwd, shell=True, stderr=errfile, stdout=logfile)
+ 
      subprocess.Popen(
-         python + " server.py --port=8080 --postgres=%s --logging=error" % (args.database_host,),
+         python + ' server.py --port=8080 --postgres=%s --logging=error' % (args.database_host,),
          shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
      return 0
  
+ 
  def stop(logfile, errfile):
-     for line in subprocess.check_output(["ps", "aux"]).splitlines():
+     for line in subprocess.check_output(['ps', 'aux']).splitlines():
          if 'server.py --port=8080' in line:
-             pid = int(line.split(None,2)[1])
+             pid = int(line.split(None, 2)[1])
-             kill(pid, 9)
+             os.kill(pid, 9)
      return 0
  
  if __name__ == '__main__':
      class DummyArg:
          database_host = 'localhost'
      start(DummyArg(), sys.stderr, sys.stderr)
      time.sleep(1)
      stop(sys.stderr, sys.stderr)
  
Call pip install before running server.
## Code Before:
from os.path import expanduser
from os import kill
import subprocess
import sys
import time


python = expanduser('~/FrameworkBenchmarks/installs/py2/bin/python')
cwd = expanduser('~/FrameworkBenchmarks/tornado')


def start(args, logfile, errfile):
    subprocess.Popen(
        python + " server.py --port=8080 --postgres=%s --logging=error" % (args.database_host,),
        shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
    return 0

def stop(logfile, errfile):
    for line in subprocess.check_output(["ps", "aux"]).splitlines():
        if 'server.py --port=8080' in line:
            pid = int(line.split(None,2)[1])
            kill(pid, 9)
    return 0

if __name__ == '__main__':
    class DummyArg:
        database_host = 'localhost'
    start(DummyArg(), sys.stderr, sys.stderr)
    time.sleep(1)
    stop(sys.stderr, sys.stderr)

## Instruction:
Call pip install before running server.
## Code After:
import os
import subprocess
import sys
import time


bin_dir = os.path.expanduser('~/FrameworkBenchmarks/installs/py2/bin')
python = os.path.expanduser(os.path.join(bin_dir, 'python'))
pip = os.path.expanduser(os.path.join(bin_dir, 'pip'))
cwd = os.path.expanduser('~/FrameworkBenchmarks/tornado')


def start(args, logfile, errfile):
    subprocess.call(pip + ' install -r requirements.txt', cwd=cwd, shell=True, stderr=errfile, stdout=logfile)

    subprocess.Popen(
        python + ' server.py --port=8080 --postgres=%s --logging=error' % (args.database_host,),
        shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
    return 0


def stop(logfile, errfile):
    for line in subprocess.check_output(['ps', 'aux']).splitlines():
        if 'server.py --port=8080' in line:
            pid = int(line.split(None, 2)[1])
            os.kill(pid, 9)
    return 0

if __name__ == '__main__':
    class DummyArg:
        database_host = 'localhost'
    start(DummyArg(), sys.stderr, sys.stderr)
    time.sleep(1)
    stop(sys.stderr, sys.stderr)
