Files
stacosys/app/run.py
T

61 lines
1.5 KiB
Python
Raw Normal View History

2015-05-02 13:08:07 +02:00
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import logging
from werkzeug.contrib.fixers import ProxyFix
2015-05-09 12:51:14 +02:00
from flask.ext.cors import CORS
2015-05-02 13:08:07 +02:00
# add current path and parent path to syspath
current_path = os.path.dirname(__file__)
parent_path = os.path.abspath(os.path.join(current_path, os.path.pardir))
paths = [current_path, parent_path]
2015-05-02 13:08:07 +02:00
for path in paths:
if path not in sys.path:
sys.path.insert(0, path)
2015-05-02 13:43:38 +02:00
# more imports
2015-05-02 13:08:07 +02:00
import config
2015-05-02 13:43:38 +02:00
from app.services import database
from app.services import processor
2015-05-02 13:43:38 +02:00
from app.controllers import api
2015-05-16 10:59:44 +02:00
from app.controllers import mail
2015-05-02 13:43:38 +02:00
from app import app
2015-05-02 13:08:07 +02:00
2015-05-02 13:43:38 +02:00
# configure logging
2015-05-02 13:08:07 +02:00
def configure_logging(level):
root_logger = logging.getLogger()
root_logger.setLevel(level)
ch = logging.StreamHandler()
ch.setLevel(level)
# create formatter
formatter = logging.Formatter('[%(asctime)s] %(name)s %(levelname)s %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
root_logger.addHandler(ch)
logging_level = (20, 10)[config.DEBUG]
configure_logging(logging_level)
logger = logging.getLogger(__name__)
# initialize database
database.setup()
# start processor
template_path = os.path.abspath(os.path.join(current_path, 'templates'))
processor.start(template_path)
2015-05-02 13:08:07 +02:00
app.wsgi_app = ProxyFix(app.wsgi_app)
logger.info("Start Stacosys application")
2015-05-09 12:51:14 +02:00
# enable CORS
cors = CORS(app, resources={r"/comments/*": {"origins": "*"}})
2015-05-02 13:08:07 +02:00
app.run(host=config.HTTP_ADDRESS,
port=config.HTTP_PORT,
debug=config.DEBUG, use_reloader=False)