1. Marcin Lulek
  2. gevent_cometd

Commits

Marcin Lulek  committed ac3312d

add support for ini file configuration

  • Participants
  • Parent commits 66595f8
  • Branches default

Comments (0)

Files changed (2)

File config.ini

View file
+[gevent_cometd]
+port = 8088
+secret = test123
+admin_secret = admin123
+allow_posting_from = 127.0.0.1,
+                     123.111.222.123,
+                     1.2.3.4
+                     

File gevent_cometd/start.py

View file
 import gevent_cometd.app_views as app_views
 import logging
 import optparse
+import ConfigParser
 
 from geventwebsocket.handler import WebSocketHandler
 from gevent_cometd import config
 
 def cli_start():
     parser = optparse.OptionParser()
+    parser.add_option("-i", "--ini", dest="ini",
+                  help="config file location",
+                  default=None
+                  )
     parser.add_option("-s", "--secret", dest="secret",
                   help="secret used to secure your requests",
                   default='secret'
                   default="127.0.0.1"
                   )
     (options, args) = parser.parse_args()
-    config['port'] = int(options.port)
-    config['secret'] = options.secret
-    config['admin_secret'] = options.admin_secret
-    config['allow_posting_from'] = [ip.strip() for ip in options.allow_posting_from.split(',')]
+    if options.ini:
+        parser = ConfigParser.ConfigParser()
+        parser.read(options.ini)
+        config['port'] = parser.getint('gevent_cometd', 'port')
+        config['secret'] = parser.get('gevent_cometd', 'secret')
+        config['admin_secret'] = parser.get('gevent_cometd', 'admin_secret')
+        ips = [ip.strip() for ip in parser.get('gevent_cometd',
+                                               'allow_posting_from').split(',')]
+        config['allow_posting_from'].extend(ips)
+        print config
+    else:
+        config['port'] = int(options.port)
+        config['secret'] = options.secret
+        config['admin_secret'] = options.admin_secret
+        config['allow_posting_from'].extend([ip.strip() for ip in options.allow_posting_from.split(',')])
+
     print 'Serving on 0.0.0.0:%s' % config['port']
     app = WSGIRouter()
     pywsgi.WSGIServer(('', config['port']), app, log=None,