-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
122 lines (89 loc) · 3.59 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
111
112
113
114
115
116
117
118
119
120
121
122
"""
Run Configuration
~~~~~~
Defines runtime variables to
support different environments
:copyright: (c) 2017 by Kiptoo Magutt
"""
import os
# define configuration environment names
CONFIG_DEVELOPMENT = 'development'
CONFIG_DEVELOPMENT_FLEX = 'development-flex'
CONFIG_TESTING = 'testing'
CONFIG_STAGING = 'staging'
CONFIG_PRODUCTION = 'production'
# value of the 'FLASK_CONFIG' env var,
# should match any of the names above, one at a time
CONFIG_ENV_VAR_NAME = 'development' # os.environ['FLASK_CONFIG']
class Config(object):
"""
Common configurations
"""
# Put any configurations here that are common across all environments
DEBUG = True
TESTING = False
CLOUDSQL_USER = 'root'
CLOUDSQL_PASSWORD = 'testpassword'
CLOUDSQL_DATABASE = 'flask_restless_db'
CONFIG_NAME = CONFIG_DEVELOPMENT
SQLALCHEMY_ECHO = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
class DevConfigStd(Config):
"""
Development configuration for the Google App Engine Standard Environment
"""
CONFIG_NAME = CONFIG_DEVELOPMENT
# this check is only necessary as far as logging is concerned. that is,
# we don't want to unnecessarily print misleading messages or execute other code
# if this is not the currently active config
if CONFIG_ENV_VAR_NAME == CONFIG_NAME:
print "current config name: ", CONFIG_NAME
CLOUDSQL_CONNECTION_NAME = 'flask-and-restless:europe-west1:flask-restless-db'
LOCAL_SQLALCHEMY_DATABASE_URI = (
'mysql+mysqldb://{user}:{password}@127.0.0.1:3306/{database}').format(
user=Config.CLOUDSQL_USER, password=Config.CLOUDSQL_PASSWORD, database=Config.CLOUDSQL_DATABASE)
# When running on App Engine a unix socket is used to connect to the cloudsql
# instance.
live_host_name = 'localhost'
LIVE_SQLALCHEMY_DATABASE_URI = (
'mysql+mysqldb://{user}:{password}@{hostname}/{database}'
'?unix_socket=/cloudsql/{connection_name}').format(
user=Config.CLOUDSQL_USER, password=Config.CLOUDSQL_PASSWORD, hostname=live_host_name,
database=Config.CLOUDSQL_DATABASE, connection_name=CLOUDSQL_CONNECTION_NAME)
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
SQLALCHEMY_DATABASE_URI = LIVE_SQLALCHEMY_DATABASE_URI
print "********* running in the live standard env ********", SQLALCHEMY_DATABASE_URI
else:
SQLALCHEMY_DATABASE_URI = LOCAL_SQLALCHEMY_DATABASE_URI
print "********* running in the local standard env ********", SQLALCHEMY_DATABASE_URI
class DevConfigFlex(Config):
"""
Development configuration for the Google App Engine Flexible Environment
"""
CONFIG_NAME = CONFIG_DEVELOPMENT_FLEX
if CONFIG_ENV_VAR_NAME == CONFIG_NAME:
print "current config name: ", CONFIG_NAME
class TestingConfig(Config):
"""
Testing configurations
"""
CONFIG_NAME = CONFIG_TESTING
if CONFIG_ENV_VAR_NAME == CONFIG_NAME:
print "current config name: ", CONFIG_NAME
DEBUG = True
#SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://twende_test_user:test_password@localhost/twende_test'
TESTING = True
class ProductionConfig(Config):
"""
Production configurations
"""
CONFIG_NAME = CONFIG_PRODUCTION
if CONFIG_ENV_VAR_NAME == CONFIG_NAME:
print "current config name: ", CONFIG_NAME
DEBUG = False
app_config = {
CONFIG_DEVELOPMENT: DevConfigStd,
CONFIG_DEVELOPMENT_FLEX: DevConfigFlex,
CONFIG_TESTING: TestingConfig,
CONFIG_PRODUCTION: ProductionConfig
}