-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathagenda.py
executable file
·88 lines (73 loc) · 2.61 KB
/
agenda.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
#!/usr/bin/env python
import os.path
import logging
import flask
import database
import webpages
import auth
default_config = {
'DEBUG': False,
'TIMEZONE': 'Europe/Bucharest',
}
def setup_mail_on_error(app):
ADMINS = ['[email protected]']
mail_on_error = app.config.get('MAIL_ON_ERROR', [])
if not mail_on_error:
return
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler(app.config.get('MAIL_HOST', '127.0.0.1'),
app.config['MAIL_FROM'],
mail_on_error,
"Error in Agenda Politicieni")
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
def create_app():
app = flask.Flask(__name__, instance_relative_config=True)
app.config['SQLALCHEMY_DATABASE_URI'] = (
'sqlite:///%s/agenda.db' % app.instance_path)
app.config.update(default_config)
app.config.from_pyfile('settings.py', silent=True)
webpages.init_app(app)
database.db.init_app(app)
auth.init_app(app)
setup_mail_on_error(app)
return app
def main():
app = create_app()
log_fmt = logging.Formatter("[%(asctime)s] %(module)s "
"%(levelname)s %(message)s")
suggestion_log_path = os.path.join(app.instance_path, 'database.log')
suggestion_handler = logging.FileHandler(suggestion_log_path)
suggestion_handler.setFormatter(log_fmt)
database.log.addHandler(suggestion_handler)
import sys
if len(sys.argv) > 1:
cmd = sys.argv[1]
else:
cmd = 'runserver'
if cmd == 'runserver':
app.run(debug=True)
elif cmd == 'shell':
from code import interact
with app.test_request_context():
interact(local={'app': app})
elif cmd == 'fastcgi':
from flup.server.fcgi import WSGIServer
error_log_path = os.path.join(app.instance_path, 'error.log')
error_handler = logging.FileHandler(error_log_path)
error_handler.setFormatter(log_fmt)
error_handler.setLevel(logging.ERROR)
logging.getLogger().addHandler(error_handler)
sock_path = os.path.join(app.instance_path, 'fcgi.sock')
server = WSGIServer(app, bindAddress=sock_path, umask=0)
server.run()
elif cmd == 'update_identities':
import sync
with app.test_request_context():
sync.update_identities()
elif cmd == 'new_people':
with app.test_request_context():
database.add_people(line.strip() for line in sys.stdin)
database.db.session.commit()
if __name__ == '__main__':
main()