Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2010 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehiah/595574 to your computer and use it in GitHub Desktop.
Save jehiah/595574 to your computer and use it in GitHub Desktop.
This module encapsulates all knowledge about what environment your
code is running in (ie: development / production).
Note: make sure all calls to settings.get() are done at runtime, and not at import time.
import settings
def test():
remote_endpoint = settings.get("remote_endpoint")
import tornado.options
import random
tornado.options.define("environment", default="dev", help="environment")
def randomize(values):
""" this is a wrapper that returns a function which when called returns a random value"""
def picker():
return random.choice(values)
return picker
# settings that are different for each environment
# (ie: pointers to remote endpoints)
options = {
"dev" : {
"remote_endpoint" : "",
"prod" : {
"remote_endpoint" : randomize(["",
# settings that are the same for each environment
# (ie: they are here just to make them easy to find/change/update)
default_options = {
"num_records_to_return" : 15,
def get(key):
env = tornado.options.options.environment
if env not in options:
raise Exception("Invalid Environment (%s)" % env)
v = options.get(env).get(key) or default_options.get(key)
if callable(v):
return v()
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment