RESTful server to serve showtimes data
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

93 lines
2.9 KiB

import logging
import tornado
import tornado.template
from tornado.options import define, options
import os
import urllib
import logconfig
import ConfigParser
conf = ConfigParser.RawConfigParser()
conf.read('site.cfg')
port = conf.getint('app', 'port') if conf.has_option('app', 'port') else 8888
app_user = conf.get('app', 'user')
app_password = conf.get('app', 'password')
app_secret = conf.get('app', 'secret_key')
mongo_conf_data = {
'host': conf.get('mongo', 'host') if conf.has_option('mongo', 'host') else 'localhost',
'port': conf.getint('mongo', 'port') if conf.has_option('mongo', 'port') else 27017,
'user': conf.get('mongo', 'user') if conf.has_option('mongo', 'user') else '',
'password': conf.get('mongo', 'password') if conf.has_option('mongo', 'password') else '',
}
mongo_config = 'mongodb://%(host)s:%(port)s'
if mongo_conf_data['user'] and mongo_conf_data['password']:
mongo_conf_data['password'] = urllib.quote_plus(mongo_conf_data['password'])
mongo_config = 'mongodb://%(user)s:%(password)s@%(host)s:%(port)s'
mongo_config = mongo_config % mongo_conf_data
# Make filepaths relative to settings.
path = lambda root, *a: os.path.join(root, *a)
ROOT = os.path.dirname(os.path.abspath(__file__))
define("port", default=port, help="run on the given port", type=int)
define("config", default=None, help="tornado config file")
define("debug", default=False, help="debug mode")
tornado.options.parse_command_line()
MEDIA_ROOT = path(ROOT, 'media')
TEMPLATE_ROOT = path(ROOT, 'templates')
class DeploymentType:
# Deployment Configuration
PRODUCTION = "PRODUCTION"
DEV = "DEV"
SOLO = "SOLO"
STAGING = "STAGING"
dict = {
SOLO: 1,
PRODUCTION: 2,
DEV: 3,
STAGING: 4
}
if 'DEPLOYMENT_TYPE' in os.environ:
DEPLOYMENT = os.environ['DEPLOYMENT_TYPE'].upper()
else:
DEPLOYMENT = DeploymentType.SOLO
settings = {}
settings['debug'] = DEPLOYMENT != DeploymentType.PRODUCTION or options.debug
settings['static_path'] = MEDIA_ROOT
settings['cookie_secret'] = '*(&$#^@&*YOURWHATEVERSECRET_JDF)#()$#@()*ur892h899'
settings['xsrf_cookies'] = True
settings['template_loader'] = tornado.template.Loader(TEMPLATE_ROOT)
SYSLOG_TAG = 'showtimes-serv'
SYSLOG_FACILITY = logging.handlers.SysLogHandler.LOG_LOCAL2
# See PEP 391 and logconfig for formatting help. Each section of LOGGERS
# will get merged into the corresponding section of log_settings.py.
# Handlers and log levels are set up automatically based on LOG_LEVEL and DEBUG
# unless you set them here. Messages will not propagate through a logger
# unless propagate: True is set.
LOGGERS = {
'loggers': {
'stockintel': {},
},
}
if settings['debug']:
LOG_LEVEL = logging.DEBUG
else:
LOG_LEVEL = logging.INFO
USE_SYSLOG = DEPLOYMENT != DeploymentType.SOLO
logconfig.initialize_logging(
SYSLOG_TAG, SYSLOG_FACILITY, LOGGERS, LOG_LEVEL, USE_SYSLOG)
if options.config:
tornado.options.parse_config_file(options.config)