Fetching contributors…
Cannot retrieve contributors at this time
executable file 78 lines (53 sloc) 1.87 KB
#!/usr/bin/env python
# coding: utf-8
from base.ext import db, manager
from base.loader import loader
import sys
# Load app scripts
loader.register(manager, submodule='manage')
def make_shell_context():
" Update shell. "
from flask import current_app
return dict(app=current_app, db=db)
def alembic():
" 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
def test(testcase=''):
" Run unittests. "
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)
testcase = getattr(mod, case)
suite = defaultTestLoader.loadTestsFromTestCase(testcase)
cases = loader.register(submodule='tests')
suites = [defaultTestLoader.loadTestsFromModule(mod) for mod in cases]
suite = defaultTestLoader.suiteClass(suites)
ARGV = []
if __name__ == '__main__':
argv = sys.argv[1:]
if argv and argv[0] == 'alembic':
ARGV = filter(lambda a: not a in ('-c', 'alembic') and not a.startswith('base.config.'), argv)
argv = filter(lambda a: not a in ARGV, argv)
sys.argv = [sys.argv[0] + ' alembic'] + argv
# pymode:lint_ignore=F0401,W801,W0603