-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
101 lines (82 loc) · 2.8 KB
/
manage.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
94
95
96
97
98
99
100
101
#!/usr/bin/env python
"""
VATSIM API
Copyright (C) 2019 Pedro Rodrigues <[email protected]>
This file is part of VATSIM API.
VATSIM API is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2 of the License.
VATSIM API is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VATSIM API. If not, see <http://www.gnu.org/licenses/>.
CLI module for app management and development tasks.
"""
import click
import subprocess
import sys
import os
@click.group()
def cli():
pass
@cli.command()
@click.option('--host', '-h', default='0.0.0.0', help='The address the web app will listen in.')
@click.option('--port', '-p', default=5000, help='The TCP port to listen to')
@click.option('--debug', '-d', default=False, is_flag=True, help='Set enviroment mode')
def run(host, port, debug):
"""Runs a development web server."""
if debug:
from wsgi import app
app.run(host=host, port=port, debug=debug)
else:
host = os.environ.get('HOST', host)
port = os.environ.get('PORT', port)
subprocess.call(['gunicorn', 'wsgi:app', '--bind', f'{host}:{port}', '--log-file=-'])
@cli.command()
def clock():
"""Runs the AP scheduler."""
from clock import sched
sched.start()
@cli.command()
def worker():
"""Runs a background celery worker."""
subprocess.call(['celery', 'worker', '-A', 'worker.celery', '--loglevel=info'])
@cli.command()
def shell():
"""Runs a shell in the app context."""
subprocess.call(['flask', 'shell'])
@cli.command()
def lint():
"""Runs pylinter."""
lint = subprocess.call(['pylint', 'src'])
sys.exit(lint)
@cli.group()
def tasks():
"""Manually schedules tasks."""
@tasks.group()
def update():
"""Schedule update tasks"""
@update.command()
def vatsim():
"""Schedules a Vatsim status update."""
from src.vatsim.tasks import update
update.apply_async()
@update.command()
def events():
"""Schedules a Vateud events update."""
from src.events.tasks import update
update.apply_async()
@cli.command()
@click.option('--only', help='Run only the specified test.')
def test(only=None):
"""Runs tests."""
suite = ['coverage', 'run', '--source=src', '-m', 'unittest', '-v']
if only:
suite.append(only)
tests = subprocess.call(suite)
subprocess.call(['coverage', 'report', '--show-missing'])
sys.exit(tests)
if __name__ == '__main__':
cli()