Commits

Robert Brewer committed 2ef30a2

run.py now takes a config arg, which must be a JSON file

Comments (0)

Files changed (2)

+import simplejson
+import optparse
 import os
 thisdir = os.path.abspath(os.path.dirname(__file__))
+import sys
 
 import cherrypy
 from cherrypy.process import plugins
 def run(config):
     flowrate.set_db(
         'postgresql://%(user)s:%(password)s@%(host)s:%(port)s/%(database)s' %
-        config.db_info, echo=False, max_overflow=10, strategy='threadlocal')
+        config['db_info'], echo=False, max_overflow=10, strategy='threadlocal')
     
     cherrypy.engine.timeout_monitor.unsubscribe()
     
     appconf = {
         'global': {
-            'server.socket_port': getattr(config, 'port', 8090),
-            'server.socket_host': getattr(config, 'host', '127.0.0.1'),
+            'server.socket_port': config.get('port', 8090),
+            'server.socket_host': config.get('host', '127.0.0.1'),
         },
         '/': {
             'tools.cpstats.on': True,
             'request.dispatch': cherrypy.dispatch.Dispatcher(),
         },
     }
-    cpenv = getattr(config, 'environment', 'development')
+    cpenv = config.get('environment', 'development')
     if cpenv != 'development':
         appconf['global']['environment'] = cpenv
 
     cherrypy.quickstart(flowrate.root, '/', appconf)
 
 
+usage = 'flowrate/run.py <config>'
+
+
 if __name__ == '__main__':
-    from flowrate.testing import config
+    parser = optparse.OptionParser(prog='flowrate/run.py', usage=usage)
+    options, args = parser.parse_args(sys.argv[1:])
+
+    if len(args) != 1:
+        parser.error("You must supply a config file path.")
+
+    config = simplejson.loads(open(args[0], 'rb').read())
     run(config)
 

flowrate/testing/config.py

-cluster_info = {
+{"cluster_info": {
     "host": "localhost",
     "superuser": "postgres",
     "template": "template1",
-    "port": 5434,
-    }
-
-db_info = {
+    "port": 5434
+    },
+ "db_info": {
     "host": "localhost",
-    "database": "flowrate_fu",
+    "database": "flowrate",
     "user": "postgres",
     "password": "",
-    "port": 5434,
-    }
+    "port": 5434
+    },
+ "port": 8090
+}
 
-port = 8090
-