forked from tulul/tululbot
/
manage.py
executable file
·87 lines (63 loc) · 1.82 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
#!/usr/bin/env python
import code
from os import environ
from os.path import dirname, join
import subprocess
import sys
import click
from dotenv import load_dotenv
import pytest
def load_app():
# Environment variable MUST be set before importing the app
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
from tululbot import app
return app
@click.group()
def manage():
"""Script to manage tasks outside the application itself."""
pass
@manage.command()
def shell():
"""Run a shell with custom context."""
app = load_app()
from tululbot import bot
context = dict(app=app, bot=bot)
try:
from IPython import embed
except ImportError:
code.interact(local=context)
else:
embed(user_ns=context)
@manage.command()
def runserver():
"""Run the application server."""
load_app().run()
@manage.command()
def test():
"""Run the tests."""
# Environment variable MUST be set before importing the app
dotenv_path = join(dirname(__file__), 'tests', '.env')
load_dotenv(dotenv_path)
sys.exit(pytest.main([]))
@manage.command()
def lint():
"""Run the linters."""
sys.exit(subprocess.call(['flake8']))
@manage.command()
def check():
"""Run linters and tests.
Use this command to check before making a pull request."""
# Environment variable MUST be set before importing the app
dotenv_path = join(dirname(__file__), 'tests', '.env')
load_dotenv(dotenv_path)
sys.exit(subprocess.call(['flake8']) or pytest.main([]))
@manage.command()
@click.argument('message')
def notify(message):
"""Send notification to TululBot developers group."""
from tululbot import bot
chat_id = environ['TULULBOT_DEVEL_CHAT_ID']
bot.send_message(chat_id, message)
if __name__ == '__main__':
manage()