-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
85 lines (68 loc) · 2.79 KB
/
setup.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
import subprocess
import sys
import configparser
import os
from pathlib import Path
from init import Init
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_script import Server, Manager, Shell
from flask_marshmallow import Marshmallow
from social_flask.routes import social_auth
from social_flask_sqlalchemy.models import init_social
from flask_migrate import Migrate, MigrateCommand
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from flask_assets import Environment
app = Flask(__name__)
cwd = Path(os.path.dirname(os.path.realpath(__file__)))
os.chdir(str(cwd))
config = configparser.ConfigParser()
config.read(str(cwd / 'settings.cfg'))
app.config['config'] = config
config = config['DEFAULT']
app.config['DEBUG'] = config.getboolean('DEBUG')
app.config['ASSETS_DEBUG'] = app.config['DEBUG']
app.config['SQLALCHEMY_DATABASE_URI'] = config['DB_PATH']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))
migrate = Migrate(app, db)
ma = Marshmallow(app)
manager = Manager(app)
manager.add_command('runserver', Server())
manager.add_command('shell', Shell(make_context=lambda: {
'app': app,
'db_session': db_session
}))
manager.add_command('db', MigrateCommand)
manager.add_command('init', Init())
environment = Environment(app)
environment.append_path(str(cwd / 'static'))
environment.append_path(str(cwd / 'bower_components'))
version = subprocess.check_output(['git', 'describe', '--tags', '--always'], cwd=str(cwd)).decode(sys.stdout.encoding).strip()
app.config['SECRET_KEY'] = config['SECRET_KEY']
app.config['SESSION_PROTECTION'] = 'strong'
app.config['SOCIAL_AUTH_LOGIN_URL'] = '/login'
app.config['SOCIAL_AUTH_LOGIN_REDIRECT_URL'] = '/?logged_in=1'
app.config['SOCIAL_AUTH_USER_MODEL'] = 'models.User'
app.config['SOCIAL_AUTH_AUTHENTICATION_BACKENDS'] = ('social_core.backends.google.GoogleOAuth2', )
app.config['SOCIAL_AUTH_FIELDS_STORED_IN_SESSION'] = ['keep']
app.config['SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS'] = {
'hd': 'andrew.cmu.edu',
'access_type': 'online',
'approval_prompt': 'auto'
}
app.config['SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'] = config['GOOGLE_OATH2_CLIENT_ID']
app.config['SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'] = config['GOOGLE_OATH2_SECRET']
app.register_blueprint(social_auth)
init_social(app, db_session)
login_manager = LoginManager()
login_manager.login_view = 'index'
login_manager.login_message = 'Please login to access that page.'
login_manager.init_app(app)
app.config['SMTP_EMAIL'] = config['SMTP_EMAIL']
app.config['CONTACT_EMAIL'] = config['CONTACT_EMAIL']
app.config['SUDO_USERID'] = 'sudo'