-
Notifications
You must be signed in to change notification settings - Fork 1
/
intranet.py
executable file
·93 lines (75 loc) · 2.02 KB
/
intranet.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
#!/usr/bin/env python
import os
from flask_migrate import Migrate
from flask.cli import main
from app import create_app, db
from app.models import Documents, EventPosts, Events, MeetingNotes, Monitor, News, Posts, Roles, Users
from app.main.utils import ping_website
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db)
def make_shell_context():
return dict(
app=app,
db=db,
Roles=Roles,
Users=Users,
Posts=Posts,
MeetingNotes=MeetingNotes,
Monitor=Monitor,
News=News,
EventPosts=EventPosts,
Events=Events,
Documents=Documents
)
@app.cli.command
def reset_database():
"""Setup the database."""
from flask_migrate import upgrade
from subprocess import call
# Reset the database
call(['sudo', 'service', 'rh-postgresql95-postgresql', 'restart'])
call(['sudo', '-u', 'postgres', '/opt/rh/rh-postgresql95/root/usr/bin/dropdb', 'intranet'])
call(['sudo', '-u', 'postgres', '/opt/rh/rh-postgresql95/root/usr/bin/createdb', 'intranet'])
# Run migrations
upgrade()
# pre-populate
list(
map(
lambda x: x.populate(),
(
Roles,
Users
)
)
)
@app.cli.command
def deploy():
"""Upgrade and pre-populate database"""
from flask_migrate import upgrade
# Run migrations
upgrade()
# pre-populate
list(
map(
lambda x: x.populate(),
(
Roles,
Users
)
)
)
@app.cli.command('ping')
def ping():
"""Ping list of monitored sites and check if they're still alive."""
# Execute pings
monitors = Monitor.query.all()
for monitor in monitors:
ping_website(monitor)
@app.cli.command()
def test():
"""Run the unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
if __name__ == '__main__':
main()