From 2a8bf2735b96e6c0d4b749c1672c3e549735de3c Mon Sep 17 00:00:00 2001 From: Zader Zheng Date: Sat, 18 Apr 2015 00:07:09 +0800 Subject: add setting support for server --- .gitignore | 1 + lab_monitor_server.py | 11 ++++++++--- server_settings.example.cfg | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 server_settings.example.cfg diff --git a/.gitignore b/.gitignore index 2e05134..f6e17d4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .*.swo *.socket client_settings.sh +server_settings.cfg venv/ diff --git a/lab_monitor_server.py b/lab_monitor_server.py index 1c664cd..91bdbb9 100644 --- a/lab_monitor_server.py +++ b/lab_monitor_server.py @@ -8,6 +8,7 @@ from tornado import gen from tornado.ioloop import IOLoop from tornado.web import RequestHandler, Application, url, StaticFileHandler from rwlock import RWLock +from ConfigParser import SafeConfigParser class ActionError(Exception): pass @@ -129,12 +130,14 @@ class AJAXHandler(RequestHandler): yield gen.Task(grab_lock, self) if __name__ == '__main__': + config = SafeConfigParser() + config.read('server_settings.cfg') logging.basicConfig(level=logging.DEBUG, format='[%(levelname)-7s] (%(threadName)-10s) %(message)s',) MAX_LENGTH = 65536 MAX_RECORDS = 32 - PORT = 2333 - SOCKET_PORT = 2334 + HTTP_PORT = config.get('HTTP', 'port') or 2333 + SOCKET_PORT = config.get('socket', 'port') or 2334 HOST = '' lock = RWLock() @@ -151,11 +154,13 @@ if __name__ == '__main__': cmd = threading.Thread(target=command_server, name="local") cmd.setDaemon(True) cmd.start() + try: app = Application([url(r"/ajax", AJAXHandler), url(r'/()', StaticFileHandler, {'path': "./static/index.html"}), url(r'/(.*)', StaticFileHandler, {'path': "./static/"})]) - app.listen(PORT) + app.listen(HTTP_PORT) IOLoop.current().start() except KeyboardInterrupt: cmd_shutdown() + diff --git a/server_settings.example.cfg b/server_settings.example.cfg new file mode 100644 index 0000000..387b054 --- /dev/null +++ b/server_settings.example.cfg @@ -0,0 +1,4 @@ +[HTTP] + port: 2333 +[socket] + port: 2334 -- cgit v1.2.3-70-g09d2