microblog2/app/__init__.py

40 lines
1.3 KiB
Python
Raw Normal View History

2012-12-16 08:30:41 +00:00
import os
2012-12-16 08:24:07 +00:00
from flask import Flask
2012-12-16 08:29:49 +00:00
from flask.ext.sqlalchemy import SQLAlchemy
2012-12-16 08:30:41 +00:00
from flask.ext.login import LoginManager
from flask.ext.openid import OpenID
2012-12-16 08:36:04 +00:00
from flask.ext.mail import Mail
2012-12-16 08:32:38 +00:00
from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD
2012-12-16 08:24:07 +00:00
app = Flask(__name__)
2012-12-16 08:28:52 +00:00
app.config.from_object('config')
2012-12-16 08:29:49 +00:00
db = SQLAlchemy(app)
2012-12-16 08:30:41 +00:00
lm = LoginManager()
lm.setup_app(app)
lm.login_view = 'login'
oid = OpenID(app, os.path.join(basedir, 'tmp'))
2012-12-16 08:36:04 +00:00
mail = Mail(app)
2012-12-16 08:29:49 +00:00
2012-12-16 08:32:38 +00:00
if not app.debug:
import logging
from logging.handlers import SMTPHandler
credentials = None
if MAIL_USERNAME or MAIL_PASSWORD:
credentials = (MAIL_USERNAME, MAIL_PASSWORD)
mail_handler = SMTPHandler((MAIL_SERVER, MAIL_PORT), 'no-reply@' + MAIL_SERVER, ADMINS, 'microblog failure', credentials)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
if not app.debug:
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('tmp/microblog.log', 'a', 1 * 1024 * 1024, 10)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup')
2012-12-16 08:29:49 +00:00
from app import views, models
2012-12-16 08:28:52 +00:00