2015-09-15 07:46:35 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-09-18 21:10:01 +00:00
|
|
|
|
2015-09-15 07:46:35 +00:00
|
|
|
import os
|
2018-10-14 20:44:00 +00:00
|
|
|
import click
|
2017-09-18 21:10:01 +00:00
|
|
|
|
|
|
|
from flask import Flask
|
|
|
|
from flask.cli import FlaskGroup
|
2015-09-15 07:46:35 +00:00
|
|
|
from flask_migrate import MigrateCommand
|
|
|
|
|
2017-09-18 21:10:01 +00:00
|
|
|
from dribdat.app import init_app
|
2015-09-15 07:46:35 +00:00
|
|
|
from dribdat.settings import DevConfig, ProdConfig
|
|
|
|
from dribdat.database import db
|
|
|
|
|
|
|
|
HERE = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
TEST_PATH = os.path.join(HERE, 'tests')
|
|
|
|
|
2017-09-18 21:10:01 +00:00
|
|
|
def shell_context():
|
|
|
|
"""Return context dict for a shell session"""
|
2017-09-18 21:22:20 +00:00
|
|
|
from dribdat.user.models import User, Event, Project, Category, Activity
|
|
|
|
return {'User': User, 'Event':Event, 'Project':Project, 'Category':Category, 'Activity':Activity}
|
2015-09-15 07:46:35 +00:00
|
|
|
|
2017-09-18 21:10:01 +00:00
|
|
|
def create_app(script_info=None):
|
|
|
|
"""Initialise the app object"""
|
|
|
|
if os.environ.get("DRIBDAT_ENV") == 'prod':
|
|
|
|
app = init_app(ProdConfig)
|
|
|
|
else:
|
|
|
|
app = init_app(DevConfig)
|
|
|
|
app.shell_context_processor(shell_context)
|
2018-10-14 20:44:00 +00:00
|
|
|
app.cli.add_command('db', MigrateCommand)
|
2017-09-18 21:10:01 +00:00
|
|
|
return app
|
|
|
|
|
2018-10-14 20:44:00 +00:00
|
|
|
@click.group(cls=FlaskGroup, create_app=create_app)
|
|
|
|
def cli():
|
|
|
|
"""This is a management script for the wiki application."""
|
2015-09-15 07:46:35 +00:00
|
|
|
|
2018-10-14 20:44:00 +00:00
|
|
|
@click.command
|
2015-09-15 07:46:35 +00:00
|
|
|
def test():
|
|
|
|
"""Run the tests."""
|
|
|
|
import pytest
|
|
|
|
exit_code = pytest.main([TEST_PATH, '--verbose'])
|
|
|
|
return exit_code
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-09-18 21:10:01 +00:00
|
|
|
cli()
|