Created
January 2, 2018 13:45
-
-
Save pimtel/4a02f0a47afea5c6cb19eb5bd01b3f3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Main module.""" | |
import os | |
import logging.config | |
import bottle | |
from pg_simple.pool import config_pool | |
import web.assets | |
from services import * | |
currentdir = os.path.dirname(__file__) | |
def registra_plugins(): | |
from bottle_cerberus import CerberusPlugin | |
bottle.install(CerberusPlugin()) | |
def init_database(): | |
dsn = { | |
'host': os.getenv('IVENDAS_DB_CRM_HOST', 'localhost'), | |
'dbname': os.getenv('IVENDAS_DB_DBNAME', 'ivendas'), | |
'user': os.getenv('IVENDAS_DB_USER', 'ivendas'), | |
'password': os.getenv('IVENDAS_DB_PASSWORD', 'ivendas') | |
} | |
dsn_line = ' '.join(['%s=%s' % (k, v) for k, v in dsn.items()]) | |
config_pool(dsn=dsn_line) | |
def config_view_template(): | |
views_path = os.path.join(currentdir, 'web/views') | |
bottle.TEMPLATE_PATH.insert(0, views_path) | |
def config_logging(): | |
logging_config_file = os.path.join(currentdir, "logging.ini") | |
logging.config.fileConfig(logging_config_file) | |
def build_app(debug=False): | |
bottle.debug(debug) | |
bottle.BaseRequest.MEMFILE_MAX = (1024 * 1024) * 4 | |
registra_plugins() | |
init_database() | |
config_view_template() | |
return bottle.default_app() | |
debug = os.getenv('IVENDAS_CRM_DEBUG', True) | |
app = build_app(debug) | |
if __name__ == "__main__": | |
dev_options = { | |
'host': os.getenv('IVENDAS_CRM_HOST', '0.0.0.0'), | |
'port': os.getenv('IVENDAS_CRM_PORT', 8000), | |
'workers': os.getenv('IVENDAS_CRM_WORKER_QTD', 1), | |
'reload': os.getenv('IVENDAS_CRM_RELOAD', True), | |
'debug': debug | |
} | |
bottle.run(**dev_options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment