Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 81 lines (55 sloc) 1.936 kb
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
#!/usr/bin/env python
# coding: utf-8
from base.ext import db, manager
from base.loader import loader
import sys


# Load app scripts
loader.load_submod('script')


@manager.shell
def make_shell_context():
    " Update shell. "

    from flask import current_app
    return dict(app=current_app, db=db)


@manager.command
def migrate():
    " Alembic migration utils. "

    from flask import current_app
    from alembic.config import main
    from os import path as op

    global ARGV

    config = op.join(op.dirname(__file__), 'migrate', 'develop.ini' if current_app.debug else 'production.ini')

    ARGV = ['-c', config] + ARGV

    main(ARGV)


@manager.command
def test(testcase=''):
    """ Run unittests.

:param testmod: path to custom module

"""

    try:
        from unittest2.loader import defaultTestLoader
        from unittest2.runner import TextTestRunner
    except ImportError:
        from unittest.loader import defaultTestLoader
        from unittest.runner import TextTestRunner

    if testcase:
        mod, case = testcase.rsplit('.', 1)
        mod = loader.import_module(mod)
        if not mod or not hasattr(mod, case):
            sys.stdout.write("Load case error: %s\n" % testcase)
            sys.exit(1)

        testcase = getattr(mod, case)
        suite = defaultTestLoader.loadTestsFromTestCase(testcase)
    else:
        cases = loader.load_submod('tests')
        suites = [defaultTestLoader.loadTestsFromModule(mod) for mod in cases]
        suite = defaultTestLoader.suiteClass(suites)

    TextTestRunner().run(suite)


ARGV = []

if __name__ == '__main__':
    argv = sys.argv[1:]
    if argv and argv[0] == 'migrate':
        ARGV = filter(lambda a: not a in ('-c', 'migrate') and not a.startswith('base.config.'), argv)
        argv = filter(lambda a: not a in ARGV, argv)
        sys.argv = [sys.argv[0]] + argv

    manager.run()


# pymode:lint_ignore=F0401,W801,W0603
Something went wrong with that request. Please try again.