Browse Source

tornado: Fix setup scripts.

INADA Naoki 11 years ago
parent
commit
35809fa331
4 changed files with 48 additions and 27 deletions
  1. 2 1
      tornado/server.py
  2. 14 8
      tornado/setup.py
  3. 16 9
      tornado/setup_py3.py
  4. 16 9
      tornado/setup_pypy.py

+ 2 - 1
tornado/server.py

@@ -13,6 +13,7 @@ if sys.version_info[0] == 3:
     xrange = range
     xrange = range
 
 
 tornado.options.define('port', default=8888, type=int, help="Server port")
 tornado.options.define('port', default=8888, type=int, help="Server port")
+tornado.options.define('mongo', default='localhost', type=str, help="MongoDB host")
 
 
 
 
 class BaseHandler(tornado.web.RequestHandler):
 class BaseHandler(tornado.web.RequestHandler):
@@ -64,5 +65,5 @@ if __name__ == "__main__":
     server = tornado.httpserver.HTTPServer(application)
     server = tornado.httpserver.HTTPServer(application)
     server.bind(options.port)
     server.bind(options.port)
     server.start(0)
     server.start(0)
-    db = motor.MotorClient("localhost").open_sync().hello_world
+    db = motor.MotorClient(options.mongo).open_sync().hello_world
     tornado.ioloop.IOLoop.instance().start()
     tornado.ioloop.IOLoop.instance().start()

+ 14 - 8
tornado/setup.py

@@ -1,24 +1,30 @@
-import subprocess
-import setup_util
 from os.path import expanduser
 from os.path import expanduser
 from os import kill
 from os import kill
+import subprocess
+import sys
+import time
+
 
 
 python = expanduser('~/FrameworkBenchmarks/installs/py2/bin/python')
 python = expanduser('~/FrameworkBenchmarks/installs/py2/bin/python')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 
 
 
 
 def start(args, logfile, errfile):
 def start(args, logfile, errfile):
-    setup_util.replace_text(
-        cwd + "/server.py", "localhost", args.database_host)
-
     subprocess.Popen(
     subprocess.Popen(
-        python + " server.py --port=8080 --logging=error",
+        python + " server.py --port=8080 --mongo=%s --logging=error" % (args.database_host,),
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
     return 0
     return 0
 
 
 def stop(logfile, errfile):
 def stop(logfile, errfile):
-    for line in subprocess.check_output("ps aux"):
-        if 'FrameworkBenchmarks/installs/py2/bin/python server.py --port=8080 --logging=error' in line:
+    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)
             kill(pid, 9)
     return 0
     return 0
+
+if __name__ == '__main__':
+    class DummyArg:
+        database_host = 'localhost'
+    start(DummyArg(), sys.stderr, sys.stderr)
+    time.sleep(1)
+    stop(sys.stderr, sys.stderr)

+ 16 - 9
tornado/setup_py3.py

@@ -1,23 +1,30 @@
-import subprocess
-import setup_util
 from os.path import expanduser
 from os.path import expanduser
+from os import kill
+import subprocess
+import sys
+import time
+
 
 
 python = expanduser('~/FrameworkBenchmarks/installs/py3/bin/python3')
 python = expanduser('~/FrameworkBenchmarks/installs/py3/bin/python3')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 
 
 
 
 def start(args, logfile, errfile):
 def start(args, logfile, errfile):
-    setup_util.replace_text(
-        cwd + "/server.py", "localhost", args.database_host)
-
     subprocess.Popen(
     subprocess.Popen(
-        python + " server.py --port=8080 --logging=error",
+        python + " server.py --port=8080 --mongo=%s --logging=error" % (args.database_host,),
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
     return 0
     return 0
 
 
 def stop(logfile, errfile):
 def stop(logfile, errfile):
-    for line in subprocess.check_output("ps aux"):
-        if "installs/py3/bin/python3" in line:
+    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])
-            os.kill(pid, 9)
+            kill(pid, 9)
     return 0
     return 0
+
+if __name__ == '__main__':
+    class DummyArg:
+        database_host = 'localhost'
+    start(DummyArg(), sys.stderr, sys.stderr)
+    time.sleep(1)
+    stop(sys.stderr, sys.stderr)

+ 16 - 9
tornado/setup_pypy.py

@@ -1,23 +1,30 @@
-import subprocess
-import setup_util
 from os.path import expanduser
 from os.path import expanduser
+from os import kill
+import subprocess
+import sys
+import time
+
 
 
 python = expanduser('~/FrameworkBenchmarks/installs/pypy/bin/pypy')
 python = expanduser('~/FrameworkBenchmarks/installs/pypy/bin/pypy')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 cwd = expanduser('~/FrameworkBenchmarks/tornado')
 
 
 
 
 def start(args, logfile, errfile):
 def start(args, logfile, errfile):
-    setup_util.replace_text(
-        cwd + "/server.py", "localhost", args.database_host)
-
     subprocess.Popen(
     subprocess.Popen(
-        python + " server.py --port=8080 --logging=error",
+        python + " server.py --port=8080 --mongo=%s --logging=error" % (args.database_host,),
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
         shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
     return 0
     return 0
 
 
 def stop(logfile, errfile):
 def stop(logfile, errfile):
-    for line in subprocess.check_output("ps aux"):
-        if "installs/pypy/bin/pypy" in line:
+    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])
-            os.kill(pid, 9)
+            kill(pid, 9)
     return 0
     return 0
+
+if __name__ == '__main__':
+    class DummyArg:
+        database_host = 'localhost'
+    start(DummyArg(), sys.stderr, sys.stderr)
+    time.sleep(1)
+    stop(sys.stderr, sys.stderr)