This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.py
52 lines (42 loc) · 1.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from app.utils import (
get_env,
to_bool,
)
from app.utils.num import (
random_func,
)
app_dir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
SQLALCHEMY_DATABASE_URI = get_env('DATABASE_URL', default=f'sqlite:///{"app" or __name__}.db')#'sqlite:///:memory:'
SQLALCHEMY_TRACK_MODIFICATIONS = False
#SQLALCHEMY_COMMIT_ON_TEARDOWN = True
_binds = get_env('SQLALCHEMY_BINDS', default=None)
if _binds:
#https://docs.sqlalchemy.org/en/13/core/exceptions.html
#https://flask-sqlalchemy.palletsprojects.com/en/2.x/binds/
#https://flask-migrate.readthedocs.io/en/latest/
SQLALCHEMY_BINDS = {}
for _ in _binds.split(','):
__ = _.split(':', 1)
SQLALCHEMY_BINDS.update({__[0].lower() : __[1] if __[1].rfind('://') != -1 else get_env(__[1])})
print(SQLALCHEMY_BINDS)
# SECURITY WARNING: don't run with debug turned on in production!
#Default: True if ENV is 'development', or False otherwise.
DEBUG = to_bool(get_env('DEBUG', default=os.sys.platform == 'win32' or os.name == 'nt'))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_env('SECRET_KEY', default=random_func(as_string=True, size=65))
DEVELOPMENT = TESTING = False
@property
def DATABASE_URI(self):
return SQLALCHEMY_DATABASE_URI
class DevelopementConfig(Config):
DEVELOPMENT = True
ENV = 'development'#dev
class TestingConfig(Config):#StagingConfig
TESTING = DEVELOPMENT = DEBUG = True
class ProductionConfig(Config):
TESTING = DEVELOPMENT = DEBUG = False
ENV = 'production'