-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·78 lines (57 loc) · 1.52 KB
/
Copy pathmain.py
File metadata and controls
executable file
·78 lines (57 loc) · 1.52 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
#!/usr/bin/env python2
# -*- encoding: utf-8 -*-
"""
Glues everything together and launches the app
"""
import os
import locale
import codecs
import logging
import yaml
from flask import Flask
import models
import login
import views
from lib import upload, filters, mail
from domain import algorithm
CONFIG_FILE = 'config.yaml'
def load_config(app):
# take config from file
with open(CONFIG_FILE) as f:
config = yaml.load(f)
# load email templates
templates = config['MAIL_TEMPLATES']
config_mails = dict()
for f in os.listdir(templates):
name = os.path.splitext(f)[0].upper()
# load template content in config
with codecs.open(os.path.join(templates, f), 'rb', 'utf8') as f_handle:
config_mails[name] = f_handle.read()
config['MAIL'] = config_mails
app.config.update(config)
def create_app():
app = Flask(__name__)
load_config(app)
app.debug = app.config['DEBUG']
app.secret_key = app.config['SECRET_KEY']
try:
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
except locale.Error:
logging.warning('Could not set locale')
# init flask extensions
mail.init_app(app)
login.init_app(app)
# init my modules
models.init_app(app)
upload.init_app(app)
filters.init_app(app)
views.init_app(app)
algorithm.init_app(app)
# register routes
map(app.register_blueprint, views.all_blueprints)
return app
def main():
app = create_app()
app.run()
if __name__ == '__main__':
main()