2014-01-17 09:36:44 +00:00
|
|
|
#!/usr/bin/env python
|
2013-10-27 16:15:35 +00:00
|
|
|
"""
|
2014-01-17 09:14:15 +00:00
|
|
|
CLI to manage redash.
|
2013-10-27 16:15:35 +00:00
|
|
|
"""
|
2015-06-30 06:25:32 +00:00
|
|
|
import json
|
|
|
|
|
2016-02-29 08:39:50 +00:00
|
|
|
from flask_script import Manager
|
2013-10-25 07:26:07 +00:00
|
|
|
|
2014-05-18 07:15:37 +00:00
|
|
|
from redash import settings, models, __version__
|
|
|
|
from redash.wsgi import app
|
2016-04-10 13:08:36 +00:00
|
|
|
from redash.cli import users, groups, database, data_sources, organization
|
2015-06-30 06:25:32 +00:00
|
|
|
from redash.monitor import get_status
|
2014-05-18 07:15:37 +00:00
|
|
|
|
2014-02-09 15:09:07 +00:00
|
|
|
manager = Manager(app)
|
2015-01-14 10:22:16 +00:00
|
|
|
manager.add_command("database", database.manager)
|
|
|
|
manager.add_command("users", users.manager)
|
2016-04-10 13:08:36 +00:00
|
|
|
manager.add_command("groups", groups.manager)
|
2015-01-14 10:22:16 +00:00
|
|
|
manager.add_command("ds", data_sources.manager)
|
2015-12-01 13:44:08 +00:00
|
|
|
manager.add_command("org", organization.manager)
|
|
|
|
|
2015-01-14 10:22:16 +00:00
|
|
|
|
2014-02-09 15:09:07 +00:00
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def version():
|
|
|
|
"""Displays re:dash version."""
|
|
|
|
print __version__
|
|
|
|
|
2015-06-30 06:25:32 +00:00
|
|
|
@manager.command
|
|
|
|
def status():
|
|
|
|
print json.dumps(get_status(), indent=2)
|
2014-02-13 11:08:48 +00:00
|
|
|
|
2014-02-09 15:09:07 +00:00
|
|
|
@manager.command
|
|
|
|
def runworkers():
|
2015-01-14 08:52:11 +00:00
|
|
|
"""Start workers (deprecated)."""
|
2014-05-16 14:57:43 +00:00
|
|
|
print "** This command is deprecated. Please use Celery's CLI to control the workers. **"
|
|
|
|
|
2013-10-25 07:26:07 +00:00
|
|
|
|
2014-02-09 15:09:07 +00:00
|
|
|
@manager.shell
|
|
|
|
def make_shell_context():
|
2014-05-18 07:15:37 +00:00
|
|
|
from redash.models import db
|
2014-02-09 15:09:07 +00:00
|
|
|
return dict(app=app, db=db, models=models)
|
2013-10-25 07:26:07 +00:00
|
|
|
|
2015-01-14 08:52:11 +00:00
|
|
|
|
2014-03-25 08:19:21 +00:00
|
|
|
@manager.command
|
|
|
|
def check_settings():
|
2015-01-14 08:52:11 +00:00
|
|
|
"""Show the settings as re:dash sees them (useful for debugging)."""
|
2015-07-09 05:38:42 +00:00
|
|
|
for name, item in settings.all_settings().iteritems():
|
|
|
|
print "{} = {}".format(name, item)
|
2014-03-25 08:19:21 +00:00
|
|
|
|
2016-10-09 06:15:47 +00:00
|
|
|
|
|
|
|
@manager.option('email', default=None, help="Email address to send test message to (default: the address you defined in MAIL_DEFAULT_SENDER)")
|
|
|
|
def send_test_mail(email=None):
|
2015-07-09 05:38:42 +00:00
|
|
|
from redash import mail
|
|
|
|
from flask_mail import Message
|
|
|
|
|
2016-10-09 06:15:47 +00:00
|
|
|
if email is None:
|
|
|
|
email = settings.MAIL_DEFAULT_SENDER
|
|
|
|
|
|
|
|
mail.send(Message(subject="Test Message from re:dash", recipients=[email], body="Test message."))
|
2014-03-25 08:19:21 +00:00
|
|
|
|
2014-04-19 14:06:47 +00:00
|
|
|
|
2013-10-25 07:26:07 +00:00
|
|
|
if __name__ == '__main__':
|
2015-01-20 14:25:51 +00:00
|
|
|
manager.run()
|