-
Notifications
You must be signed in to change notification settings - Fork 27
/
config.py
110 lines (82 loc) · 3.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!usr/bin/env python
# -*- coding: utf-8 -*-
import os
import logging
basedir = os.path.abspath(os.path.dirname(__file__))
datadir = 'data'
class Config:
SITE_NAME = 'codingpy'
SECRET_KEY = os.urandom(32)
DEBUG_TB_INTERCEPT_REDIRECTS = False
# 是否启用博客模式
# BLOG_MODE = True
# html or markdown
BODY_FORMAT = os.getenv('BODY_FORMAT') or 'html'
# mail setup
MAIL_SERVER = 'smtp.126.com'
MAIL_PORT = 25
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
MAIL_SUBJECT_PREFIX = '[CODINGPY]'
MAIL_SENDER = 'CODINGPY Admin <codingpy@126.com>'
APP_ADMIN = os.environ.get('CODINGPY_ADMIN')
# flask-cache configuration
CACHE_KEY = 'view/%s' # ?
CACHE_DEFAULT_TIMEOUT = 30
CACHE_TYPE = 'redis'
CACHE_REDIS_HOST = 'localhost'
CACHE_REDIS_PORT = 6379
CACHE_REDIS_URL = 'redis://localhost:6379'
# QiNiu Cloud Storage
QINIU_AK = os.getenv('QINIU_AK') or ''
QINIU_SK = os.getenv('QINIU_SK') or ''
QINIU_BUCKET = os.getenv('QINIU_BUCKET') or ''
QINIU_DOMAIN = os.getenv('QINIU_DOMAIN') or '%s.qiniudn.com' % QINIU_BUCKET
@staticmethod
def init_app(app):
_handler = logging.StreamHandler()
app.logger.addHandler(_handler)
# TODO
# mail_handler = Config.get_mailhandler()
# app.logger.addHandler(mail_handler)
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URI') \
or "postgresql://vagrant:vagrant@localhost/codingpy" or \
'sqlite:///%s' % os.path.join(basedir, 'data_dev_sqlite.db')
@classmethod
def init_app(cls, app):
Config.init_app(app)
class ProductionConfig(Config):
# CACHE_DIR = os.path.join(basedir, datadir, 'cache')
DEBUG = False
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or \
"postgresql://earlgrey:earlgrey@localhost/codingpy"
# postgresql configuration
# POSTGRES_USER = os.getenv('POSTGRES_USER') or ''
# POSTGRES_PASS = os.getenv('POSTGRES_PASS') or ''
# POSTGRES_HOST = os.getenv('POSTGRES_HOST') or ''
# POSTGRES_PORT = os.getenv('POSTGRES_PORT') or ''
# POSTGRES_DB = os.getenv('POSTGRES_DB') or ''
# if (len(POSTGRES_USER) > 0 and len(POSTGRES_PASS) > 0 and
# len(POSTGRES_HOST) > 0 and len(POSTGRES_PORT) > 0 and
# len(POSTGRES_DB) > 0):
# SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URI') or \
# 'postgresql://%s:%s@%s:%s/%s' % (
# POSTGRES_USER, POSTGRES_PASS, POSTGRES_HOST,
# POSTGRES_PORT, POSTGRES_DB)
@classmethod
def init_app(cls, app):
Config.init_app(app)
# mail_handler = Config.get_mailhandler()
# app.logger.addHandler(mail_handler)
class TestingConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URI') or \
'sqlite:///:memory:'
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig,
}