Permalink
Browse files

Added a configuration file for the examples.

  • Loading branch information...
FSX committed Dec 15, 2011
1 parent 7fa8614 commit 5cf3b2f63b4c8e528fb6524b898518fb17a525ad
File renamed without changes.
View
@@ -0,0 +1,16 @@
+Examples
+========
+
+To run any of the examples copy the contents of ``database.cfg.example`` into
+a new file called ``database.cfg`` and adjust the settings to your needs.
+
+Then run one of the following examples:
+
+- ``callback_client.py``
+- ``adisp_client.py``
+- ``blocking_client.py``
+- ``gen_example.py``
+- ``swift_example.py`` (you need to install Swift_ first)
+
+
+.. _Swift: http://code.naeseth.com/swirl/
View
@@ -15,13 +15,14 @@ def db(self):
# and store the connection in the application object.
if not hasattr(self.application, 'db'):
self.application.db = momoko.AdispClient({
- 'host': 'localhost',
- 'database': 'momoko',
- 'user': 'frank',
- 'password': '',
- 'min_conn': 1,
- 'max_conn': 20,
- 'cleanup_timeout': 10
+ 'host': settings.host,
+ 'port': settings.port,
+ 'database': settings.database,
+ 'user': settings.user,
+ 'password': settings.password,
+ 'min_conn': settings.min_conn,
+ 'max_conn': settings.max_conn,
+ 'cleanup_timeout': settings.cleanup_timeout
})
return self.application.db
@@ -15,13 +15,14 @@ def db(self):
# and store the connection in the application object.
if not hasattr(self.application, 'db'):
self.application.db = momoko.BlockingClient({
- 'host': 'localhost',
- 'database': 'momoko',
- 'user': 'frank',
- 'password': '',
- 'min_conn': 1,
- 'max_conn': 20,
- 'cleanup_timeout': 10
+ 'host': settings.host,
+ 'port': settings.port,
+ 'database': settings.database,
+ 'user': settings.user,
+ 'password': settings.password,
+ 'min_conn': settings.min_conn,
+ 'max_conn': settings.max_conn,
+ 'cleanup_timeout': settings.cleanup_timeout
})
return self.application.db
@@ -7,6 +7,8 @@
import momoko
+import settings
+
class BaseHandler(tornado.web.RequestHandler):
@property
@@ -15,13 +17,14 @@ def db(self):
# and store the connection in the application object.
if not hasattr(self.application, 'db'):
self.application.db = momoko.AsyncClient({
- 'host': 'localhost',
- 'database': 'momoko',
- 'user': 'frank',
- 'password': '',
- 'min_conn': 1,
- 'max_conn': 20,
- 'cleanup_timeout': 10
+ 'host': settings.host,
+ 'port': settings.port,
+ 'database': settings.database,
+ 'user': settings.user,
+ 'password': settings.password,
+ 'min_conn': settings.min_conn,
+ 'max_conn': settings.max_conn,
+ 'cleanup_timeout': settings.cleanup_timeout
})
return self.application.db
@@ -0,0 +1,11 @@
+# See API documentation for information about these settings
+
+[default]
+host=localhost
+port=5432
+database=momoko
+user=frank
+password=
+min_conn=1
+max_conn=20
+cleanup_timeout=10
@@ -1,5 +1,12 @@
#!/usr/bin/env python
+"""
+This example uses Tornado's gen_.
+
+.. _gen: http://www.tornadoweb.org/documentation/gen.html
+"""
+
+
import tornado.httpserver
import tornado.ioloop
import tornado.options
@@ -16,13 +23,14 @@ def db(self):
# and store the connection in the application object.
if not hasattr(self.application, 'db'):
self.application.db = momoko.AsyncClient({
- 'host': 'localhost',
- 'database': 'momoko',
- 'user': 'frank',
- 'password': '',
- 'min_conn': 1,
- 'max_conn': 20,
- 'cleanup_timeout': 10
+ 'host': settings.host,
+ 'port': settings.port,
+ 'database': settings.database,
+ 'user': settings.user,
+ 'password': settings.password,
+ 'min_conn': settings.min_conn,
+ 'max_conn': settings.max_conn,
+ 'cleanup_timeout': settings.cleanup_timeout
})
return self.application.db
View
@@ -0,0 +1,32 @@
+from os import path
+
+try:
+ import ConfigParser as configparser
+except ImportError:
+ import configparser # Python 3
+
+
+__all__ = [
+ 'host',
+ 'port',
+ 'database',
+ 'user',
+ 'password',
+ 'min_conn',
+ 'max_conn',
+ 'cleanup_timeout'
+]
+
+
+config = configparser.ConfigParser()
+config.read(path.join(path.dirname(__file__), 'database.cfg'))
+
+
+host = config.get('default', 'host')
+port = config.getint('default', 'port')
+database = config.get('default', 'database')
+user = config.get('default', 'user')
+password = config.get('default', 'password')
+min_conn = config.getint('default', 'min_conn')
+max_conn = config.getint('default', 'max_conn')
+cleanup_timeout = config.getint('default', 'cleanup_timeout')
View
@@ -23,13 +23,14 @@ def db(self):
# and store the connection in the application object.
if not hasattr(self.application, 'db'):
self.application.db = momoko.AsyncClient({
- 'host': 'localhost',
- 'database': 'momoko',
- 'user': 'frank',
- 'password': '',
- 'min_conn': 1,
- 'max_conn': 20,
- 'cleanup_timeout': 10
+ 'host': settings.host,
+ 'port': settings.port,
+ 'database': settings.database,
+ 'user': settings.user,
+ 'password': settings.password,
+ 'min_conn': settings.min_conn,
+ 'max_conn': settings.max_conn,
+ 'cleanup_timeout': settings.cleanup_timeout
})
return self.application.db

0 comments on commit 5cf3b2f

Please sign in to comment.