Guest User

Untitled

a guest
Jan 8th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """Main module."""
  3. import os
  4. import logging.config
  5. import bottle
  6. from pg_simple.pool import config_pool
  7. import web.assets
  8. from services import *
  9.  
  10. currentdir = os.path.dirname(__file__)
  11.  
  12.  
  13. def registra_plugins():
  14. from bottle_cerberus import CerberusPlugin
  15. bottle.install(CerberusPlugin())
  16.  
  17.  
  18. def init_database():
  19. dsn = {
  20. 'host': os.getenv('IVENDAS_DB_CRM_HOST', 'localhost'),
  21. 'dbname': os.getenv('IVENDAS_DB_DBNAME', 'ivendas'),
  22. 'user': os.getenv('IVENDAS_DB_USER', 'ivendas'),
  23. 'password': os.getenv('IVENDAS_DB_PASSWORD', 'ivendas')
  24. }
  25. dsn_line = ' '.join(['%s=%s' % (k, v) for k, v in dsn.items()])
  26. config_pool(dsn=dsn_line)
  27.  
  28.  
  29. def config_view_template():
  30. views_path = os.path.join(currentdir, 'web/views')
  31. bottle.TEMPLATE_PATH.insert(0, views_path)
  32.  
  33.  
  34. def config_logging():
  35. logging_config_file = os.path.join(currentdir, "logging.ini")
  36. logging.config.fileConfig(logging_config_file)
  37.  
  38.  
  39. def build_app(debug=False):
  40. bottle.debug(debug)
  41. bottle.BaseRequest.MEMFILE_MAX = (1024 * 1024) * 4
  42. registra_plugins()
  43. init_database()
  44. config_view_template()
  45. return bottle.default_app()
  46.  
  47.  
  48. debug = os.getenv('IVENDAS_CRM_DEBUG', True)
  49. app = build_app(debug)
  50.  
  51.  
  52. if __name__ == "__main__":
  53. dev_options = {
  54. 'host': os.getenv('IVENDAS_CRM_HOST', '0.0.0.0'),
  55. 'port': os.getenv('IVENDAS_CRM_PORT', 8000),
  56. 'workers': os.getenv('IVENDAS_CRM_WORKER_QTD', 1),
  57. 'reload': os.getenv('IVENDAS_CRM_RELOAD', True),
  58. 'debug': debug
  59. }
  60.  
  61. bottle.run(**dev_options)
Add Comment
Please, Sign In to add comment