OSDN Git Service

add Web API Server options (-I, -L, -D)
authort.moriyama <t.moriyama@users.sourceforge.jp>
Sat, 26 Oct 2013 21:49:14 +0000 (06:49 +0900)
committert.moriyama <t.moriyama@users.sourceforge.jp>
Sat, 26 Oct 2013 21:49:14 +0000 (06:49 +0900)
api_server.py
ti2.py

index 403ec51..66f3ad1 100755 (executable)
@@ -19,9 +19,9 @@ def parse_linkpair_records():
 def start_app(listen='localhost:23456', debug=True):
     app.config.update(
         DEBUG=debug,
-        SERVER_NAME=listen
     )
-    app.run()
+    (conf_host, conf_port) = listen.split(':')
+    app.run(host=conf_host, port=int(conf_port))
 
 
 @app.route("/")
diff --git a/ti2.py b/ti2.py
index 923cb80..69c2531 100755 (executable)
--- a/ti2.py
+++ b/ti2.py
@@ -71,6 +71,12 @@ if __name__ == "__main__":
                  help="import json file as linkpairs", metavar="FILE")
     p.add_option('-a', '--api_server', dest='api_server', action="store_true", default=False,
                  help="enable Web API server")
+    p.add_option('-I', '--collect_interval', dest='collect_interval', type='int', default=30,
+                 help="interval to run the collect task (Web API server, default: 30 sec)")
+    p.add_option('-L', '--listen_address', dest='listen_address', default='localhost:23456',
+                 help="specify the listen address that accepts (Web API server, default: localhost:23456)")
+    p.add_option('-D', '--debug_api_server', dest='debug_api_server', action="store_true", default=False,
+                 help="enable debug mode of Web API server")
     g2 = OptionGroup(p, "Collector Agent flags",
                      "disable Collector Agents")
     g2.add_option(
@@ -134,10 +140,13 @@ if __name__ == "__main__":
         util.message_out(exporter.run())
         sys.exit(0)
     elif opts.api_server:
-        collect_task = CollectTask(collect_func, 30)
+        if opts.collect_interval < 3:
+            util.error_out("Inerval to run the collect task(-I option), please at least 3 seconds")
+            sys.exit(1)
+        collect_task = CollectTask(collect_func, opts.collect_interval)
         collect_task.start()
         api_server.util = util
         api_server.collect_func = collect_func
-        api_server.start_app()
+        api_server.start_app(opts.listen_address, opts.debug_api_server)
     else:
         print_linkpair_records(linkpairs)