forked from deepgully/me
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
175 lines (130 loc) · 4.56 KB
/
settings.py
File metadata and controls
175 lines (130 loc) · 4.56 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# -*- coding: utf-8 -*-
# Copyright 2013 Gully Chen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Site Settings for various runtime environments
"""
# Global Settings
import os
import sys
######################################
## Global environment
######################################
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, "libs"))
try:
from google.appengine.api import conf
_, _, GAE_DEVELOPMENT = conf._inspect_environment()
RUNTIME_ENV = "gae"
if GAE_DEVELOPMENT:
RUNTIME_ENV = "gae_dev"
import logging
except:
RUNTIME_ENV = "local"
if "SERVER_SOFTWARE" in os.environ:
from bae.core import const
from bae.api import logging
RUNTIME_ENV = "bae"
else:
import logging
from flask import Flask
######################################
## Application
######################################
app = Flask(__name__)
app.config["RUNTIME_ENV"] = RUNTIME_ENV
######################################
## Database
######################################
if RUNTIME_ENV in ("bae",):
SAE_DATABASE = "qHWGMWtaVuVSNMEpprEk"
app.secret_key = const.ACCESS_KEY + const.SECRET_KEY
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://%s:%s@%s:%s/%s?charset=utf8' % (
const.MYSQL_USER, const.MYSQL_PASS,
const.MYSQL_HOST, const.MYSQL_PORT,
SAE_DATABASE
)
app.config['SQLALCHEMY_POOL_RECYCLE'] = 10
elif RUNTIME_ENV in ("local",):
LOCAL_DATABASE = "test"
app.secret_key = "ME@deepgully"
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s.db'%LOCAL_DATABASE
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@127.0.0.1:3306/%s'%LOCAL_DATABASE
elif RUNTIME_ENV in ("gae", "gae_dev"):
app.secret_key = "ME@deepgully+GAE"
if RUNTIME_ENV in ("bae", "local"):
from alembic.config import Config
MIGRATE_CFG = Config("alembic.ini")
MIGRATE_CFG.set_section_option("alembic", "sqlalchemy.url", app.config['SQLALCHEMY_DATABASE_URI'])
app.config['MIGRATE_CFG'] = MIGRATE_CFG
app.config["SiteTitle"] = "boolog"
app.config["SiteSubTitle"] = ""
app.config["OwnerEmail"] = "yjcpu@gmail.com"
app.config["DefaultPassword"] = "000000"
######################################
## User
######################################
from flask.ext.login import LoginManager
login_manager = LoginManager()
login_manager.init_app(app)
#####################################
## Mail
#####################################
if RUNTIME_ENV in ("bae",):
from bae.api.bcms import BaeBcms
BAE_BCMS = BaeBcms(const.ACCESS_KEY, const.SECRET_KEY)
elif RUNTIME_ENV in ("local",):
app.config['MAIL_SERVER'] = "localhost"
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS '] = False
app.config['MAIL_USE_SSL '] = False
app.config['MAIL_USERNAME '] = "test"
app.config['MAIL_PASSWORD '] = "test"
from flask_mail import Mail
mail = Mail(app)
elif RUNTIME_ENV in ("gae", "gae_dev"):
pass
#####################################
## Image Upload
#####################################
if RUNTIME_ENV in ("bae",):
from bae.api import bcs
BAE_BCS = bcs.BaeBCS(const.BCS_ADDR, const.ACCESS_KEY, const.SECRET_KEY)
BCS_HOST = "http://bcs.duapp.com"
BUCKET_NAME = "deepgully"
BSC_FOLDER = "/photos/"
elif RUNTIME_ENV in ("local",):
UPLOAD_URL = "static/uploads/"
UPLOAD_FOLDER = os.path.join(app.root_path, UPLOAD_URL)
elif RUNTIME_ENV in ("gae", "gae_dev"):
BLOB_SERVING_URL = "/_files"
app.config["BLOB_SERVING_URL"] = BLOB_SERVING_URL
THUMB_SIZE = (400, 300)
app.config["THUMB_SIZE"] = THUMB_SIZE
######################################
## i18n
######################################
from flask.ext.babel import Babel
from flask.ext.babel import gettext, lazy_gettext
_ = gettext
babel = Babel(app)
def T(string):
""" fake function for babel """
return string
######################################
## memcache
######################################
ENABLE_MEMCACHE = True
if RUNTIME_ENV in ("bae",):
ENABLE_MEMCACHE = False # default to disable memcache for BAE because it's not free